[cfe-commits] r143138 - /cfe/trunk/lib/Frontend/ASTUnit.cpp

Ted Kremenek kremenek at apple.com
Thu Oct 27 12:44:25 PDT 2011


Author: kremenek
Date: Thu Oct 27 14:44:25 2011
New Revision: 143138

URL: http://llvm.org/viewvc/llvm-project?rev=143138&view=rev
Log:
Add mutex for accessing ASTUnit's global OnDisk data.  This may be an issue as libclang could be processing multiple ASTUnit's at once.

Modified:
    cfe/trunk/lib/Frontend/ASTUnit.cpp

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=143138&r1=143137&r2=143138&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Thu Oct 27 14:44:25 2011
@@ -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 @@
   };
 }
 
+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 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 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 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()) {





More information about the cfe-commits mailing list