From 1dd37ea37debc148020e505b9add3dd5e4b47b89 Mon Sep 17 00:00:00 2001 From: Randell Jesup Date: Tue, 8 Sep 2015 11:34:09 -0400 Subject: [PATCH] Bug 1197152: Alternative to remove all sleep/wake functionality from Timers r=froydnj CLOSED TREE --- xpcom/threads/TimerThread.cpp | 25 +++---------------------- xpcom/threads/TimerThread.h | 1 - 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/xpcom/threads/TimerThread.cpp b/xpcom/threads/TimerThread.cpp index 65135a5929a..3225384c280 100644 --- a/xpcom/threads/TimerThread.cpp +++ b/xpcom/threads/TimerThread.cpp @@ -31,8 +31,7 @@ TimerThread::TimerThread() : mShutdown(false), mWaiting(false), mNotified(false), - mSleeping(false), - mLastTimerEventLoopRun(TimeStamp::Now()) + mSleeping(false) { } @@ -441,7 +440,6 @@ TimerThread::Run() } else { waitFor = PR_INTERVAL_NO_TIMEOUT; TimeStamp now = TimeStamp::Now(); - mLastTimerEventLoopRun = now; nsTimerImpl* timer = nullptr; if (!mTimers.IsEmpty()) { @@ -747,7 +745,6 @@ TimerThread::DoBeforeSleep() { // Mainthread MonitorAutoLock lock(mMonitor); - mLastTimerEventLoopRun = TimeStamp::Now(); mSleeping = true; } @@ -756,27 +753,11 @@ void TimerThread::DoAfterSleep() { // Mainthread - TimeStamp now = TimeStamp::Now(); - MonitorAutoLock lock(mMonitor); - - // an over-estimate of time slept, usually small - TimeDuration slept = now - mLastTimerEventLoopRun; - - // Adjust all old timers to expire roughly similar times in the future - // compared to when we went to sleep, by adding the time we slept to the - // target time. It's slightly possible a few will end up slightly in the - // past and fire immediately, but ordering should be preserved. All - // timers retain the exact same order (and relative times) as before - // going to sleep. - for (uint32_t i = 0; i < mTimers.Length(); i ++) { - nsTimerImpl* timer = mTimers[i]; - timer->mTimeout += slept; - } mSleeping = false; - mLastTimerEventLoopRun = now; - // Wake up the timer thread to process the updated array + // Wake up the timer thread to re-process the array to ensure the sleep delay is correct, + // and fire any expired timers (perhaps quite a few) mNotified = true; mMonitor.Notify(); } diff --git a/xpcom/threads/TimerThread.h b/xpcom/threads/TimerThread.h index 63caeaca2d9..7d18a4c6ee1 100644 --- a/xpcom/threads/TimerThread.h +++ b/xpcom/threads/TimerThread.h @@ -77,7 +77,6 @@ private: bool mWaiting; bool mNotified; bool mSleeping; - TimeStamp mLastTimerEventLoopRun; nsTArray mTimers; };