From 1e3e6362c8def5abcbc9a89c02619a0912177f7e Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Thu, 16 Sep 2010 23:32:35 +0000 Subject: [PATCH] Do not expose the locking for the PassRegistry in the header. Be careful to synchronize any method that might lazily initialize the pImpl. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114130 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/PassRegistry.h | 2 -- lib/VMCore/PassRegistry.cpp | 9 ++++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/llvm/PassRegistry.h b/include/llvm/PassRegistry.h index 8b7f036e20c..31d48a4e28f 100644 --- a/include/llvm/PassRegistry.h +++ b/include/llvm/PassRegistry.h @@ -18,7 +18,6 @@ #define LLVM_PASSREGISTRY_H #include "llvm/ADT/StringRef.h" -#include "llvm/System/Mutex.h" namespace llvm { @@ -33,7 +32,6 @@ struct PassRegistrationListener; /// each thread. class PassRegistry { mutable void *pImpl; - mutable sys::SmartMutex Lock; void *getImpl() const; public: diff --git a/lib/VMCore/PassRegistry.cpp b/lib/VMCore/PassRegistry.cpp index 0b4e59dc0e6..61565770226 100644 --- a/lib/VMCore/PassRegistry.cpp +++ b/lib/VMCore/PassRegistry.cpp @@ -16,6 +16,7 @@ #include "llvm/PassSupport.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/ManagedStatic.h" +#include "llvm/System/Mutex.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/StringMap.h" @@ -33,6 +34,8 @@ PassRegistry *PassRegistry::getPassRegistry() { return &*PassRegistryObj; } +sys::SmartMutex Lock; + //===----------------------------------------------------------------------===// // PassRegistryImpl // @@ -65,18 +68,21 @@ void *PassRegistry::getImpl() const { // PassRegistry::~PassRegistry() { + sys::SmartScopedLock Guard(Lock); PassRegistryImpl *Impl = static_cast(pImpl); if (Impl) delete Impl; pImpl = 0; } const PassInfo *PassRegistry::getPassInfo(const void *TI) const { + sys::SmartScopedLock Guard(Lock); PassRegistryImpl *Impl = static_cast(getImpl()); PassRegistryImpl::MapType::const_iterator I = Impl->PassInfoMap.find(TI); return I != Impl->PassInfoMap.end() ? I->second : 0; } const PassInfo *PassRegistry::getPassInfo(StringRef Arg) const { + sys::SmartScopedLock Guard(Lock); PassRegistryImpl *Impl = static_cast(getImpl()); PassRegistryImpl::StringMapType::const_iterator I = Impl->PassInfoStringMap.find(Arg); @@ -127,7 +133,6 @@ void PassRegistry::registerAnalysisGroup(const void *InterfaceID, const void *PassID, PassInfo& Registeree, bool isDefault) { - sys::SmartScopedLock Guard(Lock); PassInfo *InterfaceInfo = const_cast(getPassInfo(InterfaceID)); if (InterfaceInfo == 0) { // First reference to Interface, register it now. @@ -142,6 +147,8 @@ void PassRegistry::registerAnalysisGroup(const void *InterfaceID, assert(ImplementationInfo && "Must register pass before adding to AnalysisGroup!"); + sys::SmartScopedLock Guard(Lock); + // Make sure we keep track of the fact that the implementation implements // the interface. ImplementationInfo->addInterfaceImplemented(InterfaceInfo); -- 2.34.1