This revision was automatically updated to reflect the committed changes. Closed by commit rL308993: [TypeSystem] Guard the global `ASTSourceMap` with a mutex (authored by spyffe).
Changed prior to commit: https://reviews.llvm.org/D35083?vs=106087&id=108116#toc Repository: rL LLVM https://reviews.llvm.org/D35083 Files: lldb/trunk/source/Symbol/ClangExternalASTSourceCommon.cpp Index: lldb/trunk/source/Symbol/ClangExternalASTSourceCommon.cpp =================================================================== --- lldb/trunk/source/Symbol/ClangExternalASTSourceCommon.cpp +++ lldb/trunk/source/Symbol/ClangExternalASTSourceCommon.cpp @@ -10,23 +10,29 @@ #include "lldb/Symbol/ClangExternalASTSourceCommon.h" #include "lldb/Utility/Stream.h" +#include <mutex> + using namespace lldb_private; uint64_t g_TotalSizeOfMetadata = 0; 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::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(); }
Index: lldb/trunk/source/Symbol/ClangExternalASTSourceCommon.cpp =================================================================== --- lldb/trunk/source/Symbol/ClangExternalASTSourceCommon.cpp +++ lldb/trunk/source/Symbol/ClangExternalASTSourceCommon.cpp @@ -10,23 +10,29 @@ #include "lldb/Symbol/ClangExternalASTSourceCommon.h" #include "lldb/Utility/Stream.h" +#include <mutex> + using namespace lldb_private; uint64_t g_TotalSizeOfMetadata = 0; 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::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(); }
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits