CrashRecovery: Make CrashRecoveryContext static methods thread safe.
authorDaniel Dunbar <daniel@zuster.org>
Tue, 17 Aug 2010 22:32:34 +0000 (22:32 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 17 Aug 2010 22:32:34 +0000 (22:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111307 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/CrashRecoveryContext.h
lib/Support/CrashRecoveryContext.cpp

index d44d24ac95ebac27e46bca9cc7e4d990bfd4dede..45a43fa19502f5d4b23c389a2fdbf5adf9f20ea2 100644 (file)
@@ -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
index de98132539416fa49a11c23565aebd883281a19b..d1ecbb74dacab4affa59bf973e80deddbde03f02 100644 (file)
@@ -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;