2017-11-11 19:41:09 +00:00
|
|
|
#include "clang_index.h"
|
|
|
|
|
2017-12-07 08:23:40 +00:00
|
|
|
#include <mutex>
|
|
|
|
|
2017-11-11 19:41:09 +00:00
|
|
|
ClangIndex::ClangIndex() : ClangIndex(1, 0) {}
|
|
|
|
|
|
|
|
ClangIndex::ClangIndex(int exclude_declarations_from_pch,
|
|
|
|
int display_diagnostics) {
|
2017-12-07 19:53:48 +00:00
|
|
|
// llvm::InitializeAllTargets (and possibly others) called by
|
|
|
|
// clang_createIndex transtively modifies/reads lib/Support/TargetRegistry.cpp
|
|
|
|
// FirstTarget. There will be a race condition if two threads call
|
|
|
|
// clang_createIndex concurrently.
|
2017-12-07 08:23:40 +00:00
|
|
|
static std::mutex mutex_;
|
|
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
|
|
|
2017-11-11 19:41:09 +00:00
|
|
|
cx_index =
|
|
|
|
clang_createIndex(exclude_declarations_from_pch, display_diagnostics);
|
|
|
|
}
|
|
|
|
|
|
|
|
ClangIndex::~ClangIndex() {
|
|
|
|
clang_disposeIndex(cx_index);
|
2017-12-07 08:23:40 +00:00
|
|
|
}
|