1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 10:32:48 +02:00

[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.
This commit is contained in:
Tim Northover 2021-07-09 09:51:57 +01:00
parent f51b06e3a7
commit 295ae7d240
3 changed files with 23 additions and 14 deletions

View 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

View File

@ -48,9 +48,10 @@
#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

View File

@ -23,10 +23,10 @@
#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());
}