[llvm-commits] [llvm] r73719 - /llvm/trunk/lib/VMCore/Value.cpp
Owen Anderson
resistor at mac.com
Thu Jun 18 13:36:23 PDT 2009
Author: resistor
Date: Thu Jun 18 15:36:21 2009
New Revision: 73719
URL: http://llvm.org/viewvc/llvm-project?rev=73719&view=rev
Log:
Simplify by using no-op-when-not-multithreaded locks.
Modified:
llvm/trunk/lib/VMCore/Value.cpp
Modified: llvm/trunk/lib/VMCore/Value.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Value.cpp?rev=73719&r1=73718&r2=73719&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Value.cpp (original)
+++ llvm/trunk/lib/VMCore/Value.cpp Thu Jun 18 15:36:21 2009
@@ -407,7 +407,7 @@
/// not a value has an entry in this map.
typedef DenseMap<Value*, ValueHandleBase*> ValueHandlesTy;
static ManagedStatic<ValueHandlesTy> ValueHandles;
-static ManagedStatic<sys::RWMutex> ValueHandlesLock;
+static ManagedStatic<sys::SmartRWMutex<true> > ValueHandlesLock;
/// AddToExistingUseList - Add this ValueHandle to the use list for VP, where
/// List is known to point into the existing use list.
@@ -430,11 +430,10 @@
if (VP->HasValueHandle) {
// If this value already has a ValueHandle, then it must be in the
// ValueHandles map already.
- if (llvm_is_multithreaded()) ValueHandlesLock->reader_acquire();
+ sys::SmartScopedReader<true> Reader(&*ValueHandlesLock);
ValueHandleBase *&Entry = (*ValueHandles)[VP];
assert(Entry != 0 && "Value doesn't have any handles?");
AddToExistingUseList(&Entry);
- if (llvm_is_multithreaded()) ValueHandlesLock->reader_release();
return;
}
@@ -443,7 +442,7 @@
// reallocate itself, which would invalidate all of the PrevP pointers that
// point into the old table. Handle this by checking for reallocation and
// updating the stale pointers only if needed.
- if (llvm_is_multithreaded()) ValueHandlesLock->writer_acquire();
+ sys::SmartScopedWriter<true> Writer(&*ValueHandlesLock);
ValueHandlesTy &Handles = *ValueHandles;
const void *OldBucketPtr = Handles.getPointerIntoBucketsArray();
@@ -456,7 +455,6 @@
// walk the table.
if (Handles.isPointerIntoBucketsArray(OldBucketPtr) ||
Handles.size() == 1) {
- if (llvm_is_multithreaded()) ValueHandlesLock->writer_release();
return;
}
@@ -466,8 +464,6 @@
assert(I->second && I->first == I->second->VP && "List invariant broken!");
I->second->setPrevPtr(&I->second);
}
-
- if (llvm_is_multithreaded()) ValueHandlesLock->writer_release();
}
/// RemoveFromUseList - Remove this ValueHandle from its current use list.
@@ -488,13 +484,12 @@
// If the Next pointer was null, then it is possible that this was the last
// ValueHandle watching VP. If so, delete its entry from the ValueHandles
// map.
- if (llvm_is_multithreaded()) ValueHandlesLock->writer_acquire();
+ sys::SmartScopedWriter<true> Writer(&*ValueHandlesLock);
ValueHandlesTy &Handles = *ValueHandles;
if (Handles.isPointerIntoBucketsArray(PrevPtr)) {
Handles.erase(VP);
VP->HasValueHandle = false;
}
- if (llvm_is_multithreaded()) ValueHandlesLock->writer_release();
}
@@ -503,9 +498,9 @@
// Get the linked list base, which is guaranteed to exist since the
// HasValueHandle flag is set.
- if (llvm_is_multithreaded()) ValueHandlesLock->reader_acquire();
+ ValueHandlesLock->reader_acquire();
ValueHandleBase *Entry = (*ValueHandles)[V];
- if (llvm_is_multithreaded()) ValueHandlesLock->reader_release();
+ ValueHandlesLock->reader_release();
assert(Entry && "Value bit set but no entries exist");
while (Entry) {
@@ -543,9 +538,9 @@
// Get the linked list base, which is guaranteed to exist since the
// HasValueHandle flag is set.
- if (llvm_is_multithreaded()) ValueHandlesLock->reader_acquire();
+ ValueHandlesLock->reader_acquire();
ValueHandleBase *Entry = (*ValueHandles)[Old];
- if (llvm_is_multithreaded()) ValueHandlesLock->reader_release();
+ ValueHandlesLock->reader_release();
assert(Entry && "Value bit set but no entries exist");
while (Entry) {
More information about the llvm-commits
mailing list