summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-10-27 19:44:25 +0000
committerTed Kremenek <kremenek@apple.com>2011-10-27 19:44:25 +0000
commitbd307a53723a51826c88577a8839c4c4cda692b5 (patch)
tree245532406282a5aae78e410a307a18ef256d1053
parent9829801437b0bea7caa218df91eb6a6c4ffa2a34 (diff)
downloadbcm5719-llvm-bd307a53723a51826c88577a8839c4c4cda692b5.tar.gz
bcm5719-llvm-bd307a53723a51826c88577a8839c4c4cda692b5.zip
Add mutex for accessing ASTUnit's global OnDisk data. This may be an issue as libclang could be processing multiple ASTUnit's at once.
llvm-svn: 143138
-rw-r--r--clang/lib/Frontend/ASTUnit.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 282c93f0473..a0cfee13030 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -46,6 +46,7 @@
#include "llvm/Support/Timer.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Mutex.h"
+#include "llvm/Support/MutexGuard.h"
#include "llvm/Support/CrashRecoveryContext.h"
#include <cstdlib>
#include <cstdio>
@@ -101,6 +102,11 @@ namespace {
};
}
+static llvm::sys::SmartMutex<false> &getOnDiskMutex() {
+ static llvm::sys::SmartMutex<false> M(/* recursive = */ true);
+ return M;
+}
+
static void cleanupOnDiskMapAtExit(void);
typedef llvm::DenseMap<const ASTUnit *, OnDiskData *> OnDiskDataMap;
@@ -115,6 +121,7 @@ static OnDiskDataMap &getOnDiskDataMap() {
}
static void cleanupOnDiskMapAtExit(void) {
+ // No mutex required here since we are leaving the program.
OnDiskDataMap &M = getOnDiskDataMap();
for (OnDiskDataMap::iterator I = M.begin(), E = M.end(); I != E; ++I) {
// We don't worry about freeing the memory associated with OnDiskDataMap.
@@ -124,6 +131,9 @@ static void cleanupOnDiskMapAtExit(void) {
}
static OnDiskData &getOnDiskData(const ASTUnit *AU) {
+ // We require the mutex since we are modifying the structure of the
+ // DenseMap.
+ llvm::MutexGuard Guard(getOnDiskMutex());
OnDiskDataMap &M = getOnDiskDataMap();
OnDiskData *&D = M[AU];
if (!D)
@@ -136,6 +146,9 @@ static void erasePreambleFile(const ASTUnit *AU) {
}
static void removeOnDiskEntry(const ASTUnit *AU) {
+ // We require the mutex since we are modifying the structure of the
+ // DenseMap.
+ llvm::MutexGuard Guard(getOnDiskMutex());
OnDiskDataMap &M = getOnDiskDataMap();
OnDiskDataMap::iterator I = M.find(AU);
if (I != M.end()) {
OpenPOWER on IntegriCloud