diff options
-rw-r--r-- | lldb/source/Symbol/ClangExternalASTSourceCommon.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lldb/source/Symbol/ClangExternalASTSourceCommon.cpp b/lldb/source/Symbol/ClangExternalASTSourceCommon.cpp index 7a1a0f23a7c..992a76352d9 100644 --- a/lldb/source/Symbol/ClangExternalASTSourceCommon.cpp +++ b/lldb/source/Symbol/ClangExternalASTSourceCommon.cpp @@ -10,6 +10,8 @@ #include "lldb/Symbol/ClangExternalASTSourceCommon.h" #include "lldb/Utility/Stream.h" +#include <mutex> + using namespace lldb_private; uint64_t g_TotalSizeOfMetadata = 0; @@ -18,15 +20,19 @@ typedef llvm::DenseMap<clang::ExternalASTSource *, ClangExternalASTSourceCommon *> ASTSourceMap; -static ASTSourceMap &GetSourceMap() { +static ASTSourceMap &GetSourceMap(std::unique_lock<std::mutex> &guard) { // Intentionally leaked to avoid problems with global destructors. static ASTSourceMap *s_source_map = new ASTSourceMap; + static std::mutex s_mutex; + std::unique_lock<std::mutex> locked_guard(s_mutex); + guard.swap(locked_guard); return *s_source_map; } ClangExternalASTSourceCommon * ClangExternalASTSourceCommon::Lookup(clang::ExternalASTSource *source) { - ASTSourceMap &source_map = GetSourceMap(); + std::unique_lock<std::mutex> guard; + ASTSourceMap &source_map = GetSourceMap(guard); ASTSourceMap::iterator iter = source_map.find(source); @@ -40,11 +46,13 @@ ClangExternalASTSourceCommon::Lookup(clang::ExternalASTSource *source) { ClangExternalASTSourceCommon::ClangExternalASTSourceCommon() : clang::ExternalASTSource() { g_TotalSizeOfMetadata += m_metadata.size(); - GetSourceMap()[this] = this; + std::unique_lock<std::mutex> guard; + GetSourceMap(guard)[this] = this; } ClangExternalASTSourceCommon::~ClangExternalASTSourceCommon() { - GetSourceMap().erase(this); + std::unique_lock<std::mutex> guard; + GetSourceMap(guard).erase(this); g_TotalSizeOfMetadata -= m_metadata.size(); } |