#include "llvm/Support/Threading.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/raw_ostream.h"
-#include <mutex>
#ifdef __APPLE__
#include <pthread.h>
// Misc. API hooks.
//===----------------------------------------------------------------------===//
-static llvm::sys::Mutex LoggingMutex;
-static std::once_flag LibclangGlobalInitFlag;
+static llvm::sys::Mutex EnableMultithreadingMutex;
+static bool EnabledMultithreading;
static void fatal_error_handler(void *user_data, const std::string& reason,
bool gen_crash_diag) {
::abort();
}
-static void initializeLibClang() {
- llvm::install_fatal_error_handler(fatal_error_handler, nullptr);
-}
-
extern "C" {
CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
int displayDiagnostics) {
if (!getenv("LIBCLANG_DISABLE_CRASH_RECOVERY"))
llvm::CrashRecoveryContext::Enable();
- std::call_once(LibclangGlobalInitFlag, initializeLibClang);
+ // Enable support for multithreading in LLVM.
+ {
+ llvm::sys::ScopedLock L(EnableMultithreadingMutex);
+ if (!EnabledMultithreading) {
+ llvm::install_fatal_error_handler(fatal_error_handler, nullptr);
+ llvm::llvm_start_multithreaded();
+ EnabledMultithreading = true;
+ }
+ }
CIndexer *CIdxr = new CIndexer();
if (excludeDeclarationsFromPCH)
cxindex::Logger::~Logger() {
LogOS.flush();
- llvm::sys::ScopedLock L(LoggingMutex);
+ llvm::sys::ScopedLock L(EnableMultithreadingMutex);
static llvm::TimeRecord sBeginTR = llvm::TimeRecord::getCurrentTime();