Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions llvm/lib/Support/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static SignpostEmitter &signposts();
static sys::SmartMutex<true> &timerLock();
static TimerGroup &defaultTimerGroup();
static Name2PairMap &namedGroupedTimers();
static bool isTimerGlobalsConstructed();

//===----------------------------------------------------------------------===//
//
Expand Down Expand Up @@ -305,14 +306,24 @@ TimerGroup::~TimerGroup() {
PrintQueuedTimers(*OutStream);
}

auto unlink = [&]() {
*Prev = Next;
if (Next)
Next->Prev = Prev;
};

// If the managed instance is already dead, it means we're in the CRT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused by this comment.

llvm::TimerGroup::acquireTimerGlobals() frees ManagedStatic. Is the leak due to timerLock() re-constructing the ManagedStatic?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will clarify the comment.

// destruction, so no need to lock.
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());

Expand Down Expand Up @@ -557,3 +568,7 @@ void TimerGroup::constructForStatistics() {
}

void *TimerGroup::acquireTimerGlobals() { return ManagedTimerGlobals.claim(); }

static bool isTimerGlobalsConstructed() {
return ManagedTimerGlobals.isConstructed();
}
Loading