summaryrefslogtreecommitdiff
path: root/lib/VMCore/TypeSymbolTable.cpp
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-06-18 20:44:31 +0000
committerOwen Anderson <resistor@mac.com>2009-06-18 20:44:31 +0000
commitf0f220a07ef093cc9e27dad2738892f6b2335463 (patch)
tree9f43760c857b60ef7dec5beff686dd6403f2f487 /lib/VMCore/TypeSymbolTable.cpp
parentb13bafe5c12dd908b55c559c93adaeb1627ed096 (diff)
downloadllvm-f0f220a07ef093cc9e27dad2738892f6b2335463.tar.gz
llvm-f0f220a07ef093cc9e27dad2738892f6b2335463.tar.bz2
llvm-f0f220a07ef093cc9e27dad2738892f6b2335463.tar.xz
Simplify with SmartRWMutex.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73721 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/TypeSymbolTable.cpp')
-rw-r--r--lib/VMCore/TypeSymbolTable.cpp32
1 files changed, 11 insertions, 21 deletions
diff --git a/lib/VMCore/TypeSymbolTable.cpp b/lib/VMCore/TypeSymbolTable.cpp
index 0ab6c54a4c..5ae60e28d7 100644
--- a/lib/VMCore/TypeSymbolTable.cpp
+++ b/lib/VMCore/TypeSymbolTable.cpp
@@ -24,7 +24,7 @@ using namespace llvm;
#define DEBUG_SYMBOL_TABLE 0
#define DEBUG_ABSTYPE 0
-static ManagedStatic<sys::RWMutex> TypeSymbolTableLock;
+static ManagedStatic<sys::SmartRWMutex<true> > TypeSymbolTableLock;
TypeSymbolTable::~TypeSymbolTable() {
// Drop all abstract type references in the type plane...
@@ -37,36 +37,30 @@ TypeSymbolTable::~TypeSymbolTable() {
std::string TypeSymbolTable::getUniqueName(const std::string &BaseName) const {
std::string TryName = BaseName;
- if (llvm_is_multithreaded()) TypeSymbolTableLock->reader_acquire();
+ sys::SmartScopedReader<true> Reader(&*TypeSymbolTableLock);
const_iterator End = tmap.end();
// See if the name exists
while (tmap.find(TryName) != End) // Loop until we find a free
TryName = BaseName + utostr(++LastUnique); // name in the symbol table
-
- if (llvm_is_multithreaded()) TypeSymbolTableLock->reader_release();
-
return TryName;
}
// lookup a type by name - returns null on failure
Type* TypeSymbolTable::lookup(const std::string& Name) const {
- if (llvm_is_multithreaded()) TypeSymbolTableLock->reader_acquire();
+ sys::SmartScopedReader<true> Reader(&*TypeSymbolTableLock);
const_iterator TI = tmap.find(Name);
Type* result = 0;
if (TI != tmap.end())
result = const_cast<Type*>(TI->second);
-
- if (llvm_is_multithreaded()) TypeSymbolTableLock->reader_release();
-
return result;
}
// remove - Remove a type from the symbol table...
Type* TypeSymbolTable::remove(iterator Entry) {
- if (llvm_is_multithreaded()) TypeSymbolTableLock->writer_acquire();
+ TypeSymbolTableLock->writer_acquire();
assert(Entry != tmap.end() && "Invalid entry to remove!");
const Type* Result = Entry->second;
@@ -78,7 +72,7 @@ Type* TypeSymbolTable::remove(iterator Entry) {
tmap.erase(Entry);
- if (llvm_is_multithreaded()) TypeSymbolTableLock->writer_release();
+ TypeSymbolTableLock->writer_release();
// If we are removing an abstract type, remove the symbol table from it's use
// list...
@@ -99,7 +93,7 @@ Type* TypeSymbolTable::remove(iterator Entry) {
void TypeSymbolTable::insert(const std::string& Name, const Type* T) {
assert(T && "Can't insert null type into symbol table!");
- if (llvm_is_multithreaded()) TypeSymbolTableLock->writer_acquire();
+ TypeSymbolTableLock->writer_acquire();
if (tmap.insert(make_pair(Name, T)).second) {
// Type inserted fine with no conflict.
@@ -126,7 +120,7 @@ void TypeSymbolTable::insert(const std::string& Name, const Type* T) {
tmap.insert(make_pair(UniqueName, T));
}
- if (llvm_is_multithreaded()) TypeSymbolTableLock->writer_release();
+ TypeSymbolTableLock->writer_release();
// If we are adding an abstract type, add the symbol table to it's use list.
if (T->isAbstract()) {
@@ -140,8 +134,8 @@ void TypeSymbolTable::insert(const std::string& Name, const Type* T) {
// This function is called when one of the types in the type plane are refined
void TypeSymbolTable::refineAbstractType(const DerivedType *OldType,
const Type *NewType) {
- if (llvm_is_multithreaded()) TypeSymbolTableLock->reader_acquire();
-
+ sys::SmartScopedReader<true> Reader(&*TypeSymbolTableLock);
+
// Loop over all of the types in the symbol table, replacing any references
// to OldType with references to NewType. Note that there may be multiple
// occurrences, and although we only need to remove one at a time, it's
@@ -163,8 +157,6 @@ void TypeSymbolTable::refineAbstractType(const DerivedType *OldType,
}
}
}
-
- if (llvm_is_multithreaded()) TypeSymbolTableLock->reader_release();
}
@@ -173,11 +165,10 @@ void TypeSymbolTable::typeBecameConcrete(const DerivedType *AbsTy) {
// Loop over all of the types in the symbol table, dropping any abstract
// type user entries for AbsTy which occur because there are names for the
// type.
- if (llvm_is_multithreaded()) TypeSymbolTableLock->reader_acquire();
+ sys::SmartScopedReader<true> Reader(&*TypeSymbolTableLock);
for (iterator TI = begin(), TE = end(); TI != TE; ++TI)
if (TI->second == const_cast<Type*>(static_cast<const Type*>(AbsTy)))
AbsTy->removeAbstractTypeUser(this);
- if (llvm_is_multithreaded()) TypeSymbolTableLock->reader_release();
}
static void DumpTypes(const std::pair<const std::string, const Type*>& T ) {
@@ -188,9 +179,8 @@ static void DumpTypes(const std::pair<const std::string, const Type*>& T ) {
void TypeSymbolTable::dump() const {
cerr << "TypeSymbolPlane: ";
- if (llvm_is_multithreaded()) TypeSymbolTableLock->reader_acquire();
+ sys::SmartScopedReader<true> Reader(&*TypeSymbolTableLock);
for_each(tmap.begin(), tmap.end(), DumpTypes);
- if (llvm_is_multithreaded()) TypeSymbolTableLock->reader_release();
}
// vim: sw=2 ai