forked from OSchip/llvm-project
Change libclang initialization to use std::call_once instead of
hand rolled once-initialization, and rename the mutex to be more descriptive of its actual purpose. llvm-svn: 211121
This commit is contained in:
parent
092f332ef2
commit
f68823ba3f
|
@ -51,6 +51,7 @@
|
||||||
#include "llvm/Support/Threading.h"
|
#include "llvm/Support/Threading.h"
|
||||||
#include "llvm/Support/Timer.h"
|
#include "llvm/Support/Timer.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
@ -2559,8 +2560,8 @@ buildPieces(unsigned NameFlags, bool IsMemberRefExpr,
|
||||||
// Misc. API hooks.
|
// Misc. API hooks.
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
static llvm::sys::Mutex EnableMultithreadingMutex;
|
static llvm::sys::Mutex LoggingMutex;
|
||||||
static bool EnabledMultithreading;
|
static std::once_flag LibclangGlobalInitFlag;
|
||||||
|
|
||||||
static void fatal_error_handler(void *user_data, const std::string& reason,
|
static void fatal_error_handler(void *user_data, const std::string& reason,
|
||||||
bool gen_crash_diag) {
|
bool gen_crash_diag) {
|
||||||
|
@ -2570,6 +2571,12 @@ static void fatal_error_handler(void *user_data, const std::string& reason,
|
||||||
::abort();
|
::abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void initializeLibClang() {
|
||||||
|
// Install our error handler, and make sure multi-threading is enabled.
|
||||||
|
llvm::llvm_start_multithreaded();
|
||||||
|
llvm::install_fatal_error_handler(fatal_error_handler, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
|
CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
|
||||||
int displayDiagnostics) {
|
int displayDiagnostics) {
|
||||||
|
@ -2578,15 +2585,7 @@ CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
|
||||||
if (!getenv("LIBCLANG_DISABLE_CRASH_RECOVERY"))
|
if (!getenv("LIBCLANG_DISABLE_CRASH_RECOVERY"))
|
||||||
llvm::CrashRecoveryContext::Enable();
|
llvm::CrashRecoveryContext::Enable();
|
||||||
|
|
||||||
// Enable support for multithreading in LLVM.
|
std::call_once(LibclangGlobalInitFlag, initializeLibClang);
|
||||||
{
|
|
||||||
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();
|
CIndexer *CIdxr = new CIndexer();
|
||||||
if (excludeDeclarationsFromPCH)
|
if (excludeDeclarationsFromPCH)
|
||||||
|
@ -6962,7 +6961,7 @@ Logger &cxindex::Logger::operator<<(const llvm::format_object_base &Fmt) {
|
||||||
cxindex::Logger::~Logger() {
|
cxindex::Logger::~Logger() {
|
||||||
LogOS.flush();
|
LogOS.flush();
|
||||||
|
|
||||||
llvm::sys::ScopedLock L(EnableMultithreadingMutex);
|
llvm::sys::ScopedLock L(LoggingMutex);
|
||||||
|
|
||||||
static llvm::TimeRecord sBeginTR = llvm::TimeRecord::getCurrentTime();
|
static llvm::TimeRecord sBeginTR = llvm::TimeRecord::getCurrentTime();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue