[Lldb-commits] [PATCH] D35083: [TypeSystem] Guard the global `ASTSourceMap` with a mutex
Sean Callanan via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue Jul 25 10:34:26 PDT 2017
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();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35083.108116.patch
Type: text/x-patch
Size: 1778 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20170725/b61658b2/attachment.bin>
More information about the lldb-commits
mailing list