[llvm-commits] [llvm] r73963 - /llvm/trunk/lib/Support/Timer.cpp
Owen Anderson
resistor at mac.com
Tue Jun 23 10:33:45 PDT 2009
Author: resistor
Date: Tue Jun 23 12:33:37 2009
New Revision: 73963
URL: http://llvm.org/viewvc/llvm-project?rev=73963&view=rev
Log:
Make the lazy initialization of DefaultTimerGroup threadsafe.
Modified:
llvm/trunk/lib/Support/Timer.cpp
Modified: llvm/trunk/lib/Support/Timer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Timer.cpp?rev=73963&r1=73962&r2=73963&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Timer.cpp (original)
+++ llvm/trunk/lib/Support/Timer.cpp Tue Jun 23 12:33:37 2009
@@ -52,8 +52,20 @@
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 @@
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;
- }
}
More information about the llvm-commits
mailing list