diff options
Diffstat (limited to 'llvm/lib/Support/Timer.cpp')
-rw-r--r-- | llvm/lib/Support/Timer.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/llvm/lib/Support/Timer.cpp b/llvm/lib/Support/Timer.cpp index 75ec299..67483ba 100644 --- a/llvm/lib/Support/Timer.cpp +++ b/llvm/lib/Support/Timer.cpp @@ -57,6 +57,7 @@ static SignpostEmitter &signposts(); static sys::SmartMutex<true> &timerLock(); static TimerGroup &defaultTimerGroup(); static Name2PairMap &namedGroupedTimers(); +static bool isTimerGlobalsConstructed(); //===----------------------------------------------------------------------===// // @@ -305,14 +306,26 @@ TimerGroup::~TimerGroup() { PrintQueuedTimers(*OutStream); } + auto unlink = [&]() { + *Prev = Next; + if (Next) + Next->Prev = Prev; + }; + + // TimerGlobals is always created implicity, through a call to timerLock(), + // when a TimeGroup is created. On CRT shutdown, the TimerGlobals instance + // might have been destroyed already. Avoid re-creating it if calling + // timerLock(). + if (!isTimerGlobalsConstructed()) { + unlink(); + return; + } + // Remove the group from the TimerGroupList. sys::SmartScopedLock<true> L(timerLock()); - *Prev = Next; - if (Next) - Next->Prev = Prev; + unlink(); } - void TimerGroup::removeTimer(Timer &T) { sys::SmartScopedLock<true> L(timerLock()); @@ -557,3 +570,7 @@ void TimerGroup::constructForStatistics() { } void *TimerGroup::acquireTimerGlobals() { return ManagedTimerGlobals.claim(); } + +static bool isTimerGlobalsConstructed() { + return ManagedTimerGlobals.isConstructed(); +} |