summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-09-24 21:18:36 +0000
committerDouglas Gregor <dgregor@apple.com>2010-09-24 21:18:36 +0000
commit2c84482abd2b5f6c83c0a353ca3bba10428cd4a9 (patch)
tree3725ba202f1bdc2a70f90359cd7f62a599dbd01d
parent4a6ab13fb9970741f53d0b0635bb99b0244280b3 (diff)
downloadbcm5719-llvm-2c84482abd2b5f6c83c0a353ca3bba10428cd4a9.tar.gz
bcm5719-llvm-2c84482abd2b5f6c83c0a353ca3bba10428cd4a9.zip
Teach libclang to enable multithreading in LLVM, since libclang clients are likely to be multithreaded. Also move the printing of timers to somewhere better for multithreaded libclang clients
llvm-svn: 114760
-rw-r--r--clang/lib/Frontend/ASTUnit.cpp3
-rw-r--r--clang/tools/libclang/CIndex.cpp16
2 files changed, 17 insertions, 2 deletions
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index b6c4eaac5ff..bd7e712bc78 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -84,6 +84,9 @@ ASTUnit::~ASTUnit() {
ClearCachedCompletionResults();
+ if (TimerGroup)
+ TimerGroup->printAll(llvm::errs());
+
for (unsigned I = 0, N = Timers.size(); I != N; ++I)
delete Timers[I];
}
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index d2d00571c1d..554edd824ef 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -34,8 +34,10 @@
#include "llvm/Support/CrashRecoveryContext.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Timer.h"
+#include "llvm/System/Mutex.h"
#include "llvm/System/Program.h"
#include "llvm/System/Signals.h"
+#include "llvm/System/Threading.h"
// Needed to define L_TMPNAM on some systems.
#include <cstdio>
@@ -1910,6 +1912,9 @@ bool CursorVisitor::VisitAttributes(Decl *D) {
return false;
}
+static llvm::sys::Mutex EnableMultithreadingMutex;
+static bool EnabledMultithreading;
+
extern "C" {
CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
int displayDiagnostics) {
@@ -1917,6 +1922,15 @@ CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
// enable it.
llvm::CrashRecoveryContext::Enable();
+ // Enable support for multithreading in LLVM.
+ {
+ llvm::sys::ScopedLock L(EnableMultithreadingMutex);
+ if (!EnabledMultithreading) {
+ llvm::llvm_start_multithreaded();
+ EnabledMultithreading = true;
+ }
+ }
+
CIndexer *CIdxr = new CIndexer();
if (excludeDeclarationsFromPCH)
CIdxr->setOnlyLocalDecls();
@@ -1928,8 +1942,6 @@ CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
void clang_disposeIndex(CXIndex CIdx) {
if (CIdx)
delete static_cast<CIndexer *>(CIdx);
- if (getenv("LIBCLANG_TIMING"))
- llvm::TimerGroup::printAll(llvm::errs());
}
void clang_setUseExternalASTGeneration(CXIndex CIdx, int value) {
OpenPOWER on IntegriCloud