[llvm-commits] [llvm] r74029 - /llvm/trunk/lib/VMCore/Pass.cpp
Owen Anderson
resistor at mac.com
Tue Jun 23 17:25:42 PDT 2009
Author: resistor
Date: Tue Jun 23 19:25:42 2009
New Revision: 74029
URL: http://llvm.org/viewvc/llvm-project?rev=74029&view=rev
Log:
Guard the listeners list. Unfortunately, this requires a real static rather
than a managed static because other managed statics can (and do) access this
list in their destructors. Yes, I know it's horrible.
Modified:
llvm/trunk/lib/VMCore/Pass.cpp
Modified: llvm/trunk/lib/VMCore/Pass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Pass.cpp?rev=74029&r1=74028&r2=74029&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Pass.cpp (original)
+++ llvm/trunk/lib/VMCore/Pass.cpp Tue Jun 23 19:25:42 2009
@@ -20,6 +20,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/System/Atomic.h"
+#include "llvm/System/Mutex.h"
#include "llvm/System/Threading.h"
#include <algorithm>
#include <map>
@@ -187,6 +188,7 @@
}
static std::vector<PassRegistrationListener*> *Listeners = 0;
+static sys::SmartMutex<true> ListenersLock;
// FIXME: This should use ManagedStatic to manage the pass registrar.
// Unfortunately, we can't do this, because passes are registered with static
@@ -231,6 +233,7 @@
getPassRegistrar()->RegisterPass(*this);
// Notify any listeners.
+ sys::SmartScopedLock<true> Lock(&ListenersLock);
if (Listeners)
for (std::vector<PassRegistrationListener*>::iterator
I = Listeners->begin(), E = Listeners->end(); I != E; ++I)
@@ -283,12 +286,14 @@
// PassRegistrationListener ctor - Add the current object to the list of
// PassRegistrationListeners...
PassRegistrationListener::PassRegistrationListener() {
+ sys::SmartScopedLock<true> Lock(&ListenersLock);
if (!Listeners) Listeners = new std::vector<PassRegistrationListener*>();
Listeners->push_back(this);
}
// dtor - Remove object from list of listeners...
PassRegistrationListener::~PassRegistrationListener() {
+ sys::SmartScopedLock<true> Lock(&ListenersLock);
std::vector<PassRegistrationListener*>::iterator I =
std::find(Listeners->begin(), Listeners->end(), this);
assert(Listeners && I != Listeners->end() &&
More information about the llvm-commits
mailing list