[llvm-commits] [llvm] r114036 - in /llvm/trunk: include/llvm/PassRegistry.h lib/VMCore/PassRegistry.cpp
Chris Lattner
clattner at apple.com
Wed Sep 15 18:12:05 PDT 2010
On Sep 15, 2010, at 4:03 PM, Owen Anderson wrote:
> Author: resistor
> Date: Wed Sep 15 18:03:33 2010
> New Revision: 114036
>
> URL: http://llvm.org/viewvc/llvm-project?rev=114036&view=rev
> Log:
> 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.
Ok, but please don't add the mutex to PassRegistry, add it to the impl.
-Chris
>
> Modified:
> llvm/trunk/include/llvm/PassRegistry.h
> llvm/trunk/lib/VMCore/PassRegistry.cpp
>
> Modified: llvm/trunk/include/llvm/PassRegistry.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/PassRegistry.h?rev=114036&r1=114035&r2=114036&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/PassRegistry.h (original)
> +++ llvm/trunk/include/llvm/PassRegistry.h Wed Sep 15 18:03:33 2010
> @@ -18,6 +18,7 @@
> #define LLVM_PASSREGISTRY_H
>
> #include "llvm/ADT/StringRef.h"
> +#include "llvm/System/Mutex.h"
>
> namespace llvm {
>
> @@ -32,6 +33,7 @@
> /// each thread.
> class PassRegistry {
> mutable void *pImpl;
> + mutable sys::SmartMutex<true> Lock;
> void *getImpl() const;
>
> public:
>
> Modified: llvm/trunk/lib/VMCore/PassRegistry.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/PassRegistry.cpp?rev=114036&r1=114035&r2=114036&view=diff
> ==============================================================================
> --- llvm/trunk/lib/VMCore/PassRegistry.cpp (original)
> +++ llvm/trunk/lib/VMCore/PassRegistry.cpp Wed Sep 15 18:03:33 2010
> @@ -88,6 +88,7 @@
> //
>
> 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::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::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 @@
> 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::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
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list