Do not expose the locking for the PassRegistry in the header. Be careful to

synchronize any method that might lazily initialize the pImpl.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114130 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson 2010-09-16 23:32:35 +00:00
parent fc24c1a7ba
commit 1e3e6362c8
2 changed files with 8 additions and 3 deletions

View File

@ -18,7 +18,6 @@
#define LLVM_PASSREGISTRY_H #define LLVM_PASSREGISTRY_H
#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringRef.h"
#include "llvm/System/Mutex.h"
namespace llvm { namespace llvm {
@ -33,7 +32,6 @@ struct PassRegistrationListener;
/// each thread. /// each thread.
class PassRegistry { class PassRegistry {
mutable void *pImpl; mutable void *pImpl;
mutable sys::SmartMutex<true> Lock;
void *getImpl() const; void *getImpl() const;
public: public:

View File

@ -16,6 +16,7 @@
#include "llvm/PassSupport.h" #include "llvm/PassSupport.h"
#include "llvm/Support/Compiler.h" #include "llvm/Support/Compiler.h"
#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/ManagedStatic.h"
#include "llvm/System/Mutex.h"
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringMap.h"
@ -33,6 +34,8 @@ PassRegistry *PassRegistry::getPassRegistry() {
return &*PassRegistryObj; return &*PassRegistryObj;
} }
sys::SmartMutex<true> Lock;
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// PassRegistryImpl // PassRegistryImpl
// //
@ -65,18 +68,21 @@ void *PassRegistry::getImpl() const {
// //
PassRegistry::~PassRegistry() { PassRegistry::~PassRegistry() {
sys::SmartScopedLock<true> Guard(Lock);
PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(pImpl); PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(pImpl);
if (Impl) delete Impl; if (Impl) delete Impl;
pImpl = 0; pImpl = 0;
} }
const PassInfo *PassRegistry::getPassInfo(const void *TI) const { const PassInfo *PassRegistry::getPassInfo(const void *TI) const {
sys::SmartScopedLock<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);
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);
@ -127,7 +133,6 @@ void PassRegistry::registerAnalysisGroup(const void *InterfaceID,
const void *PassID, const void *PassID,
PassInfo& Registeree, PassInfo& Registeree,
bool isDefault) { bool isDefault) {
sys::SmartScopedLock<true> Guard(Lock);
PassInfo *InterfaceInfo = const_cast<PassInfo*>(getPassInfo(InterfaceID)); PassInfo *InterfaceInfo = const_cast<PassInfo*>(getPassInfo(InterfaceID));
if (InterfaceInfo == 0) { if (InterfaceInfo == 0) {
// First reference to Interface, register it now. // First reference to Interface, register it now.
@ -142,6 +147,8 @@ 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);
// 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.
ImplementationInfo->addInterfaceImplemented(InterfaceInfo); ImplementationInfo->addInterfaceImplemented(InterfaceInfo);