summaryrefslogtreecommitdiff
path: root/llvm/lib/Support/CrashRecoveryContext.cpp
diff options
context:
space:
mode:
authorTim Northover <t.p.northover@gmail.com>2021-05-26 11:25:11 +0100
committerTim Northover <t.p.northover@gmail.com>2021-07-08 14:51:53 +0100
commit727e1c9be3a5b20c6b502f056d74a681689049d7 (patch)
treee3c71993913d8c1aca895ffe677ee4f3ae67a082 /llvm/lib/Support/CrashRecoveryContext.cpp
parent7445f1e4dcd4525ab1f04f3cebfda341ec2eb716 (diff)
downloadllvm-727e1c9be3a5b20c6b502f056d74a681689049d7.tar.gz
Support: add llvm::thread class that supports specifying stack size.
This adds a new llvm::thread class with the same interface as std::thread except there is an extra constructor that allows us to set the new thread's stack size. On Darwin even the default size is boosted to 8MB to match the main thread. It also switches all users of the older C-style `llvm_execute_on_thread` API family over to `llvm::thread` followed by either a `detach` or `join` call and removes the old API.
Diffstat (limited to 'llvm/lib/Support/CrashRecoveryContext.cpp')
-rw-r--r--llvm/lib/Support/CrashRecoveryContext.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/llvm/lib/Support/CrashRecoveryContext.cpp b/llvm/lib/Support/CrashRecoveryContext.cpp
index 3ee6a4fd36f4..433d99df5932 100644
--- a/llvm/lib/Support/CrashRecoveryContext.cpp
+++ b/llvm/lib/Support/CrashRecoveryContext.cpp
@@ -13,6 +13,7 @@
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/ThreadLocal.h"
+#include "llvm/Support/thread.h"
#include <mutex>
#include <setjmp.h>
@@ -500,10 +501,12 @@ bool CrashRecoveryContext::RunSafelyOnThread(function_ref<void()> Fn,
unsigned RequestedStackSize) {
bool UseBackgroundPriority = hasThreadBackgroundPriority();
RunSafelyOnThreadInfo Info = { Fn, this, UseBackgroundPriority, false };
- llvm_execute_on_thread(RunSafelyOnThread_Dispatch, &Info,
- RequestedStackSize == 0
- ? llvm::None
- : llvm::Optional<unsigned>(RequestedStackSize));
+ llvm::thread Thread(RequestedStackSize == 0
+ ? llvm::None
+ : llvm::Optional<unsigned>(RequestedStackSize),
+ RunSafelyOnThread_Dispatch, &Info);
+ Thread.join();
+
if (CrashRecoveryContextImpl *CRC = (CrashRecoveryContextImpl *)Impl)
CRC->setSwitchedThread();
return Info.Result;