From: Tim Northover Date: Fri, 9 Jul 2021 08:51:57 +0000 (+0100) Subject: [Support] reorder Threading includes to avoid conflict with FreeBSD headers X-Git-Tag: llvmorg-14-init~1980 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0c39f82f0b3e9268f7699e62f59f960a1bff89fa;p=platform%2Fupstream%2Fllvm.git [Support] reorder Threading includes to avoid conflict with FreeBSD headers 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. --- diff --git a/llvm/lib/Support/Threading.cpp b/llvm/lib/Support/Threading.cpp index ba92a3e..04a1a9e 100644 --- a/llvm/lib/Support/Threading.cpp +++ b/llvm/lib/Support/Threading.cpp @@ -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 #include @@ -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 diff --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc index 2131def..5de1cf0 100644 --- a/llvm/lib/Support/Unix/Threading.inc +++ b/llvm/lib/Support/Unix/Threading.inc @@ -48,9 +48,10 @@ #include // For syscall() #endif +namespace llvm { pthread_t -llvm::llvm_execute_on_thread_impl(void *(*ThreadFunc)(void *), void *Arg, - llvm::Optional StackSizeInBytes) { +llvm_execute_on_thread_impl(void *(*ThreadFunc)(void *), void *Arg, + llvm::Optional 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 diff --git a/llvm/lib/Support/Windows/Threading.inc b/llvm/lib/Support/Windows/Threading.inc index 12d8cbc..7b48ca8 100644 --- a/llvm/lib/Support/Windows/Threading.inc +++ b/llvm/lib/Support/Windows/Threading.inc @@ -23,10 +23,10 @@ #undef MemoryFence #endif +namespace llvm { HANDLE -llvm::llvm_execute_on_thread_impl(unsigned(__stdcall *ThreadFunc)(void *), - void *Arg, - llvm::Optional StackSizeInBytes) { +llvm_execute_on_thread_impl(unsigned(__stdcall *ThreadFunc)(void *), void *Arg, + llvm::Optional 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()); }