summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Callanan <scallanan@apple.com>2017-07-25 17:33:37 +0000
committerSean Callanan <scallanan@apple.com>2017-07-25 17:33:37 +0000
commitafc70ab3e204feb4b3e227d430b9ffa0be04e4e6 (patch)
treec840bb217631ac48407e6185e4213556268ba0be
parentdafea67abd711f40028e86e3cb361d5d3f63e292 (diff)
downloadbcm5719-llvm-afc70ab3e204feb4b3e227d430b9ffa0be04e4e6.tar.gz
bcm5719-llvm-afc70ab3e204feb4b3e227d430b9ffa0be04e4e6.zip
[TypeSystem] Guard the global `ASTSourceMap` with a mutex
s_source_map in ClangExternalASTSourceCommon.cpp is unguarded and therefore can break in multithreaded conditions. This can cause crashes in particular if multiple targets are being set up at once. This patch wraps s_source_map in a function that ensures exclusivity, and makes every user of it use that function instead. <rdar://problem/33429774> lldb crashes after "resume_off" Differential Revision: https://reviews.llvm.org/D35083 llvm-svn: 308993
-rw-r--r--lldb/source/Symbol/ClangExternalASTSourceCommon.cpp16
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();
}
OpenPOWER on IntegriCloud