summaryrefslogtreecommitdiff
path: root/include/llvm/Support/Timer.h
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-06-23 20:52:29 +0000
committerOwen Anderson <resistor@mac.com>2009-06-23 20:52:29 +0000
commit46d9a6494496d215e850f337b5a723c484212f80 (patch)
tree0e7bb70cb2e9fac383f1673e8aaf334e215cd59e /include/llvm/Support/Timer.h
parent223e99cd8d9a0a6a57504589b8593d402c67d38b (diff)
downloadllvm-46d9a6494496d215e850f337b5a723c484212f80.tar.gz
llvm-46d9a6494496d215e850f337b5a723c484212f80.tar.bz2
llvm-46d9a6494496d215e850f337b5a723c484212f80.tar.xz
Make timers threadsafe again. This isn't quite as nice as I'd hoped (it uses locking rather than atomic arithmetic),
but should work on all the platforms we care about. I might revisit this if a totally awesome way to do it occurs to me. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74002 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/Timer.h')
-rw-r--r--include/llvm/Support/Timer.h25
1 files changed, 21 insertions, 4 deletions
diff --git a/include/llvm/Support/Timer.h b/include/llvm/Support/Timer.h
index 584199f440..71b7ee58fd 100644
--- a/include/llvm/Support/Timer.h
+++ b/include/llvm/Support/Timer.h
@@ -16,6 +16,7 @@
#define LLVM_SUPPORT_TIMER_H
#include "llvm/Support/DataTypes.h"
+#include "llvm/System/Mutex.h"
#include <string>
#include <vector>
#include <iosfwd>
@@ -43,6 +44,7 @@ class Timer {
std::string Name; // The name of this time variable
bool Started; // Has this time variable ever been started?
TimerGroup *TG; // The TimerGroup this Timer is in.
+ mutable sys::SmartMutex<true> Lock; // Mutex for the contents of this Timer.
public:
explicit Timer(const std::string &N);
Timer(const std::string &N, TimerGroup &tg);
@@ -56,6 +58,14 @@ public:
std::string getName() const { return Name; }
const Timer &operator=(const Timer &T) {
+ if (&T < this) {
+ T.Lock.acquire();
+ Lock.acquire();
+ } else {
+ Lock.acquire();
+ T.Lock.acquire();
+ }
+
Elapsed = T.Elapsed;
UserTime = T.UserTime;
SystemTime = T.SystemTime;
@@ -65,6 +75,15 @@ public:
Name = T.Name;
Started = T.Started;
assert(TG == T.TG && "Can only assign timers in the same TimerGroup!");
+
+ if (&T < this) {
+ T.Lock.release();
+ Lock.release();
+ } else {
+ Lock.release();
+ T.Lock.release();
+ }
+
return *this;
}
@@ -160,11 +179,9 @@ public:
private:
friend class Timer;
- void addTimer() { ++NumTimers; }
+ void addTimer();
void removeTimer();
- void addTimerToPrint(const Timer &T) {
- TimersToPrint.push_back(Timer(true, T));
- }
+ void addTimerToPrint(const Timer &T);
};
} // End llvm namespace