diff --git a/llvm/lib/Support/CrashRecoveryContext.cpp b/llvm/lib/Support/CrashRecoveryContext.cpp --- a/llvm/lib/Support/CrashRecoveryContext.cpp +++ b/llvm/lib/Support/CrashRecoveryContext.cpp @@ -85,7 +85,7 @@ } static ManagedStatic gCrashRecoveryContextMutex; -static bool gCrashRecoveryEnabled = false; +static std::atomic gCrashRecoveryEnabled = 0; static ManagedStatic> tlIsRecoveringFromCrash; @@ -137,18 +137,15 @@ void CrashRecoveryContext::Enable() { std::lock_guard L(*gCrashRecoveryContextMutex); - // FIXME: Shouldn't this be a refcount or something? - if (gCrashRecoveryEnabled) + if (gCrashRecoveryEnabled++) return; - gCrashRecoveryEnabled = true; installExceptionOrSignalHandlers(); } void CrashRecoveryContext::Disable() { std::lock_guard L(*gCrashRecoveryContextMutex); - if (!gCrashRecoveryEnabled) + if (!(gCrashRecoveryEnabled--)) return; - gCrashRecoveryEnabled = false; uninstallExceptionOrSignalHandlers(); }