[llvm-branch-commits] [cfe-branch] r114905 - in /cfe/branches/Apple/whitney: lib/Frontend/ASTUnit.cpp tools/libclang/CIndex.cpp

Daniel Dunbar daniel at zuster.org
Mon Sep 27 15:13:03 PDT 2010


Author: ddunbar
Date: Mon Sep 27 17:13:02 2010
New Revision: 114905

URL: http://llvm.org/viewvc/llvm-project?rev=114905&view=rev
Log:
Merge r114760:
--
Author: Douglas Gregor <dgregor at apple.com>
Date:   Fri Sep 24 21:18:36 2010 +0000

    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

Modified:
    cfe/branches/Apple/whitney/lib/Frontend/ASTUnit.cpp
    cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp

Modified: cfe/branches/Apple/whitney/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Frontend/ASTUnit.cpp?rev=114905&r1=114904&r2=114905&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Frontend/ASTUnit.cpp Mon Sep 27 17:13:02 2010
@@ -84,6 +84,9 @@
 
   ClearCachedCompletionResults();
   
+  if (TimerGroup)
+    TimerGroup->printAll(llvm::errs());
+
   for (unsigned I = 0, N = Timers.size(); I != N; ++I)
     delete Timers[I];
 }

Modified: cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp?rev=114905&r1=114904&r2=114905&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp (original)
+++ cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp Mon Sep 27 17:13:02 2010
@@ -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 @@
   return false;
 }
 
+static llvm::sys::Mutex EnableMultithreadingMutex;
+static bool EnabledMultithreading;
+
 extern "C" {
 CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
                           int displayDiagnostics) {
@@ -1917,6 +1922,15 @@
   // 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 @@
 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) {





More information about the llvm-branch-commits mailing list