Index: lib/CodeGen/PseudoSourceValue.cpp =================================================================== --- lib/CodeGen/PseudoSourceValue.cpp +++ lib/CodeGen/PseudoSourceValue.cpp @@ -17,16 +17,16 @@ #include "llvm/IR/LLVMContext.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ManagedStatic.h" -#include "llvm/Support/Mutex.h" #include "llvm/Support/raw_ostream.h" #include +#include using namespace llvm; namespace { struct PSVGlobalsTy { // PseudoSourceValues are immutable so don't need locking. const PseudoSourceValue PSVs[4]; - sys::Mutex Lock; // Guards FSValues, but not the values inside it. + std::recursive_mutex Lock; // Guards FSValues, but not the values inside it. std::map FSValues; PSVGlobalsTy() : PSVs() {} @@ -68,7 +68,7 @@ const PseudoSourceValue *PseudoSourceValue::getFixedStack(int FI) { PSVGlobalsTy &PG = *PSVGlobals; - sys::ScopedLock locked(PG.Lock); + std::lock_guard locked(PG.Lock); const PseudoSourceValue *&V = PG.FSValues[FI]; if (!V) V = new FixedStackPseudoSourceValue(FI); Index: lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp =================================================================== --- lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp +++ lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp @@ -46,7 +46,7 @@ using namespace llvm; -static ManagedStatic FunctionsLock; +static ManagedStatic FunctionsLock; typedef GenericValue (*ExFunc)(FunctionType *, const std::vector &); @@ -96,7 +96,7 @@ ExtName += getTypeID(FT->getContainedType(i)); ExtName += "_" + F->getName().str(); - sys::ScopedLock Writer(*FunctionsLock); + std::lock_guard Writer(*FunctionsLock); ExFunc FnPtr = FuncNames[ExtName]; if (!FnPtr) FnPtr = FuncNames["lle_X_" + F->getName().str()]; @@ -248,14 +248,14 @@ const std::vector &ArgVals) { TheInterpreter = this; - FunctionsLock->acquire(); + FunctionsLock->lock(); // Do a lookup to see if the function is in our cache... this should just be a // deferred annotation! std::map::iterator FI = ExportedFunctions->find(F); if (ExFunc Fn = (FI == ExportedFunctions->end()) ? lookupFunction(F) : FI->second) { - FunctionsLock->release(); + FunctionsLock->unlock(); return Fn(F->getFunctionType(), ArgVals); } @@ -273,7 +273,7 @@ RawFn = RF->second; } - FunctionsLock->release(); + FunctionsLock->unlock(); GenericValue Result; if (RawFn != 0 && ffiInvoke(RawFn, F, ArgVals, getDataLayout(), Result)) @@ -496,7 +496,7 @@ } void Interpreter::initializeExternalFunctions() { - sys::ScopedLock Writer(*FunctionsLock); + std::lock_guard Writer(*FunctionsLock); FuncNames["lle_X_atexit"] = lle_X_atexit; FuncNames["lle_X_exit"] = lle_X_exit; FuncNames["lle_X_abort"] = lle_X_abort; Index: lib/ExecutionEngine/OProfileJIT/OProfileWrapper.cpp =================================================================== --- lib/ExecutionEngine/OProfileJIT/OProfileWrapper.cpp +++ lib/ExecutionEngine/OProfileJIT/OProfileWrapper.cpp @@ -17,12 +17,11 @@ #include "llvm/ADT/SmallString.h" #include "llvm/Support/Debug.h" #include "llvm/Support/DynamicLibrary.h" -#include "llvm/Support/Mutex.h" -#include "llvm/Support/MutexGuard.h" #include "llvm/Support/raw_ostream.h" #include #include #include +#include #include #include #include @@ -33,7 +32,7 @@ namespace { // Global mutex to ensure a single thread initializes oprofile agent. -llvm::sys::Mutex OProfileInitializationMutex; +std::recursive_mutex OProfileInitializationMutex; } // anonymous namespace @@ -56,7 +55,7 @@ using namespace llvm; using namespace llvm::sys; - MutexGuard Guard(OProfileInitializationMutex); + std::lock_guard Guard(OProfileInitializationMutex); if (Initialized) return OpenAgentFunc != 0; Index: lib/ExecutionEngine/RuntimeDyld/GDBRegistrar.cpp =================================================================== --- lib/ExecutionEngine/RuntimeDyld/GDBRegistrar.cpp +++ lib/ExecutionEngine/RuntimeDyld/GDBRegistrar.cpp @@ -11,9 +11,8 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/Mutex.h" -#include "llvm/Support/MutexGuard.h" #include "llvm/Support/ManagedStatic.h" +#include using namespace llvm; @@ -101,7 +100,7 @@ /// Lock used to serialize all jit registration events, since they /// modify global variables. -llvm::sys::Mutex JITDebugLock; +std::recursive_mutex JITDebugLock; /// Do the registration. void NotifyDebugger(jit_code_entry* JITCodeEntry) { @@ -121,7 +120,7 @@ GDBJITRegistrar::~GDBJITRegistrar() { // Free all registered object files. - llvm::MutexGuard locked(JITDebugLock); + std::lock_guard locked(JITDebugLock); for (RegisteredObjectBufferMap::iterator I = ObjectBufferMap.begin(), E = ObjectBufferMap.end(); I != E; ++I) { // Call the private method that doesn't update the map so our iterator @@ -137,7 +136,7 @@ size_t Size = Object.getBufferSize(); assert(Buffer && "Attempt to register a null object with a debugger."); - llvm::MutexGuard locked(JITDebugLock); + std::lock_guard locked(JITDebugLock); assert(ObjectBufferMap.find(Buffer) == ObjectBufferMap.end() && "Second attempt to perform debug registration."); jit_code_entry* JITCodeEntry = new jit_code_entry(); @@ -156,7 +155,7 @@ bool GDBJITRegistrar::deregisterObject(const ObjectBuffer& Object) { const char *Buffer = Object.getBufferStart(); - llvm::MutexGuard locked(JITDebugLock); + std::lock_guard locked(JITDebugLock); RegisteredObjectBufferMap::iterator I = ObjectBufferMap.find(Buffer); if (I != ObjectBufferMap.end()) { Index: lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp =================================================================== --- lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp +++ lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp @@ -19,7 +19,7 @@ #include "RuntimeDyldMachO.h" #include "llvm/Object/ELF.h" #include "llvm/Support/MathExtras.h" -#include "llvm/Support/MutexGuard.h" +#include using namespace llvm; using namespace llvm::object; @@ -42,7 +42,7 @@ // Resolve the relocations for all symbols we currently know about. void RuntimeDyldImpl::resolveRelocations() { - MutexGuard locked(lock); + std::lock_guard locked(lock); // First, resolve relocations associated with external symbols. resolveExternalSymbols(); @@ -63,7 +63,7 @@ void RuntimeDyldImpl::mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress) { - MutexGuard locked(lock); + std::lock_guard locked(lock); for (unsigned i = 0, e = Sections.size(); i != e; ++i) { if (Sections[i].Address == LocalAddress) { reassignSectionAddress(i, TargetAddress); @@ -102,7 +102,7 @@ } ObjectImage *RuntimeDyldImpl::loadObject(ObjectImage *InputObject) { - MutexGuard locked(lock); + std::lock_guard locked(lock); std::unique_ptr Obj(InputObject); if (!Obj) Index: lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h =================================================================== --- lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h +++ lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h @@ -25,10 +25,10 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Format.h" #include "llvm/Support/Host.h" -#include "llvm/Support/Mutex.h" #include "llvm/Support/SwapByteOrder.h" #include "llvm/Support/raw_ostream.h" #include +#include #include using namespace llvm; @@ -220,7 +220,7 @@ // processRelocations, and that's OK. The handling of the relocation lists // is written in such a way as to work correctly if new elements are added to // the end of the list while the list is being processed. - sys::Mutex lock; + std::recursive_mutex lock; virtual unsigned getMaxStubSize() = 0; virtual unsigned getStubAlignment() = 0; Index: lib/Support/CrashRecoveryContext.cpp =================================================================== --- lib/Support/CrashRecoveryContext.cpp +++ lib/Support/CrashRecoveryContext.cpp @@ -12,9 +12,9 @@ #include "llvm/Config/config.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ManagedStatic.h" -#include "llvm/Support/Mutex.h" #include "llvm/Support/ThreadLocal.h" #include +#include #include using namespace llvm; @@ -64,7 +64,7 @@ } -static ManagedStatic gCrashRecoveryContextMutex; +static ManagedStatic gCrashRecoveryContextMutex; static bool gCrashRecoveryEnabled = false; static ManagedStatic > @@ -184,7 +184,7 @@ static sys::ThreadLocal sCurrentExceptionHandle; void CrashRecoveryContext::Enable() { - sys::ScopedLock L(*gCrashRecoveryContextMutex); + std::lock_guard L(*gCrashRecoveryContextMutex); if (gCrashRecoveryEnabled) return; @@ -200,7 +200,7 @@ } void CrashRecoveryContext::Disable() { - sys::ScopedLock L(*gCrashRecoveryContextMutex); + std::lock_guard L(*gCrashRecoveryContextMutex); if (!gCrashRecoveryEnabled) return; @@ -270,7 +270,7 @@ } void CrashRecoveryContext::Enable() { - sys::ScopedLock L(*gCrashRecoveryContextMutex); + std::lock_guard L(*gCrashRecoveryContextMutex); if (gCrashRecoveryEnabled) return; @@ -289,7 +289,7 @@ } void CrashRecoveryContext::Disable() { - sys::ScopedLock L(*gCrashRecoveryContextMutex); + std::lock_guard L(*gCrashRecoveryContextMutex); if (!gCrashRecoveryEnabled) return; Index: lib/Support/ErrorHandling.cpp =================================================================== --- lib/Support/ErrorHandling.cpp +++ lib/Support/ErrorHandling.cpp @@ -20,13 +20,12 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/Errc.h" #include "llvm/Support/Signals.h" -#include "llvm/Support/Mutex.h" -#include "llvm/Support/MutexGuard.h" #include "llvm/Support/Threading.h" #include "llvm/Support/WindowsError.h" #include "llvm/Support/raw_ostream.h" #include #include +#include #if defined(HAVE_UNISTD_H) # include @@ -41,18 +40,18 @@ static fatal_error_handler_t ErrorHandler = nullptr; static void *ErrorHandlerUserData = nullptr; -static sys::Mutex ErrorHandlerMutex; +static std::recursive_mutex ErrorHandlerMutex; void llvm::install_fatal_error_handler(fatal_error_handler_t handler, void *user_data) { - llvm::MutexGuard Lock(ErrorHandlerMutex); + std::lock_guard Lock(ErrorHandlerMutex); assert(!ErrorHandler && "Error handler already registered!\n"); ErrorHandler = handler; ErrorHandlerUserData = user_data; } void llvm::remove_fatal_error_handler() { - llvm::MutexGuard Lock(ErrorHandlerMutex); + std::lock_guard Lock(ErrorHandlerMutex); ErrorHandler = nullptr; ErrorHandlerUserData = nullptr; } @@ -75,7 +74,7 @@ { // Only acquire the mutex while reading the handler, so as not to invoke a // user-supplied callback under a lock. - llvm::MutexGuard Lock(ErrorHandlerMutex); + std::lock_guard Lock(ErrorHandlerMutex); handler = ErrorHandler; handlerData = ErrorHandlerUserData; } Index: lib/Support/Unix/Process.inc =================================================================== --- lib/Support/Unix/Process.inc +++ lib/Support/Unix/Process.inc @@ -14,8 +14,6 @@ #include "Unix.h" #include "llvm/ADT/Hashing.h" #include "llvm/ADT/StringRef.h" -#include "llvm/Support/Mutex.h" -#include "llvm/Support/MutexGuard.h" #include "llvm/Support/TimeValue.h" #ifdef HAVE_SYS_TIME_H #include @@ -38,6 +36,7 @@ #ifdef HAVE_TERMIOS_H # include #endif +#include //===----------------------------------------------------------------------===// //=== WARNING: Implementation here must contain only generic UNIX code that @@ -266,8 +265,8 @@ static bool terminalHasColors(int fd) { #ifdef HAVE_TERMINFO // First, acquire a global lock because these C routines are thread hostile. - static sys::Mutex M; - MutexGuard G(M); + static std::recursive_mutex M; + std::lock_guard G(M); int errret = 0; if (setupterm((char *)nullptr, fd, &errret) != 0) Index: lib/Target/NVPTX/NVPTXUtilities.cpp =================================================================== --- lib/Target/NVPTX/NVPTXUtilities.cpp +++ lib/Target/NVPTX/NVPTXUtilities.cpp @@ -15,16 +15,17 @@ #include "llvm/IR/Constants.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalVariable.h" +#include "llvm/IR/InstIterator.h" #include "llvm/IR/Module.h" #include "llvm/IR/Operator.h" +#include "llvm/Support/ManagedStatic.h" + #include #include #include +#include #include #include -#include "llvm/Support/ManagedStatic.h" -#include "llvm/IR/InstIterator.h" -#include "llvm/Support/MutexGuard.h" using namespace llvm; @@ -33,15 +34,15 @@ typedef std::map per_module_annot_t; ManagedStatic annotationCache; -static sys::Mutex Lock; +static std::recursive_mutex Lock; void llvm::clearAnnotationCache(const llvm::Module *Mod) { - MutexGuard Guard(Lock); + std::lock_guard Guard(Lock); annotationCache->erase(Mod); } static void cacheAnnotationFromMD(const MDNode *md, key_val_pair_t &retval) { - MutexGuard Guard(Lock); + std::lock_guard Guard(Lock); assert(md && "Invalid mdnode for annotation"); assert((md->getNumOperands() % 2) == 1 && "Invalid number of operands"); // start index = 1, to skip the global variable key @@ -67,7 +68,7 @@ } static void cacheAnnotationFromMD(const Module *m, const GlobalValue *gv) { - MutexGuard Guard(Lock); + std::lock_guard Guard(Lock); NamedMDNode *NMD = m->getNamedMetadata(llvm::NamedMDForAnnotations); if (!NMD) return; @@ -100,7 +101,7 @@ bool llvm::findOneNVVMAnnotation(const GlobalValue *gv, std::string prop, unsigned &retval) { - MutexGuard Guard(Lock); + std::lock_guard Guard(Lock); const Module *m = gv->getParent(); if ((*annotationCache).find(m) == (*annotationCache).end()) cacheAnnotationFromMD(m, gv); @@ -114,7 +115,7 @@ bool llvm::findAllNVVMAnnotation(const GlobalValue *gv, std::string prop, std::vector &retval) { - MutexGuard Guard(Lock); + std::lock_guard Guard(Lock); const Module *m = gv->getParent(); if ((*annotationCache).find(m) == (*annotationCache).end()) cacheAnnotationFromMD(m, gv);