[llvm] a4b42c6 - [llvm] Protect signpost map with a mutex

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 19 11:42:02 PST 2021


Author: Jonas Devlieghere
Date: 2021-01-19T11:41:54-08:00
New Revision: a4b42c621b9e2009cfd8bc9265bbf970c7231271

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

LOG: [llvm] Protect signpost map with a mutex

Use a mutex to protect concurrent access to the signpost map. This fixes
nondeterministic crashes in LLDB that appeared after using signposts in
the timer implementation.

Differential revision: https://reviews.llvm.org/D94285

Added: 
    

Modified: 
    llvm/lib/Support/Signposts.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/Signposts.cpp b/llvm/lib/Support/Signposts.cpp
index 91ce909c7dcb..9353e9b294d1 100644
--- a/llvm/lib/Support/Signposts.cpp
+++ b/llvm/lib/Support/Signposts.cpp
@@ -13,6 +13,7 @@
 #include "llvm/Config/config.h"
 #if LLVM_SUPPORT_XCODE_SIGNPOSTS
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/Support/Mutex.h"
 #include <os/signpost.h>
 #endif // if LLVM_SUPPORT_XCODE_SIGNPOSTS
 
@@ -38,9 +39,11 @@ class SignpostEmitterImpl {
 
   LogPtrTy SignpostLog;
   DenseMap<const void *, os_signpost_id_t> Signposts;
+  sys::SmartMutex<true> Mutex;
 
   LogTy &getLogger() const { return *SignpostLog; }
   os_signpost_id_t getSignpostForObject(const void *O) {
+    sys::SmartScopedLock<true> Lock(Mutex);
     const auto &I = Signposts.find(O);
     if (I != Signposts.end())
       return I->second;


        


More information about the llvm-commits mailing list