[llvm-commits] [llvm] r73722 - in /llvm/trunk: include/llvm/System/Mutex.h lib/VMCore/PassManager.cpp
Owen Anderson
resistor at mac.com
Thu Jun 18 13:51:01 PDT 2009
Author: resistor
Date: Thu Jun 18 15:51:00 2009
New Revision: 73722
URL: http://llvm.org/viewvc/llvm-project?rev=73722&view=rev
Log:
Add a SmartScopedLock, and use it to simplify code.
Modified:
llvm/trunk/include/llvm/System/Mutex.h
llvm/trunk/lib/VMCore/PassManager.cpp
Modified: llvm/trunk/include/llvm/System/Mutex.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/System/Mutex.h?rev=73722&r1=73721&r2=73722&view=diff
==============================================================================
--- llvm/trunk/include/llvm/System/Mutex.h (original)
+++ llvm/trunk/include/llvm/System/Mutex.h Thu Jun 18 15:51:00 2009
@@ -115,6 +115,22 @@
/// Mutex - A standard, always enforced mutex.
typedef SmartMutex<false> Mutex;
+
+ template<bool mt_only>
+ class SmartScopedLock {
+ SmartMutex<mt_only>* mtx;
+
+ public:
+ SmartScopedLock(SmartMutex<mt_only>* m) : mtx(m) {
+ mtx->acquire();
+ }
+
+ ~SmartScopedLock() {
+ mtx->release();
+ }
+ };
+
+ typedef SmartScopedLock<false> ScopedLock;
}
}
Modified: llvm/trunk/lib/VMCore/PassManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/PassManager.cpp?rev=73722&r1=73721&r2=73722&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/PassManager.cpp (original)
+++ llvm/trunk/lib/VMCore/PassManager.cpp Thu Jun 18 15:51:00 2009
@@ -358,7 +358,7 @@
/// -time-passes is enabled on the command line.
///
-static ManagedStatic<sys::Mutex> TimingInfoMutex;
+static ManagedStatic<sys::SmartMutex<true> > TimingInfoMutex;
class VISIBILITY_HIDDEN TimingInfo {
std::map<Pass*, Timer> TimingData;
@@ -384,22 +384,21 @@
if (dynamic_cast<PMDataManager *>(P))
return;
- if (llvm_is_multithreaded()) TimingInfoMutex->acquire();
+ sys::SmartScopedLock<true> Lock(&*TimingInfoMutex);
std::map<Pass*, Timer>::iterator I = TimingData.find(P);
if (I == TimingData.end())
I=TimingData.insert(std::make_pair(P, Timer(P->getPassName(), TG))).first;
I->second.startTimer();
- if (llvm_is_multithreaded()) TimingInfoMutex->release();
}
+
void passEnded(Pass *P) {
if (dynamic_cast<PMDataManager *>(P))
return;
- if (llvm_is_multithreaded()) TimingInfoMutex->acquire();
+ sys::SmartScopedLock<true> Lock(&*TimingInfoMutex);
std::map<Pass*, Timer>::iterator I = TimingData.find(P);
assert(I != TimingData.end() && "passStarted/passEnded not nested right!");
I->second.stopTimer();
- if (llvm_is_multithreaded()) TimingInfoMutex->release();
}
};
More information about the llvm-commits
mailing list