[llvm] r296891 - Don't bring in llvm/Support/thread.h in Threading.cpp
Zachary Turner via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 3 09:39:24 PST 2017
Author: zturner
Date: Fri Mar 3 11:39:24 2017
New Revision: 296891
URL: http://llvm.org/viewvc/llvm-project?rev=296891&view=rev
Log:
Don't bring in llvm/Support/thread.h in Threading.cpp
Doing so defines the type llvm::thread. On FreeBSD, we need
to call a macro which references its own ::thread type, which
causes an ambiguity due to ADL when inside of the llvm namespace.
Since we don't even need this unless LLVM_ENABLE_THREADS == 1,
we don't even need this type anyway, as it is always equal to
std::thread, so we can just use that directly.
Modified:
llvm/trunk/lib/Support/Threading.cpp
Modified: llvm/trunk/lib/Support/Threading.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Threading.cpp?rev=296891&r1=296890&r2=296891&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Threading.cpp (original)
+++ llvm/trunk/lib/Support/Threading.cpp Fri Mar 3 11:39:24 2017
@@ -15,7 +15,6 @@
#include "llvm/Support/Threading.h"
#include "llvm/Config/config.h"
#include "llvm/Support/Host.h"
-#include "llvm/Support/thread.h"
#include <cassert>
#include <errno.h>
@@ -56,10 +55,17 @@ void llvm::get_thread_name(SmallVectorIm
#else
+#include <thread>
unsigned llvm::heavyweight_hardware_concurrency() {
+ // Since we can't get here unless LLVM_ENABLE_THREADS == 1, it is safe to use
+ // `std::thread` directly instead of `llvm::thread` (and indeed, doing so
+ // allows us to not define `thread` in the llvm namespace, which conflicts
+ // with some platforms such as FreeBSD whose headers also define a struct
+ // called `thread` in the global namespace which can cause ambiguity due to
+ // ADL.
int NumPhysical = sys::getHostNumPhysicalCores();
if (NumPhysical == -1)
- return thread::hardware_concurrency();
+ return std::thread::hardware_concurrency();
return NumPhysical;
}
More information about the llvm-commits
mailing list