aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Support/Threading.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2021-08-22 19:00:43 +0000
committerDimitry Andric <dim@FreeBSD.org>2021-11-13 20:39:49 +0000
commitfe6060f10f634930ff71b7c50291ddc610da2475 (patch)
tree1483580c790bd4d27b6500a7542b5ee00534d3cc /contrib/llvm-project/llvm/lib/Support/Threading.cpp
parentb61bce17f346d79cecfd8f195a64b10f77be43b1 (diff)
parent344a3780b2e33f6ca763666c380202b18aab72a3 (diff)
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/Threading.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Support/Threading.cpp65
1 files changed, 14 insertions, 51 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/Threading.cpp b/contrib/llvm-project/llvm/lib/Support/Threading.cpp
index 61f8ee5be5b3..04a1a9e19428 100644
--- a/contrib/llvm-project/llvm/lib/Support/Threading.cpp
+++ b/contrib/llvm-project/llvm/lib/Support/Threading.cpp
@@ -38,13 +38,6 @@ 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; }
@@ -60,25 +53,6 @@ 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();
@@ -95,17 +69,6 @@ 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"
@@ -114,21 +77,21 @@ enum class JoiningPolicy { Join, Detach };
#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);
-}
+// 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
+ // the same interface as std::thread but requests the same stack size as the
+ // main thread (8MB) before creation.
+const llvm::Optional<unsigned> llvm::thread::DefaultStackSize = 8 * 1024 * 1024;
+#else
+const llvm::Optional<unsigned> llvm::thread::DefaultStackSize = None;
+#endif
-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