diff options
author | Tim Northover <t.p.northover@gmail.com> | 2021-07-08 14:59:47 +0100 |
---|---|---|
committer | Tim Northover <t.p.northover@gmail.com> | 2021-07-08 14:59:47 +0100 |
commit | 2bf5e8d953ededbc208bd4c116c9d6331d73f0f0 (patch) | |
tree | 6f0e1d1dce203f49fd943933ea271edbb56bee75 /llvm/lib/Support/Threading.cpp | |
parent | 727e1c9be3a5b20c6b502f056d74a681689049d7 (diff) | |
download | llvm-2bf5e8d953ededbc208bd4c116c9d6331d73f0f0.zip llvm-2bf5e8d953ededbc208bd4c116c9d6331d73f0f0.tar.gz llvm-2bf5e8d953ededbc208bd4c116c9d6331d73f0f0.tar.bz2 |
Revert "Support: add llvm::thread class that supports specifying stack size."
It's causing build failures because DefaultStackSize isn't defined everywhere
it should be and I need time to investigate.
Diffstat (limited to 'llvm/lib/Support/Threading.cpp')
-rw-r--r-- | llvm/lib/Support/Threading.cpp | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/llvm/lib/Support/Threading.cpp b/llvm/lib/Support/Threading.cpp index 55e97d6..61f8ee5 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 <cassert> #include <errno.h> @@ -39,6 +38,13 @@ bool llvm::llvm_is_multithreaded() { #if LLVM_ENABLE_THREADS == 0 || \ (!defined(_WIN32) && !defined(HAVE_PTHREAD_H)) +// Support for non-Win32, non-pthread implementation. +void llvm::llvm_execute_on_thread(void (*Fn)(void *), void *UserData, + llvm::Optional<unsigned> StackSizeInBytes) { + (void)StackSizeInBytes; + Fn(UserData); +} + uint64_t llvm::get_threadid() { return 0; } uint32_t llvm::get_max_thread_name_length() { return 0; } @@ -54,6 +60,25 @@ unsigned llvm::ThreadPoolStrategy::compute_thread_count() const { return 1; } +#if LLVM_ENABLE_THREADS == 0 +void llvm::llvm_execute_on_thread_async( + llvm::unique_function<void()> Func, + llvm::Optional<unsigned> StackSizeInBytes) { + (void)Func; + (void)StackSizeInBytes; + report_fatal_error("Spawning a detached thread doesn't make sense with no " + "threading support"); +} +#else +// Support for non-Win32, non-pthread implementation. +void llvm::llvm_execute_on_thread_async( + llvm::unique_function<void()> Func, + llvm::Optional<unsigned> StackSizeInBytes) { + (void)StackSizeInBytes; + std::thread(std::move(Func)).detach(); +} +#endif + #else int computeHostNumHardwareThreads(); @@ -70,6 +95,17 @@ unsigned llvm::ThreadPoolStrategy::compute_thread_count() const { return std::min((unsigned)MaxThreadCount, ThreadsRequested); } +namespace { +struct SyncThreadInfo { + void (*UserFn)(void *); + void *UserData; +}; + +using AsyncThreadInfo = llvm::unique_function<void()>; + +enum class JoiningPolicy { Join, Detach }; +} // namespace + // Include the platform-specific parts of this class. #ifdef LLVM_ON_UNIX #include "Unix/Threading.inc" @@ -78,6 +114,22 @@ unsigned llvm::ThreadPoolStrategy::compute_thread_count() const { #include "Windows/Threading.inc" #endif +void llvm::llvm_execute_on_thread(void (*Fn)(void *), void *UserData, + llvm::Optional<unsigned> StackSizeInBytes) { + + SyncThreadInfo Info = {Fn, UserData}; + llvm_execute_on_thread_impl(threadFuncSync, &Info, StackSizeInBytes, + JoiningPolicy::Join); +} + +void llvm::llvm_execute_on_thread_async( + llvm::unique_function<void()> Func, + llvm::Optional<unsigned> StackSizeInBytes) { + llvm_execute_on_thread_impl(&threadFuncAsync, + new AsyncThreadInfo(std::move(Func)), + StackSizeInBytes, JoiningPolicy::Detach); +} + #endif Optional<ThreadPoolStrategy> |