[PATCH] Change llvm::sys::Mutex implementation to use STL-provided mutexes.

Zachary Turner zturner at google.com
Thu May 29 13:36:32 PDT 2014


Hi rnk,

Clang side changes to support LLVM mutex refactor.

http://reviews.llvm.org/D3961

Files:
  lib/Frontend/ASTUnit.cpp
  tools/libclang/CIndex.cpp

Index: lib/Frontend/ASTUnit.cpp
===================================================================
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -99,8 +99,8 @@
   };
 }
 
-static llvm::sys::SmartMutex<false> &getOnDiskMutex() {
-  static llvm::sys::SmartMutex<false> M(/* recursive = */ true);
+static llvm::sys::RecursiveMutex &getOnDiskMutex() {
+  static llvm::sys::RecursiveMutex M;
   return M;
 }
 
@@ -2893,20 +2893,20 @@
 
 #ifndef NDEBUG
 ASTUnit::ConcurrencyState::ConcurrencyState() {
-  Mutex = new llvm::sys::MutexImpl(/*recursive=*/true);
+  Mutex = new llvm::sys::RecursiveMutex;
 }
 
 ASTUnit::ConcurrencyState::~ConcurrencyState() {
-  delete static_cast<llvm::sys::MutexImpl *>(Mutex);
+  delete static_cast<llvm::sys::RecursiveMutex *>(Mutex);
 }
 
 void ASTUnit::ConcurrencyState::start() {
-  bool acquired = static_cast<llvm::sys::MutexImpl *>(Mutex)->tryacquire();
+  bool acquired = static_cast<llvm::sys::RecursiveMutex *>(Mutex)->tryacquire();
   assert(acquired && "Concurrent access to ASTUnit!");
 }
 
 void ASTUnit::ConcurrencyState::finish() {
-  static_cast<llvm::sys::MutexImpl *>(Mutex)->release();
+  static_cast<llvm::sys::RecursiveMutex *>(Mutex)->release();
 }
 
 #else // NDEBUG
Index: tools/libclang/CIndex.cpp
===================================================================
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -45,6 +45,7 @@
 #include "llvm/Support/Format.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Mutex.h"
+#include "llvm/Support/MutexGuard.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/SaveAndRestore.h"
 #include "llvm/Support/Signals.h"
@@ -2552,7 +2553,7 @@
 // Misc. API hooks.
 //===----------------------------------------------------------------------===//               
 
-static llvm::sys::Mutex EnableMultithreadingMutex;
+static llvm::sys::RecursiveMutex EnableMultithreadingMutex;
 static bool EnabledMultithreading;
 
 static void fatal_error_handler(void *user_data, const std::string& reason,
@@ -2573,7 +2574,7 @@
 
   // Enable support for multithreading in LLVM.
   {
-    llvm::sys::ScopedLock L(EnableMultithreadingMutex);
+    llvm::MutexGuard L(EnableMultithreadingMutex);
     if (!EnabledMultithreading) {
       llvm::install_fatal_error_handler(fatal_error_handler, 0);
       llvm::llvm_start_multithreaded();
@@ -6954,7 +6955,7 @@
 cxindex::Logger::~Logger() {
   LogOS.flush();
 
-  llvm::sys::ScopedLock L(EnableMultithreadingMutex);
+  llvm::MutexGuard L(EnableMultithreadingMutex);
 
   static llvm::TimeRecord sBeginTR = llvm::TimeRecord::getCurrentTime();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3961.9931.patch
Type: text/x-patch
Size: 2624 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140529/68be611f/attachment.bin>


More information about the llvm-commits mailing list