From: Benjamin Kramer Date: Wed, 7 Aug 2019 10:57:25 +0000 (+0000) Subject: Replace llvm::MutexGuard/UniqueLock with their standard equivalents X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=82f727d27c5a716bb01ab722f6bd5edc37aa2239;p=llvm Replace llvm::MutexGuard/UniqueLock with their standard equivalents All supported platforms have now, so we don't need our own copies any longer. No functionality change intended. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368149 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/IR/ValueMap.h b/include/llvm/IR/ValueMap.h index 6a79b1d387f..faa27039af1 100644 --- a/include/llvm/IR/ValueMap.h +++ b/include/llvm/IR/ValueMap.h @@ -33,11 +33,11 @@ #include "llvm/IR/ValueHandle.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Mutex.h" -#include "llvm/Support/UniqueLock.h" #include #include #include #include +#include #include #include @@ -266,9 +266,9 @@ public: // Make a copy that won't get changed even when *this is destroyed. ValueMapCallbackVH Copy(*this); typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data); - unique_lock Guard; + std::unique_lock Guard; if (M) - Guard = unique_lock(*M); + Guard = std::unique_lock(*M); Config::onDelete(Copy.Map->Data, Copy.Unwrap()); // May destroy *this. Copy.Map->Map.erase(Copy); // Definitely destroys *this. } @@ -279,9 +279,9 @@ public: // Make a copy that won't get changed even when *this is destroyed. ValueMapCallbackVH Copy(*this); typename Config::mutex_type *M = Config::getMutex(Copy.Map->Data); - unique_lock Guard; + std::unique_lock Guard; if (M) - Guard = unique_lock(*M); + Guard = std::unique_lock(*M); KeyT typed_new_key = cast(new_key); // Can destroy *this: diff --git a/include/llvm/Support/MutexGuard.h b/include/llvm/Support/MutexGuard.h deleted file mode 100644 index d86ced14581..00000000000 --- a/include/llvm/Support/MutexGuard.h +++ /dev/null @@ -1,40 +0,0 @@ -//===-- Support/MutexGuard.h - Acquire/Release Mutex In Scope ---*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file defines a guard for a block of code that ensures a Mutex is locked -// upon construction and released upon destruction. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_SUPPORT_MUTEXGUARD_H -#define LLVM_SUPPORT_MUTEXGUARD_H - -#include "llvm/Support/Mutex.h" - -namespace llvm { - /// Instances of this class acquire a given Mutex Lock when constructed and - /// hold that lock until destruction. The intention is to instantiate one of - /// these on the stack at the top of some scope to be assured that C++ - /// destruction of the object will always release the Mutex and thus avoid - /// a host of nasty multi-threading problems in the face of exceptions, etc. - /// Guard a section of code with a Mutex. - class MutexGuard { - sys::Mutex &M; - MutexGuard(const MutexGuard &) = delete; - void operator=(const MutexGuard &) = delete; - public: - MutexGuard(sys::Mutex &m) : M(m) { M.lock(); } - ~MutexGuard() { M.unlock(); } - /// holds - Returns true if this locker instance holds the specified lock. - /// This is mostly used in assertions to validate that the correct mutex - /// is held. - bool holds(const sys::Mutex& lock) const { return &M == &lock; } - }; -} - -#endif // LLVM_SUPPORT_MUTEXGUARD_H diff --git a/include/llvm/Support/UnicodeCharRanges.h b/include/llvm/Support/UnicodeCharRanges.h index 4b59f8a92b7..73d3603b74d 100644 --- a/include/llvm/Support/UnicodeCharRanges.h +++ b/include/llvm/Support/UnicodeCharRanges.h @@ -9,11 +9,8 @@ #define LLVM_SUPPORT_UNICODECHARRANGES_H #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/SmallPtrSet.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" -#include "llvm/Support/Mutex.h" -#include "llvm/Support/MutexGuard.h" #include "llvm/Support/raw_ostream.h" #include diff --git a/include/llvm/Support/UniqueLock.h b/include/llvm/Support/UniqueLock.h deleted file mode 100644 index 0a887ad5965..00000000000 --- a/include/llvm/Support/UniqueLock.h +++ /dev/null @@ -1,68 +0,0 @@ -//===- Support/UniqueLock.h - Acquire/Release Mutex In Scope ----*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file defines a guard for a block of code that ensures a Mutex is locked -// upon construction and released upon destruction. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_SUPPORT_UNIQUE_LOCK_H -#define LLVM_SUPPORT_UNIQUE_LOCK_H - -#include - -namespace llvm { - - /// A pared-down imitation of std::unique_lock from C++11. Contrary to the - /// name, it's really more of a wrapper for a lock. It may or may not have - /// an associated mutex, which is guaranteed to be locked upon creation - /// and unlocked after destruction. unique_lock can also unlock the mutex - /// and re-lock it freely during its lifetime. - /// Guard a section of code with a mutex. - template - class unique_lock { - MutexT *M = nullptr; - bool locked = false; - - public: - unique_lock() = default; - explicit unique_lock(MutexT &m) : M(&m), locked(true) { M->lock(); } - unique_lock(const unique_lock &) = delete; - unique_lock &operator=(const unique_lock &) = delete; - - void operator=(unique_lock &&o) { - if (owns_lock()) - M->unlock(); - M = o.M; - locked = o.locked; - o.M = nullptr; - o.locked = false; - } - - ~unique_lock() { if (owns_lock()) M->unlock(); } - - void lock() { - assert(!locked && "mutex already locked!"); - assert(M && "no associated mutex!"); - M->lock(); - locked = true; - } - - void unlock() { - assert(locked && "unlocking a mutex that isn't locked!"); - assert(M && "no associated mutex!"); - M->unlock(); - locked = false; - } - - bool owns_lock() { return locked; } - }; - -} // end namespace llvm - -#endif // LLVM_SUPPORT_UNIQUE_LOCK_H diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index 1c6c0406d04..75ac80f4b75 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -32,12 +32,12 @@ #include "llvm/Support/DynamicLibrary.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Host.h" -#include "llvm/Support/MutexGuard.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetMachine.h" #include #include +#include using namespace llvm; #define DEBUG_TYPE "jit" @@ -191,7 +191,7 @@ uint64_t ExecutionEngineState::RemoveMapping(StringRef Name) { std::string ExecutionEngine::getMangledName(const GlobalValue *GV) { assert(GV->hasName() && "Global must have name."); - MutexGuard locked(lock); + std::lock_guard locked(lock); SmallString<128> FullName; const DataLayout &DL = @@ -204,12 +204,12 @@ std::string ExecutionEngine::getMangledName(const GlobalValue *GV) { } void ExecutionEngine::addGlobalMapping(const GlobalValue *GV, void *Addr) { - MutexGuard locked(lock); + std::lock_guard locked(lock); addGlobalMapping(getMangledName(GV), (uint64_t) Addr); } void ExecutionEngine::addGlobalMapping(StringRef Name, uint64_t Addr) { - MutexGuard locked(lock); + std::lock_guard locked(lock); assert(!Name.empty() && "Empty GlobalMapping symbol name!"); @@ -228,14 +228,14 @@ void ExecutionEngine::addGlobalMapping(StringRef Name, uint64_t Addr) { } void ExecutionEngine::clearAllGlobalMappings() { - MutexGuard locked(lock); + std::lock_guard locked(lock); EEState.getGlobalAddressMap().clear(); EEState.getGlobalAddressReverseMap().clear(); } void ExecutionEngine::clearGlobalMappingsFromModule(Module *M) { - MutexGuard locked(lock); + std::lock_guard locked(lock); for (GlobalObject &GO : M->global_objects()) EEState.RemoveMapping(getMangledName(&GO)); @@ -243,12 +243,12 @@ void ExecutionEngine::clearGlobalMappingsFromModule(Module *M) { uint64_t ExecutionEngine::updateGlobalMapping(const GlobalValue *GV, void *Addr) { - MutexGuard locked(lock); + std::lock_guard locked(lock); return updateGlobalMapping(getMangledName(GV), (uint64_t) Addr); } uint64_t ExecutionEngine::updateGlobalMapping(StringRef Name, uint64_t Addr) { - MutexGuard locked(lock); + std::lock_guard locked(lock); ExecutionEngineState::GlobalAddressMapTy &Map = EEState.getGlobalAddressMap(); @@ -275,7 +275,7 @@ uint64_t ExecutionEngine::updateGlobalMapping(StringRef Name, uint64_t Addr) { } uint64_t ExecutionEngine::getAddressToGlobalIfAvailable(StringRef S) { - MutexGuard locked(lock); + std::lock_guard locked(lock); uint64_t Address = 0; ExecutionEngineState::GlobalAddressMapTy::iterator I = EEState.getGlobalAddressMap().find(S); @@ -286,19 +286,19 @@ uint64_t ExecutionEngine::getAddressToGlobalIfAvailable(StringRef S) { void *ExecutionEngine::getPointerToGlobalIfAvailable(StringRef S) { - MutexGuard locked(lock); + std::lock_guard locked(lock); if (void* Address = (void *) getAddressToGlobalIfAvailable(S)) return Address; return nullptr; } void *ExecutionEngine::getPointerToGlobalIfAvailable(const GlobalValue *GV) { - MutexGuard locked(lock); + std::lock_guard locked(lock); return getPointerToGlobalIfAvailable(getMangledName(GV)); } const GlobalValue *ExecutionEngine::getGlobalValueAtAddress(void *Addr) { - MutexGuard locked(lock); + std::lock_guard locked(lock); // If we haven't computed the reverse mapping yet, do so first. if (EEState.getGlobalAddressReverseMap().empty()) { @@ -575,7 +575,7 @@ void *ExecutionEngine::getPointerToGlobal(const GlobalValue *GV) { if (Function *F = const_cast(dyn_cast(GV))) return getPointerToFunction(F); - MutexGuard locked(lock); + std::lock_guard locked(lock); if (void* P = getPointerToGlobalIfAvailable(GV)) return P; diff --git a/lib/ExecutionEngine/GDBRegistrationListener.cpp b/lib/ExecutionEngine/GDBRegistrationListener.cpp index 08d20156a59..7ed025fbb48 100644 --- a/lib/ExecutionEngine/GDBRegistrationListener.cpp +++ b/lib/ExecutionEngine/GDBRegistrationListener.cpp @@ -14,7 +14,7 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Mutex.h" -#include "llvm/Support/MutexGuard.h" +#include using namespace llvm; using namespace llvm::object; @@ -135,7 +135,7 @@ void NotifyDebugger(jit_code_entry* JITCodeEntry) { GDBJITRegistrationListener::~GDBJITRegistrationListener() { // 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) { @@ -159,7 +159,7 @@ void GDBJITRegistrationListener::notifyObjectLoaded( const char *Buffer = DebugObj.getBinary()->getMemoryBufferRef().getBufferStart(); size_t Size = DebugObj.getBinary()->getMemoryBufferRef().getBufferSize(); - llvm::MutexGuard locked(*JITDebugLock); + std::lock_guard locked(*JITDebugLock); assert(ObjectBufferMap.find(K) == ObjectBufferMap.end() && "Second attempt to perform debug registration."); jit_code_entry* JITCodeEntry = new jit_code_entry(); @@ -178,7 +178,7 @@ void GDBJITRegistrationListener::notifyObjectLoaded( } void GDBJITRegistrationListener::notifyFreeingObject(ObjectKey K) { - llvm::MutexGuard locked(*JITDebugLock); + std::lock_guard locked(*JITDebugLock); RegisteredObjectBufferMap::iterator I = ObjectBufferMap.find(K); if (I != ObjectBufferMap.end()) { diff --git a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp index c3a2ccc582c..71b7f893d71 100644 --- a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp +++ b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp @@ -32,7 +32,6 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Mutex.h" -#include "llvm/Support/UniqueLock.h" #include "llvm/Support/raw_ostream.h" #include #include @@ -41,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -258,7 +258,7 @@ GenericValue Interpreter::callExternalFunction(Function *F, ArrayRef ArgVals) { TheInterpreter = this; - unique_lock Guard(*FunctionsLock); + std::unique_lock Guard(*FunctionsLock); // Do a lookup to see if the function is in our cache... this should just be a // deferred annotation! diff --git a/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/lib/ExecutionEngine/MCJIT/MCJIT.cpp index 08815b7a80a..94741f5f01d 100644 --- a/lib/ExecutionEngine/MCJIT/MCJIT.cpp +++ b/lib/ExecutionEngine/MCJIT/MCJIT.cpp @@ -23,7 +23,7 @@ #include "llvm/Support/DynamicLibrary.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/MutexGuard.h" +#include using namespace llvm; @@ -88,7 +88,7 @@ MCJIT::MCJIT(std::unique_ptr M, std::unique_ptr TM, } MCJIT::~MCJIT() { - MutexGuard locked(lock); + std::lock_guard locked(lock); Dyld.deregisterEHFrames(); @@ -100,7 +100,7 @@ MCJIT::~MCJIT() { } void MCJIT::addModule(std::unique_ptr M) { - MutexGuard locked(lock); + std::lock_guard locked(lock); if (M->getDataLayout().isDefault()) M->setDataLayout(getDataLayout()); @@ -109,7 +109,7 @@ void MCJIT::addModule(std::unique_ptr M) { } bool MCJIT::removeModule(Module *M) { - MutexGuard locked(lock); + std::lock_guard locked(lock); return OwnedModules.removeModule(M); } @@ -136,14 +136,14 @@ void MCJIT::addArchive(object::OwningBinary A) { } void MCJIT::setObjectCache(ObjectCache* NewCache) { - MutexGuard locked(lock); + std::lock_guard locked(lock); ObjCache = NewCache; } std::unique_ptr MCJIT::emitObject(Module *M) { assert(M && "Can not emit a null module"); - MutexGuard locked(lock); + std::lock_guard locked(lock); // Materialize all globals in the module if they have not been // materialized already. @@ -185,7 +185,7 @@ std::unique_ptr MCJIT::emitObject(Module *M) { void MCJIT::generateCodeForModule(Module *M) { // Get a thread lock to make sure we aren't trying to load multiple times - MutexGuard locked(lock); + std::lock_guard locked(lock); // This must be a module which has already been added to this MCJIT instance. assert(OwnedModules.ownsModule(M) && @@ -234,7 +234,7 @@ void MCJIT::generateCodeForModule(Module *M) { } void MCJIT::finalizeLoadedModules() { - MutexGuard locked(lock); + std::lock_guard locked(lock); // Resolve any outstanding relocations. Dyld.resolveRelocations(); @@ -250,7 +250,7 @@ void MCJIT::finalizeLoadedModules() { // FIXME: Rename this. void MCJIT::finalizeObject() { - MutexGuard locked(lock); + std::lock_guard locked(lock); // Generate code for module is going to move objects out of the 'added' list, // so we need to copy that out before using it: @@ -265,7 +265,7 @@ void MCJIT::finalizeObject() { } void MCJIT::finalizeModule(Module *M) { - MutexGuard locked(lock); + std::lock_guard locked(lock); // This must be a module which has already been added to this MCJIT instance. assert(OwnedModules.ownsModule(M) && "MCJIT::finalizeModule: Unknown module."); @@ -292,7 +292,7 @@ Module *MCJIT::findModuleForSymbol(const std::string &Name, if (DemangledName[0] == getDataLayout().getGlobalPrefix()) DemangledName = DemangledName.substr(1); - MutexGuard locked(lock); + std::lock_guard locked(lock); // If it hasn't already been generated, see if it's in one of our modules. for (ModulePtrSet::iterator I = OwnedModules.begin_added(), @@ -332,7 +332,7 @@ uint64_t MCJIT::getSymbolAddress(const std::string &Name, JITSymbol MCJIT::findSymbol(const std::string &Name, bool CheckFunctionsOnly) { - MutexGuard locked(lock); + std::lock_guard locked(lock); // First, check to see if we already have this symbol. if (auto Sym = findExistingSymbol(Name)) @@ -388,7 +388,7 @@ JITSymbol MCJIT::findSymbol(const std::string &Name, } uint64_t MCJIT::getGlobalValueAddress(const std::string &Name) { - MutexGuard locked(lock); + std::lock_guard locked(lock); uint64_t Result = getSymbolAddress(Name, false); if (Result != 0) finalizeLoadedModules(); @@ -396,7 +396,7 @@ uint64_t MCJIT::getGlobalValueAddress(const std::string &Name) { } uint64_t MCJIT::getFunctionAddress(const std::string &Name) { - MutexGuard locked(lock); + std::lock_guard locked(lock); uint64_t Result = getSymbolAddress(Name, true); if (Result != 0) finalizeLoadedModules(); @@ -405,7 +405,7 @@ uint64_t MCJIT::getFunctionAddress(const std::string &Name) { // Deprecated. Use getFunctionAddress instead. void *MCJIT::getPointerToFunction(Function *F) { - MutexGuard locked(lock); + std::lock_guard locked(lock); Mangler Mang; SmallString<128> Name; @@ -632,14 +632,14 @@ void *MCJIT::getPointerToNamedFunction(StringRef Name, bool AbortOnFailure) { void MCJIT::RegisterJITEventListener(JITEventListener *L) { if (!L) return; - MutexGuard locked(lock); + std::lock_guard locked(lock); EventListeners.push_back(L); } void MCJIT::UnregisterJITEventListener(JITEventListener *L) { if (!L) return; - MutexGuard locked(lock); + std::lock_guard locked(lock); auto I = find(reverse(EventListeners), L); if (I != EventListeners.rend()) { std::swap(*I, EventListeners.back()); @@ -651,7 +651,7 @@ void MCJIT::notifyObjectLoaded(const object::ObjectFile &Obj, const RuntimeDyld::LoadedObjectInfo &L) { uint64_t Key = static_cast(reinterpret_cast(Obj.getData().data())); - MutexGuard locked(lock); + std::lock_guard locked(lock); MemMgr->notifyObjectLoaded(this, Obj); for (unsigned I = 0, S = EventListeners.size(); I < S; ++I) { EventListeners[I]->notifyObjectLoaded(Key, Obj, L); @@ -661,7 +661,7 @@ void MCJIT::notifyObjectLoaded(const object::ObjectFile &Obj, void MCJIT::notifyFreeingObject(const object::ObjectFile &Obj) { uint64_t Key = static_cast(reinterpret_cast(Obj.getData().data())); - MutexGuard locked(lock); + std::lock_guard locked(lock); for (JITEventListener *L : EventListeners) L->notifyFreeingObject(Key); } diff --git a/lib/ExecutionEngine/OProfileJIT/OProfileWrapper.cpp b/lib/ExecutionEngine/OProfileJIT/OProfileWrapper.cpp index 1a266773692..b78d2531382 100644 --- a/lib/ExecutionEngine/OProfileJIT/OProfileWrapper.cpp +++ b/lib/ExecutionEngine/OProfileJIT/OProfileWrapper.cpp @@ -17,11 +17,11 @@ #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 @@ -54,7 +54,7 @@ bool OProfileWrapper::initialize() { using namespace llvm; using namespace llvm::sys; - MutexGuard Guard(OProfileInitializationMutex); + std::lock_guard Guard(OProfileInitializationMutex); if (Initialized) return OpenAgentFunc != 0; diff --git a/lib/ExecutionEngine/PerfJITEvents/PerfJITEventListener.cpp b/lib/ExecutionEngine/PerfJITEvents/PerfJITEventListener.cpp index 5606421a3cb..5a898d96d7d 100644 --- a/lib/ExecutionEngine/PerfJITEvents/PerfJITEventListener.cpp +++ b/lib/ExecutionEngine/PerfJITEvents/PerfJITEventListener.cpp @@ -26,11 +26,11 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Mutex.h" -#include "llvm/Support/MutexGuard.h" #include "llvm/Support/Path.h" #include "llvm/Support/Process.h" #include "llvm/Support/Threading.h" #include "llvm/Support/raw_ostream.h" +#include #include // mmap() #include // getpid() @@ -420,7 +420,7 @@ void PerfJITEventListener::NotifyCode(Expected &Symbol, rec.Tid = get_threadid(); // avoid interspersing output - MutexGuard Guard(Mutex); + std::lock_guard Guard(Mutex); rec.CodeIndex = CodeGeneration++; // under lock! @@ -462,7 +462,7 @@ void PerfJITEventListener::NotifyDebug(uint64_t CodeAddr, // * char name[n] : source file name in ASCII, including null termination // avoid interspersing output - MutexGuard Guard(Mutex); + std::lock_guard Guard(Mutex); Dumpstream->write(reinterpret_cast(&rec), sizeof(rec)); diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp index e26e6ce45db..f73d1c61edf 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp @@ -20,7 +20,7 @@ #include "llvm/Support/MSVCErrorWorkarounds.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MathExtras.h" -#include "llvm/Support/MutexGuard.h" +#include #include @@ -120,7 +120,7 @@ static void dumpSectionMemory(const SectionEntry &S, StringRef State) { // Resolve the relocations for all symbols we currently know about. void RuntimeDyldImpl::resolveRelocations() { - MutexGuard locked(lock); + std::lock_guard locked(lock); // Print out the sections prior to relocation. LLVM_DEBUG(for (int i = 0, e = Sections.size(); i != e; ++i) @@ -156,7 +156,7 @@ void RuntimeDyldImpl::resolveLocalRelocations() { 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].getAddress() == LocalAddress) { reassignSectionAddress(i, TargetAddress); @@ -177,7 +177,7 @@ static Error getOffset(const SymbolRef &Sym, SectionRef Sec, Expected RuntimeDyldImpl::loadObjectImpl(const object::ObjectFile &Obj) { - MutexGuard locked(lock); + std::lock_guard locked(lock); // Save information about our target Arch = (Triple::ArchType)Obj.getArch(); diff --git a/lib/Support/ManagedStatic.cpp b/lib/Support/ManagedStatic.cpp index 28ceb1a70e4..c51ef96e9f8 100644 --- a/lib/Support/ManagedStatic.cpp +++ b/lib/Support/ManagedStatic.cpp @@ -13,9 +13,9 @@ #include "llvm/Support/ManagedStatic.h" #include "llvm/Config/config.h" #include "llvm/Support/Mutex.h" -#include "llvm/Support/MutexGuard.h" #include "llvm/Support/Threading.h" #include +#include using namespace llvm; static const ManagedStaticBase *StaticList = nullptr; @@ -35,7 +35,7 @@ void ManagedStaticBase::RegisterManagedStatic(void *(*Creator)(), void (*Deleter)(void*)) const { assert(Creator); if (llvm_is_multithreaded()) { - MutexGuard Lock(*getManagedStaticMutex()); + std::lock_guard Lock(*getManagedStaticMutex()); if (!Ptr.load(std::memory_order_relaxed)) { void *Tmp = Creator(); @@ -77,7 +77,7 @@ void ManagedStaticBase::destroy() const { /// llvm_shutdown - Deallocate and destroy all ManagedStatic variables. void llvm::llvm_shutdown() { - MutexGuard Lock(*getManagedStaticMutex()); + std::lock_guard Lock(*getManagedStaticMutex()); while (StaticList) StaticList->destroy(); diff --git a/lib/Support/Unix/Process.inc b/lib/Support/Unix/Process.inc index 4115ee39658..86101e47391 100644 --- a/lib/Support/Unix/Process.inc +++ b/lib/Support/Unix/Process.inc @@ -16,7 +16,7 @@ #include "llvm/Config/config.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Mutex.h" -#include "llvm/Support/MutexGuard.h" +#include #if HAVE_FCNTL_H #include #endif @@ -333,7 +333,7 @@ static ManagedStatic TermColorMutex; static bool terminalHasColors(int fd) { #ifdef HAVE_TERMINFO // First, acquire a global lock because these C routines are thread hostile. - MutexGuard G(*TermColorMutex); + std::lock_guard G(*TermColorMutex); int errret = 0; if (setupterm(nullptr, fd, &errret) != 0) diff --git a/lib/Support/Unix/Signals.inc b/lib/Support/Unix/Signals.inc index 634c16aa36c..be05eabfb2e 100644 --- a/lib/Support/Unix/Signals.inc +++ b/lib/Support/Unix/Signals.inc @@ -43,7 +43,6 @@ #include "llvm/Support/Mutex.h" #include "llvm/Support/Program.h" #include "llvm/Support/SaveAndRestore.h" -#include "llvm/Support/UniqueLock.h" #include "llvm/Support/raw_ostream.h" #include #include diff --git a/lib/Target/NVPTX/NVPTXUtilities.cpp b/lib/Target/NVPTX/NVPTXUtilities.cpp index 665eb138325..43c2e992040 100644 --- a/lib/Target/NVPTX/NVPTXUtilities.cpp +++ b/lib/Target/NVPTX/NVPTXUtilities.cpp @@ -19,10 +19,11 @@ #include "llvm/IR/Module.h" #include "llvm/IR/Operator.h" #include "llvm/Support/ManagedStatic.h" -#include "llvm/Support/MutexGuard.h" +#include "llvm/Support/Mutex.h" #include #include #include +#include #include #include @@ -38,12 +39,12 @@ static ManagedStatic annotationCache; static sys::Mutex Lock; void clearAnnotationCache(const 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 @@ -69,7 +70,7 @@ static void cacheAnnotationFromMD(const MDNode *md, key_val_pair_t &retval) { } static void cacheAnnotationFromMD(const Module *m, const GlobalValue *gv) { - MutexGuard Guard(Lock); + std::lock_guard Guard(Lock); NamedMDNode *NMD = m->getNamedMetadata("nvvm.annotations"); if (!NMD) return; @@ -103,7 +104,7 @@ static void cacheAnnotationFromMD(const Module *m, const GlobalValue *gv) { bool findOneNVVMAnnotation(const GlobalValue *gv, const 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); @@ -117,7 +118,7 @@ bool findOneNVVMAnnotation(const GlobalValue *gv, const std::string &prop, bool findAllNVVMAnnotation(const GlobalValue *gv, const 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);