summaryrefslogtreecommitdiff
path: root/lib/Support/Timer.cpp
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-06-23 17:33:37 +0000
committerOwen Anderson <resistor@mac.com>2009-06-23 17:33:37 +0000
commit3b8d135879bd045d63174064c6879eaa6581ec00 (patch)
tree7924daa3a2dc8968b3b89949067faa0cdd934c05 /lib/Support/Timer.cpp
parenta0162ff2b94b0634fcbe51e20b35238618831981 (diff)
downloadllvm-3b8d135879bd045d63174064c6879eaa6581ec00.tar.gz
llvm-3b8d135879bd045d63174064c6879eaa6581ec00.tar.bz2
llvm-3b8d135879bd045d63174064c6879eaa6581ec00.tar.xz
Make the lazy initialization of DefaultTimerGroup threadsafe.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73963 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/Timer.cpp')
-rw-r--r--lib/Support/Timer.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/Support/Timer.cpp b/lib/Support/Timer.cpp
index 3c8879bd06..bcb27a4ab4 100644
--- a/lib/Support/Timer.cpp
+++ b/lib/Support/Timer.cpp
@@ -52,8 +52,20 @@ namespace {
static TimerGroup *DefaultTimerGroup = 0;
static TimerGroup *getDefaultTimerGroup() {
- if (DefaultTimerGroup) return DefaultTimerGroup;
- return DefaultTimerGroup = new TimerGroup("Miscellaneous Ungrouped Timers");
+ TimerGroup* tmp = DefaultTimerGroup;
+ sys::MemoryFence();
+ if (!tmp) {
+ llvm_acquire_global_lock();
+ tmp = DefaultTimerGroup;
+ if (!tmp) {
+ tmp = new TimerGroup("Miscellaneous Ungrouped Timers");
+ sys::MemoryFence();
+ DefaultTimerGroup = tmp;
+ }
+ llvm_release_global_lock();
+ }
+
+ return tmp;
}
Timer::Timer(const std::string &N)
@@ -377,11 +389,5 @@ void TimerGroup::removeTimer() {
if (OutStream != cerr.stream() && OutStream != cout.stream())
delete OutStream; // Close the file...
}
-
- // Delete default timer group!
- if (NumTimers == 0 && this == DefaultTimerGroup) {
- delete DefaultTimerGroup;
- DefaultTimerGroup = 0;
- }
}