From 74d28327be3a4cc1d2109a7ed16f669a79fad1d5 Mon Sep 17 00:00:00 2001 From: Gerald Squelart Date: Thu, 19 May 2022 20:31:25 +0000 Subject: [PATCH] Bug 1767396 - Don't wake up the timer thread when removing timers - r=florian,smaug Differential Revision: https://phabricator.services.mozilla.com/D146031 --- xpcom/threads/TimerThread.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/xpcom/threads/TimerThread.cpp b/xpcom/threads/TimerThread.cpp index acb8aeffde07..ea3daeb83395 100644 --- a/xpcom/threads/TimerThread.cpp +++ b/xpcom/threads/TimerThread.cpp @@ -686,11 +686,14 @@ nsresult TimerThread::RemoveTimer(nsTimerImpl* aTimer, return NS_ERROR_NOT_AVAILABLE; } - // Awaken the timer thread. - if (mWaiting) { - mNotified = true; - mMonitor.Notify(); - } + // Note: The timer thread is *not* awoken. + // The removed-timer entry is just left null, and will be reused (by a new or + // re-set timer) or discarded (when the timer thread logic handles non-null + // timers around it). + // If this was the front timer, and in the unlikely case that its entry is not + // soon reused by a re-set timer, the timer thread will wake up at the + // previously-scheduled time, but will quickly notice that there is no actual + // pending timer, and will restart its wait until the following real timeout. if (profiler_thread_is_being_profiled_for_markers(mProfilerThreadId)) { nsAutoCString name;