TsanHappensAfter(&flag);
#endif
}
+
+ /// Get the amount of currency based on physical cores, if available for the
+ /// host system, otherwise falls back to thread::hardware_concurrency().
+ unsigned hardware_physical_concurrency();
}
#endif
#include "llvm/Support/Threading.h"
#include "llvm/Config/config.h"
#include "llvm/Support/Atomic.h"
+#include "llvm/Support/Host.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Support/thread.h"
#include <cassert>
}
#endif
+
+unsigned llvm::hardware_physical_concurrency() {
+ int NumPhysical = sys::getHostNumPhysicalCores();
+ if (NumPhysical == -1)
+ return thread::hardware_concurrency();
+ return NumPhysical;
+}
--- /dev/null
+//===- unittests/Threading.cpp - Thread tests -----------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/Threading.h"
+#include "llvm/Support/thread.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+TEST(Threading, PhysicalConcurrency) {
+ auto Num = hardware_physical_concurrency();
+ // Since Num is unsigned this will also catch us trying to
+ // return -1.
+ ASSERT_LE(Num, thread::hardware_concurrency());
+}
+
+} // end anon namespace