diff --git a/include/llvm/PassRegistry.h b/include/llvm/PassRegistry.h index 31d48a4e28f..8b7f036e20c 100644 --- a/include/llvm/PassRegistry.h +++ b/include/llvm/PassRegistry.h @@ -18,6 +18,7 @@ #define LLVM_PASSREGISTRY_H #include "llvm/ADT/StringRef.h" +#include "llvm/System/Mutex.h" namespace llvm { @@ -32,6 +33,7 @@ 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 c6dc9210cb2..0b4e59dc0e6 100644 --- a/lib/VMCore/PassRegistry.cpp +++ b/lib/VMCore/PassRegistry.cpp @@ -88,6 +88,7 @@ const PassInfo *PassRegistry::getPassInfo(StringRef Arg) const { // void PassRegistry::registerPass(const PassInfo &PI) { + sys::SmartScopedLock Guard(Lock); PassRegistryImpl *Impl = static_cast(getImpl()); bool Inserted = Impl->PassInfoMap.insert(std::make_pair(PI.getTypeInfo(),&PI)).second; @@ -101,6 +102,7 @@ void PassRegistry::registerPass(const PassInfo &PI) { } void PassRegistry::unregisterPass(const PassInfo &PI) { + sys::SmartScopedLock Guard(Lock); PassRegistryImpl *Impl = static_cast(getImpl()); PassRegistryImpl::MapType::iterator I = Impl->PassInfoMap.find(PI.getTypeInfo()); @@ -112,6 +114,7 @@ void PassRegistry::unregisterPass(const PassInfo &PI) { } void PassRegistry::enumerateWith(PassRegistrationListener *L) { + sys::SmartScopedLock Guard(Lock); PassRegistryImpl *Impl = static_cast(getImpl()); for (PassRegistryImpl::MapType::const_iterator I = Impl->PassInfoMap.begin(), E = Impl->PassInfoMap.end(); I != E; ++I) @@ -124,6 +127,7 @@ 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. @@ -159,11 +163,14 @@ void PassRegistry::registerAnalysisGroup(const void *InterfaceID, } void PassRegistry::addRegistrationListener(PassRegistrationListener *L) { + sys::SmartScopedLock Guard(Lock); PassRegistryImpl *Impl = static_cast(getImpl()); Impl->Listeners.push_back(L); } void PassRegistry::removeRegistrationListener(PassRegistrationListener *L) { + sys::SmartScopedLock Guard(Lock); + // NOTE: This is necessary, because removeRegistrationListener() can be called // as part of the llvm_shutdown sequence. Since we have no control over the // order of that sequence, we need to gracefully handle the case where the