[Support] reorder Threading includes to avoid conflict with FreeBSD headers
authorTim Northover <t.p.northover@gmail.com>
Fri, 9 Jul 2021 08:51:57 +0000 (09:51 +0100)
committerTim Northover <t.p.northover@gmail.com>
Fri, 9 Jul 2021 09:39:52 +0000 (10:39 +0100)
FreeBSD's condvar.h (included by user.h in Threading.inc) uses a "struct
thread" that conflicts with llvm::thread if both are visible when it's
included.

So this moves our #include after the FreeBSD code.

llvm/lib/Support/Threading.cpp
llvm/lib/Support/Unix/Threading.inc
llvm/lib/Support/Windows/Threading.inc

index ba92a3e..04a1a9e 100644 (file)
@@ -15,7 +15,6 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/Config/config.h"
 #include "llvm/Support/Host.h"
-#include "llvm/Support/thread.h"
 
 #include <cassert>
 #include <errno.h>
@@ -78,6 +77,11 @@ unsigned llvm::ThreadPoolStrategy::compute_thread_count() const {
 #include "Windows/Threading.inc"
 #endif
 
+// Must be included after Threading.inc to provide definition for llvm::thread
+// because FreeBSD's condvar.h (included by user.h) misuses the "thread"
+// keyword.
+#include "llvm/Support/thread.h"
+
 #if defined(__APPLE__)
   // Darwin's default stack size for threads except the main one is only 512KB,
   // which is not enough for some/many normal LLVM compilations. This implements
index 2131def..5de1cf0 100644 (file)
 #include <unistd.h>      // For syscall()
 #endif
 
+namespace llvm {
 pthread_t
-llvm::llvm_execute_on_thread_impl(void *(*ThreadFunc)(void *), void *Arg,
-                                  llvm::Optional<unsigned> StackSizeInBytes) {
+llvm_execute_on_thread_impl(void *(*ThreadFunc)(void *), void *Arg,
+                            llvm::Optional<unsigned> StackSizeInBytes) {
   int errnum;
 
   // Construct the attributes object.
@@ -80,7 +81,7 @@ llvm::llvm_execute_on_thread_impl(void *(*ThreadFunc)(void *), void *Arg,
   return Thread;
 }
 
-void llvm::llvm_thread_detach_impl(pthread_t Thread) {
+void llvm_thread_detach_impl(pthread_t Thread) {
   int errnum;
 
   if ((errnum = ::pthread_detach(Thread)) != 0) {
@@ -88,7 +89,7 @@ void llvm::llvm_thread_detach_impl(pthread_t Thread) {
   }
 }
 
-void llvm::llvm_thread_join_impl(pthread_t Thread) {
+void llvm_thread_join_impl(pthread_t Thread) {
   int errnum;
 
   if ((errnum = ::pthread_join(Thread, nullptr)) != 0) {
@@ -96,14 +97,16 @@ void llvm::llvm_thread_join_impl(pthread_t Thread) {
   }
 }
 
-pthread_t llvm::llvm_thread_get_id_impl(pthread_t Thread) {
+pthread_t llvm_thread_get_id_impl(pthread_t Thread) {
   return Thread;
 }
 
-pthread_t llvm::llvm_thread_get_current_id_impl() {
+pthread_t llvm_thread_get_current_id_impl() {
   return ::pthread_self();
 }
 
+} // namespace llvm
+
 uint64_t llvm::get_threadid() {
 #if defined(__APPLE__)
   // Calling "mach_thread_self()" bumps the reference count on the thread
index 12d8cbc..7b48ca8 100644 (file)
 #undef MemoryFence
 #endif
 
+namespace llvm {
 HANDLE
-llvm::llvm_execute_on_thread_impl(unsigned(__stdcall *ThreadFunc)(void *),
-                                  void *Arg,
-                                  llvm::Optional<unsigned> StackSizeInBytes) {
+llvm_execute_on_thread_impl(unsigned(__stdcall *ThreadFunc)(void *), void *Arg,
+                            llvm::Optional<unsigned> StackSizeInBytes) {
   HANDLE hThread = (HANDLE)::_beginthreadex(
       NULL, StackSizeInBytes.getValueOr(0), ThreadFunc, Arg, 0, NULL);
 
@@ -37,26 +37,28 @@ llvm::llvm_execute_on_thread_impl(unsigned(__stdcall *ThreadFunc)(void *),
   return hThread;
 }
 
-void llvm::llvm_thread_join_impl(HANDLE hThread) {
+void llvm_thread_join_impl(HANDLE hThread) {
   if (::WaitForSingleObject(hThread, INFINITE) == WAIT_FAILED) {
     ReportLastErrorFatal("WaitForSingleObject failed");
   }
 }
 
-void llvm::llvm_thread_detach_impl(HANDLE hThread) {
+void llvm_thread_detach_impl(HANDLE hThread) {
   if (::CloseHandle(hThread) == FALSE) {
     ReportLastErrorFatal("CloseHandle failed");
   }
 }
 
-DWORD llvm::llvm_thread_get_id_impl(HANDLE hThread) {
+DWORD llvm_thread_get_id_impl(HANDLE hThread) {
   return ::GetThreadId(hThread);
 }
 
-DWORD llvm::llvm_thread_get_current_id_impl() {
+DWORD llvm_thread_get_current_id_impl() {
   return ::GetCurrentThreadId();
 }
 
+} // namespace llvm
+
 uint64_t llvm::get_threadid() {
   return uint64_t(::GetCurrentThreadId());
 }