From 325021f37a8cfd8135e1ca485ea401569f041c74 Mon Sep 17 00:00:00 2001 From: Iulian Moraru Date: Sat, 25 Feb 2023 14:30:52 +0200 Subject: [PATCH] Backed out changeset 9f0d0ce9c0df (bug 1770658) for causing dt failures on browser_aboutdebugging_devtoolstoolbox_reload.js. CLOSED TREE --- xpcom/threads/TimerThread.cpp | 49 ++++++++++++++++------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/xpcom/threads/TimerThread.cpp b/xpcom/threads/TimerThread.cpp index 3306a0a3bcca..b7dcba65bd75 100644 --- a/xpcom/threads/TimerThread.cpp +++ b/xpcom/threads/TimerThread.cpp @@ -800,34 +800,31 @@ nsresult TimerThread::AddTimer(nsTimerImpl* aTimer, return rv; } - // Fire this timer immediately (and skip adding it to our timer list) if the - // delay is 0, which are meant to be run as soon as possible. This has less - // overhead than waking up the timer thread and handling it there while still - // maintaining timer ordering and response time. - const bool fireImmediately = aTimer->mDelay.IsZero(); - if (fireImmediately) { - RefPtr timerRef(aTimer); - LogTimerEvent::Run run(aTimer); - PostTimerEvent(timerRef.forget()); - } else { - // Awaken the timer thread if this timer wants to fire *before* the Timer - // Thread is scheduled to wake up. We don't track this directly but we know - // that we will have attempted to wake up at the timeout for the first time - // in our list (if it exists), so we can use that. Note: This is true even - // if the timer has since been canceled. - const bool wakeUpTimerThread = - mWaiting && - (mTimers.Length() == 0 || aTimer->mTimeout < mTimers[0].Timeout()); + // Awaken the timer thread if: + // - This timer wants to fire *before* the Timer Thread is scheduled to wake + // up. We don't track this directly but we know that we will have attempted + // to wake up at the timeout for the first time in our list (if it exists), + // so we can use that. Note: This is true even if the timer has since been + // canceled. + // AND/OR + // - The delay is 0, which is usually meant to be run as soon as possible. + // Note: Even if the thread is scheduled to wake up now/soon, on some + // systems there could be a significant delay compared to notifying, which + // is almost immediate; and some users of 0-delay depend on it being this + // fast! + const bool wakeUpTimerThread = + mWaiting && + (mTimers.Length() == 0 || aTimer->mTimeout < mTimers[0].Timeout() || + aTimer->mDelay.IsZero()); - // Add the timer to our list. - if (!AddTimerInternal(aTimer)) { - return NS_ERROR_OUT_OF_MEMORY; - } + // Add the timer to our list. + if (!AddTimerInternal(aTimer)) { + return NS_ERROR_OUT_OF_MEMORY; + } - if (wakeUpTimerThread) { - mNotified = true; - mMonitor.Notify(); - } + if (wakeUpTimerThread) { + mNotified = true; + mMonitor.Notify(); } if (profiler_thread_is_being_profiled_for_markers(mProfilerThreadId)) {