[llvm] 5e77ea0 - Make gCrashRecoveryEnabled thread local

Jacques Pienaar via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 10 12:46:09 PST 2021


Author: Jacques Pienaar
Date: 2021-02-10T12:44:18-08:00
New Revision: 5e77ea04f214c7a18bd5c782c8b8a7b7c828ad7a

URL: https://github.com/llvm/llvm-project/commit/5e77ea04f214c7a18bd5c782c8b8a7b7c828ad7a
DIFF: https://github.com/llvm/llvm-project/commit/5e77ea04f214c7a18bd5c782c8b8a7b7c828ad7a.diff

LOG: Make gCrashRecoveryEnabled thread local

If context is enabled/disabled and queried concurrently then this
results in a data race/TSAN failure with RunSafely (where boolean
variable was not locked).

There doesn't seem to be a reasonable way to enable threads that enable
and disable recovery in parallel (without also keeping
gCrashRecoveryEnabled's lock held during Fn execution which seems
undesirable). This makes enable checking if enabled thread local and
consistent with other thread local usage of crash context here.

Differential Revision: https://reviews.llvm.org/D93907

Added: 
    

Modified: 
    llvm/lib/Support/CrashRecoveryContext.cpp

Removed: 
    


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


        


More information about the llvm-commits mailing list