diff options
author | Owen Anderson <resistor@mac.com> | 2010-09-15 23:03:33 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2010-09-15 23:03:33 +0000 |
commit | b6d760c7d5e8496475a0063c32f87bd6161cb2db (patch) | |
tree | 0cf860ffa4c2083289f07d9d562299de9bb76a44 /lib/VMCore/PassRegistry.cpp | |
parent | 8a26f818896c6a02ebdb11d624cb9ef39f082df2 (diff) | |
download | llvm-b6d760c7d5e8496475a0063c32f87bd6161cb2db.tar.gz llvm-b6d760c7d5e8496475a0063c32f87bd6161cb2db.tar.bz2 llvm-b6d760c7d5e8496475a0063c32f87bd6161cb2db.tar.xz |
Since PassRegistry is currently a shared global object, it needs locking. While it might intuitively seem
that all the setup of this class currently happens at static initialization time, this misses the fact
that some later events can cause mutation of the PassRegistrationListeners list, and thus cause race issues.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114036 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/PassRegistry.cpp')
-rw-r--r-- | lib/VMCore/PassRegistry.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/VMCore/PassRegistry.cpp b/lib/VMCore/PassRegistry.cpp index c6dc9210cb..0b4e59dc0e 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<true> Guard(Lock); PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(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<true> Guard(Lock); PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(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<true> Guard(Lock); PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(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<true> Guard(Lock); PassInfo *InterfaceInfo = const_cast<PassInfo*>(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<true> Guard(Lock); PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(getImpl()); Impl->Listeners.push_back(L); } void PassRegistry::removeRegistrationListener(PassRegistrationListener *L) { + sys::SmartScopedLock<true> 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 |