[llvm-commits] [llvm] r73725 - /llvm/trunk/lib/VMCore/LeakDetector.cpp
Owen Anderson
resistor at mac.com
Thu Jun 18 14:35:56 PDT 2009
Author: resistor
Date: Thu Jun 18 16:35:56 2009
New Revision: 73725
URL: http://llvm.org/viewvc/llvm-project?rev=73725&view=rev
Log:
Simplify.
Modified:
llvm/trunk/lib/VMCore/LeakDetector.cpp
Modified: llvm/trunk/lib/VMCore/LeakDetector.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LeakDetector.cpp?rev=73725&r1=73724&r2=73725&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LeakDetector.cpp (original)
+++ llvm/trunk/lib/VMCore/LeakDetector.cpp Thu Jun 18 16:35:56 2009
@@ -32,7 +32,7 @@
static void print(const Value* P) { cerr << *P; }
};
- ManagedStatic<sys::RWMutex> LeakDetectorLock;
+ ManagedStatic<sys::SmartRWMutex<true> > LeakDetectorLock;
template <typename T>
struct VISIBILITY_HIDDEN LeakDetectorImpl {
@@ -54,41 +54,26 @@
// immediately, it is added to the CachedValue Value. If it is
// immediately removed, no set search need be performed.
void addGarbage(const T* o) {
- if (llvm_is_multithreaded()) {
- sys::ScopedWriter Writer(&*LeakDetectorLock);
- if (Cache) {
- assert(Ts.count(Cache) == 0 && "Object already in set!");
- Ts.insert(Cache);
- }
- Cache = o;
- } else {
- if (Cache) {
- assert(Ts.count(Cache) == 0 && "Object already in set!");
- Ts.insert(Cache);
- }
- Cache = o;
+ sys::SmartScopedWriter<true> Writer(&*LeakDetectorLock);
+ if (Cache) {
+ assert(Ts.count(Cache) == 0 && "Object already in set!");
+ Ts.insert(Cache);
}
+ Cache = o;
}
void removeGarbage(const T* o) {
- if (llvm_is_multithreaded()) {
- sys::ScopedWriter Writer(&*LeakDetectorLock);
- if (o == Cache)
- Cache = 0; // Cache hit
- else
- Ts.erase(o);
- } else {
- if (o == Cache)
- Cache = 0; // Cache hit
- else
- Ts.erase(o);
- }
+ sys::SmartScopedWriter<true> Writer(&*LeakDetectorLock);
+ if (o == Cache)
+ Cache = 0; // Cache hit
+ else
+ Ts.erase(o);
}
bool hasGarbage(const std::string& Message) {
addGarbage(0); // Flush the Cache
- if (llvm_is_multithreaded()) LeakDetectorLock->reader_acquire();
+ sys::SmartScopedReader<true> Reader(&*LeakDetectorLock);
assert(Cache == 0 && "No value should be cached anymore!");
if (!Ts.empty()) {
@@ -101,11 +86,9 @@
}
cerr << '\n';
- if (llvm_is_multithreaded()) LeakDetectorLock->reader_release();
return true;
}
- if (llvm_is_multithreaded()) LeakDetectorLock->reader_release();
return false;
}
More information about the llvm-commits
mailing list