[PATCH] D94285: [llvm] Protect signpost map with a mutex

Jonas Devlieghere via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 7 21:10:59 PST 2021


JDevlieghere created this revision.
JDevlieghere added a reviewer: dsanders.
Herald added subscribers: dexonsmith, hiraditya.
JDevlieghere requested review of this revision.
Herald added a project: LLVM.

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.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D94285

Files:
  llvm/lib/Support/Signposts.cpp


Index: llvm/lib/Support/Signposts.cpp
===================================================================
--- llvm/lib/Support/Signposts.cpp
+++ llvm/lib/Support/Signposts.cpp
@@ -14,6 +14,7 @@
 #if LLVM_SUPPORT_XCODE_SIGNPOSTS
 #include "llvm/ADT/DenseMap.h"
 #include <os/signpost.h>
+#include <mutex>
 #endif // if LLVM_SUPPORT_XCODE_SIGNPOSTS
 
 using namespace llvm;
@@ -38,9 +39,11 @@
 
   LogPtrTy SignpostLog;
   DenseMap<const void *, os_signpost_id_t> Signposts;
+  std::mutex Mutex;
 
   LogTy &getLogger() const { return *SignpostLog; }
   os_signpost_id_t getSignpostForObject(const void *O) {
+    std::lock_guard<std::mutex> Guard(Mutex);
     const auto &I = Signposts.find(O);
     if (I != Signposts.end())
       return I->second;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94285.315294.patch
Type: text/x-patch
Size: 750 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210108/0c5658d1/attachment.bin>


More information about the llvm-commits mailing list