#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>
};
}
+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;
}
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.
}
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)
}
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()) {