forked from OSchip/llvm-project
Use an RWMutex instead of a Mutex in PassRegistry.
Patch by Alex Crichton <alex@crichton.co>. Approved by Chris Lattner. llvm-svn: 185566
This commit is contained in:
parent
a9d6a0e1f8
commit
673a7db236
|
@ -21,6 +21,7 @@
|
||||||
#include "llvm/Support/Compiler.h"
|
#include "llvm/Support/Compiler.h"
|
||||||
#include "llvm/Support/ManagedStatic.h"
|
#include "llvm/Support/ManagedStatic.h"
|
||||||
#include "llvm/Support/Mutex.h"
|
#include "llvm/Support/Mutex.h"
|
||||||
|
#include "llvm/Support/RWMutex.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
@ -35,7 +36,7 @@ PassRegistry *PassRegistry::getPassRegistry() {
|
||||||
return &*PassRegistryObj;
|
return &*PassRegistryObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ManagedStatic<sys::SmartMutex<true> > Lock;
|
static ManagedStatic<sys::SmartRWMutex<true> > Lock;
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// PassRegistryImpl
|
// PassRegistryImpl
|
||||||
|
@ -72,7 +73,7 @@ void *PassRegistry::getImpl() const {
|
||||||
//
|
//
|
||||||
|
|
||||||
PassRegistry::~PassRegistry() {
|
PassRegistry::~PassRegistry() {
|
||||||
sys::SmartScopedLock<true> Guard(*Lock);
|
sys::SmartScopedWriter<true> Guard(*Lock);
|
||||||
PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(pImpl);
|
PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(pImpl);
|
||||||
|
|
||||||
for (std::vector<const PassInfo*>::iterator I = Impl->ToFree.begin(),
|
for (std::vector<const PassInfo*>::iterator I = Impl->ToFree.begin(),
|
||||||
|
@ -84,14 +85,14 @@ PassRegistry::~PassRegistry() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const PassInfo *PassRegistry::getPassInfo(const void *TI) const {
|
const PassInfo *PassRegistry::getPassInfo(const void *TI) const {
|
||||||
sys::SmartScopedLock<true> Guard(*Lock);
|
sys::SmartScopedReader<true> Guard(*Lock);
|
||||||
PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(getImpl());
|
PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(getImpl());
|
||||||
PassRegistryImpl::MapType::const_iterator I = Impl->PassInfoMap.find(TI);
|
PassRegistryImpl::MapType::const_iterator I = Impl->PassInfoMap.find(TI);
|
||||||
return I != Impl->PassInfoMap.end() ? I->second : 0;
|
return I != Impl->PassInfoMap.end() ? I->second : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PassInfo *PassRegistry::getPassInfo(StringRef Arg) const {
|
const PassInfo *PassRegistry::getPassInfo(StringRef Arg) const {
|
||||||
sys::SmartScopedLock<true> Guard(*Lock);
|
sys::SmartScopedReader<true> Guard(*Lock);
|
||||||
PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(getImpl());
|
PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(getImpl());
|
||||||
PassRegistryImpl::StringMapType::const_iterator
|
PassRegistryImpl::StringMapType::const_iterator
|
||||||
I = Impl->PassInfoStringMap.find(Arg);
|
I = Impl->PassInfoStringMap.find(Arg);
|
||||||
|
@ -103,7 +104,7 @@ const PassInfo *PassRegistry::getPassInfo(StringRef Arg) const {
|
||||||
//
|
//
|
||||||
|
|
||||||
void PassRegistry::registerPass(const PassInfo &PI, bool ShouldFree) {
|
void PassRegistry::registerPass(const PassInfo &PI, bool ShouldFree) {
|
||||||
sys::SmartScopedLock<true> Guard(*Lock);
|
sys::SmartScopedWriter<true> Guard(*Lock);
|
||||||
PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(getImpl());
|
PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(getImpl());
|
||||||
bool Inserted =
|
bool Inserted =
|
||||||
Impl->PassInfoMap.insert(std::make_pair(PI.getTypeInfo(),&PI)).second;
|
Impl->PassInfoMap.insert(std::make_pair(PI.getTypeInfo(),&PI)).second;
|
||||||
|
@ -120,7 +121,7 @@ void PassRegistry::registerPass(const PassInfo &PI, bool ShouldFree) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PassRegistry::unregisterPass(const PassInfo &PI) {
|
void PassRegistry::unregisterPass(const PassInfo &PI) {
|
||||||
sys::SmartScopedLock<true> Guard(*Lock);
|
sys::SmartScopedWriter<true> Guard(*Lock);
|
||||||
PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(getImpl());
|
PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(getImpl());
|
||||||
PassRegistryImpl::MapType::iterator I =
|
PassRegistryImpl::MapType::iterator I =
|
||||||
Impl->PassInfoMap.find(PI.getTypeInfo());
|
Impl->PassInfoMap.find(PI.getTypeInfo());
|
||||||
|
@ -132,7 +133,7 @@ void PassRegistry::unregisterPass(const PassInfo &PI) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PassRegistry::enumerateWith(PassRegistrationListener *L) {
|
void PassRegistry::enumerateWith(PassRegistrationListener *L) {
|
||||||
sys::SmartScopedLock<true> Guard(*Lock);
|
sys::SmartScopedReader<true> Guard(*Lock);
|
||||||
PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(getImpl());
|
PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(getImpl());
|
||||||
for (PassRegistryImpl::MapType::const_iterator I = Impl->PassInfoMap.begin(),
|
for (PassRegistryImpl::MapType::const_iterator I = Impl->PassInfoMap.begin(),
|
||||||
E = Impl->PassInfoMap.end(); I != E; ++I)
|
E = Impl->PassInfoMap.end(); I != E; ++I)
|
||||||
|
@ -160,7 +161,7 @@ void PassRegistry::registerAnalysisGroup(const void *InterfaceID,
|
||||||
assert(ImplementationInfo &&
|
assert(ImplementationInfo &&
|
||||||
"Must register pass before adding to AnalysisGroup!");
|
"Must register pass before adding to AnalysisGroup!");
|
||||||
|
|
||||||
sys::SmartScopedLock<true> Guard(*Lock);
|
sys::SmartScopedWriter<true> Guard(*Lock);
|
||||||
|
|
||||||
// Make sure we keep track of the fact that the implementation implements
|
// Make sure we keep track of the fact that the implementation implements
|
||||||
// the interface.
|
// the interface.
|
||||||
|
@ -186,13 +187,13 @@ void PassRegistry::registerAnalysisGroup(const void *InterfaceID,
|
||||||
}
|
}
|
||||||
|
|
||||||
void PassRegistry::addRegistrationListener(PassRegistrationListener *L) {
|
void PassRegistry::addRegistrationListener(PassRegistrationListener *L) {
|
||||||
sys::SmartScopedLock<true> Guard(*Lock);
|
sys::SmartScopedWriter<true> Guard(*Lock);
|
||||||
PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(getImpl());
|
PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(getImpl());
|
||||||
Impl->Listeners.push_back(L);
|
Impl->Listeners.push_back(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PassRegistry::removeRegistrationListener(PassRegistrationListener *L) {
|
void PassRegistry::removeRegistrationListener(PassRegistrationListener *L) {
|
||||||
sys::SmartScopedLock<true> Guard(*Lock);
|
sys::SmartScopedWriter<true> Guard(*Lock);
|
||||||
|
|
||||||
// NOTE: This is necessary, because removeRegistrationListener() can be called
|
// NOTE: This is necessary, because removeRegistrationListener() can be called
|
||||||
// as part of the llvm_shutdown sequence. Since we have no control over the
|
// as part of the llvm_shutdown sequence. Since we have no control over the
|
||||||
|
|
Loading…
Reference in New Issue