[llvm] r295370 - Change default TimerGroup singleton to use magic statics
Erich Keane via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 16 12:19:49 PST 2017
Author: erichkeane
Date: Thu Feb 16 14:19:49 2017
New Revision: 295370
URL: http://llvm.org/viewvc/llvm-project?rev=295370&view=rev
Log:
Change default TimerGroup singleton to use magic statics
TimerGroup was showing up on a leak in valigrind, and
used some pretty complex code to implement a singleton.
This patch replaces the implementation with a vastly simpler
one.
Differential Revision: https://reviews.llvm.org/D28367
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=295370&r1=295369&r2=295370&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Timer.cpp (original)
+++ llvm/trunk/lib/Support/Timer.cpp Thu Feb 16 14:19:49 2017
@@ -72,22 +72,9 @@ std::unique_ptr<raw_fd_ostream> llvm::Cr
return llvm::make_unique<raw_fd_ostream>(2, false); // stderr.
}
-
-static TimerGroup *DefaultTimerGroup = nullptr;
static TimerGroup *getDefaultTimerGroup() {
- TimerGroup *tmp = DefaultTimerGroup;
- sys::MemoryFence();
- if (tmp) return tmp;
-
- sys::SmartScopedLock<true> Lock(*TimerLock);
- tmp = DefaultTimerGroup;
- if (!tmp) {
- tmp = new TimerGroup("misc", "Miscellaneous Ungrouped Timers");
- sys::MemoryFence();
- DefaultTimerGroup = tmp;
- }
-
- return tmp;
+ static TimerGroup DefaultTimerGroup("misc", "Miscellaneous Ungrouped Timers");
+ return &DefaultTimerGroup;
}
//===----------------------------------------------------------------------===//
@@ -309,7 +296,7 @@ void TimerGroup::PrintQueuedTimers(raw_o
// If this is not an collection of ungrouped times, print the total time.
// Ungrouped timers don't really make sense to add up. We still print the
// TOTAL line to make the percentages make sense.
- if (this != DefaultTimerGroup)
+ if (this != getDefaultTimerGroup())
OS << format(" Total Execution Time: %5.4f seconds (%5.4f wall clock)\n",
Total.getProcessTime(), Total.getWallTime());
OS << '\n';
More information about the llvm-commits
mailing list