From d616de3e6a1336044c8a4e7a7cb8cba6d47eba72 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Tue, 19 Jan 2021 11:37:45 -0800 Subject: [PATCH] [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 (cherry picked from commit a4b42c621b9e2009cfd8bc9265bbf970c7231271) --- llvm/lib/Support/Signposts.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/llvm/lib/Support/Signposts.cpp b/llvm/lib/Support/Signposts.cpp index 91ce909c7dcb0..9353e9b294d10 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 #endif // if LLVM_SUPPORT_XCODE_SIGNPOSTS @@ -38,9 +39,11 @@ class SignpostEmitterImpl { LogPtrTy SignpostLog; DenseMap Signposts; + sys::SmartMutex Mutex; LogTy &getLogger() const { return *SignpostLog; } os_signpost_id_t getSignpostForObject(const void *O) { + sys::SmartScopedLock Lock(Mutex); const auto &I = Signposts.find(O); if (I != Signposts.end()) return I->second;