diff --git a/llvm/lib/Support/CrashRecoveryContext.cpp b/llvm/lib/Support/CrashRecoveryContext.cpp index 64f8b3699ed70..3ee6a4fd36f40 100644 --- a/llvm/lib/Support/CrashRecoveryContext.cpp +++ b/llvm/lib/Support/CrashRecoveryContext.cpp @@ -84,7 +84,8 @@ struct CrashRecoveryContextImpl { }; } // namespace -static LLVM_THREAD_LOCAL bool gCrashRecoveryEnabled = false; +static ManagedStatic gCrashRecoveryContextMutex; +static bool gCrashRecoveryEnabled = false; static ManagedStatic> tlIsRecoveringFromCrash; @@ -135,6 +136,8 @@ CrashRecoveryContext *CrashRecoveryContext::GetCurrent() { } void CrashRecoveryContext::Enable() { + std::lock_guard L(*gCrashRecoveryContextMutex); + // FIXME: Shouldn't this be a refcount or something? if (gCrashRecoveryEnabled) return; gCrashRecoveryEnabled = true; @@ -142,6 +145,7 @@ void CrashRecoveryContext::Enable() { } void CrashRecoveryContext::Disable() { + std::lock_guard L(*gCrashRecoveryContextMutex); if (!gCrashRecoveryEnabled) return; gCrashRecoveryEnabled = false;