diff options
-rw-r--r-- | include/llvm/Support/CrashRecoveryContext.h | 6 | ||||
-rw-r--r-- | lib/Support/CrashRecoveryContext.cpp | 10 |
2 files changed, 12 insertions, 4 deletions
diff --git a/include/llvm/Support/CrashRecoveryContext.h b/include/llvm/Support/CrashRecoveryContext.h index d44d24ac95..45a43fa195 100644 --- a/include/llvm/Support/CrashRecoveryContext.h +++ b/include/llvm/Support/CrashRecoveryContext.h @@ -47,12 +47,10 @@ public: CrashRecoveryContext() : Impl(0) {} ~CrashRecoveryContext(); - /// \brief Enable crash recovery. This function is not thread safe, clients - /// should call it during startup or with a lock held. + /// \brief Enable crash recovery. static void Enable(); - /// \brief Disable crash recovery. This function is not thread safe, clients - /// should call it during startup or with a lock held. + /// \brief Disable crash recovery. static void Disable(); /// \brief Execute the provide callback function (with the given arguments) in diff --git a/lib/Support/CrashRecoveryContext.cpp b/lib/Support/CrashRecoveryContext.cpp index de98132539..d1ecbb74da 100644 --- a/lib/Support/CrashRecoveryContext.cpp +++ b/lib/Support/CrashRecoveryContext.cpp @@ -10,6 +10,7 @@ #include "llvm/Support/CrashRecoveryContext.h" #include "llvm/ADT/SmallString.h" #include "llvm/Config/config.h" +#include "llvm/System/Mutex.h" #include "llvm/System/ThreadLocal.h" #include <setjmp.h> #include <cstdio> @@ -47,6 +48,7 @@ public: } +static sys::Mutex gCrashRecoveryContexMutex; static bool gCrashRecoveryEnabled = false; CrashRecoveryContext::~CrashRecoveryContext() { @@ -59,6 +61,8 @@ CrashRecoveryContext::~CrashRecoveryContext() { // FIXME: No real Win32 implementation currently. void CrashRecoveryContext::Enable() { + sys::ScopedLock L(gCrashRecoveryContexMutex); + if (gCrashRecoveryEnabled) return; @@ -66,6 +70,8 @@ void CrashRecoveryContext::Enable() { } void CrashRecoveryContext::Disable() { + sys::ScopedLock L(gCrashRecoveryContexMutex); + if (!gCrashRecoveryEnabled) return; @@ -121,6 +127,8 @@ static void CrashRecoverySignalHandler(int Signal) { } void CrashRecoveryContext::Enable() { + sys::ScopedLock L(gCrashRecoveryContexMutex); + if (gCrashRecoveryEnabled) return; @@ -138,6 +146,8 @@ void CrashRecoveryContext::Enable() { } void CrashRecoveryContext::Disable() { + sys::ScopedLock L(gCrashRecoveryContexMutex); + if (!gCrashRecoveryEnabled) return; |