summaryrefslogtreecommitdiff
path: root/lib/Support/CrashRecoveryContext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Support/CrashRecoveryContext.cpp')
-rw-r--r--lib/Support/CrashRecoveryContext.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/Support/CrashRecoveryContext.cpp b/lib/Support/CrashRecoveryContext.cpp
index 182c362cc7..d2a38958ae 100644
--- a/lib/Support/CrashRecoveryContext.cpp
+++ b/lib/Support/CrashRecoveryContext.cpp
@@ -28,16 +28,23 @@ struct CrashRecoveryContextImpl {
std::string Backtrace;
::jmp_buf JumpBuffer;
volatile unsigned Failed : 1;
+ unsigned SwitchedThread : 1;
public:
CrashRecoveryContextImpl(CrashRecoveryContext *CRC) : CRC(CRC),
- Failed(false) {
+ Failed(false),
+ SwitchedThread(false) {
CurrentContext.set(this);
}
~CrashRecoveryContextImpl() {
- CurrentContext.erase();
+ if (!SwitchedThread)
+ CurrentContext.erase();
}
+ /// \brief Called when the separate crash-recovery thread was finished, to
+ /// indicate that we don't need to clear the thread-local CurrentContext.
+ void setSwitchedThread() { SwitchedThread = true; }
+
void HandleCrash() {
// Eliminate the current context entry, to avoid re-entering in case the
// cleanup code crashes.
@@ -342,5 +349,7 @@ bool CrashRecoveryContext::RunSafelyOnThread(void (*Fn)(void*), void *UserData,
unsigned RequestedStackSize) {
RunSafelyOnThreadInfo Info = { Fn, UserData, this, false };
llvm_execute_on_thread(RunSafelyOnThread_Dispatch, &Info, RequestedStackSize);
+ if (CrashRecoveryContextImpl *CRC = (CrashRecoveryContextImpl *)Impl)
+ CRC->setSwitchedThread();
return Info.Result;
}