Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1115)

Unified Diff: third_party/WebKit/Source/platform/Timer.cpp

Issue 1373503002: Fix the drift in repeating timers (try #2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename some variables and add a todo Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/Timer.cpp
diff --git a/third_party/WebKit/Source/platform/Timer.cpp b/third_party/WebKit/Source/platform/Timer.cpp
index c2913c3bc49da7494f2b06eb9bd0bc97af2f066c..ad619a3cf12d69041cb403d9afafdd874e4e1037 100644
--- a/third_party/WebKit/Source/platform/Timer.cpp
+++ b/third_party/WebKit/Source/platform/Timer.cpp
@@ -110,12 +110,8 @@ void TimerBase::setNextFireTime(double now, double delay)
// TODO(skyostil): Move timer alignment into the scheduler.
m_webScheduler->postTimerTaskAt(m_location, m_cancellableTimerTask, m_nextFireTime);
} else {
- // Round the delay up to the nearest millisecond to be consistant with the
- // previous behavior of BlinkPlatformImpl::setSharedTimerFireInterval.
- long long delayMs = static_cast<long long>(ceil((newTime - now) * 1000.0));
- if (delayMs < 0)
- delayMs = 0;
- timerTaskRunner()->postDelayedTask(m_location, m_cancellableTimerTask, delayMs);
+ double delayMs = 1000.0 * (newTime - now);
+ m_webScheduler->timerTaskRunner()->postDelayedTask(m_location, m_cancellableTimerTask, delayMs);
}
}
}
@@ -131,10 +127,15 @@ void TimerBase::runInternal()
TRACE_EVENT_SET_SAMPLING_STATE("blink", "BlinkInternal");
m_nextFireTime = 0;
- // Note: repeating timers drift, but this is preserving the functionality of the old timer heap.
- // See crbug.com/328700.
- if (m_repeatInterval)
- setNextFireTime(monotonicallyIncreasingTime(), m_repeatInterval);
+ if (m_repeatInterval) {
+ double now = monotonicallyIncreasingTime();
+ // This computation should be drift free, and it will cope if we miss a beat,
+ // which can easily happen if the thread is busy. It will also cope if we get
+ // called slightly before m_unalignedNextFireTime, which can happen due to lack
+ // of timer precision.
+ double intervalToNextFireTime = m_repeatInterval - fmod(now - m_unalignedNextFireTime, m_repeatInterval);
+ setNextFireTime(monotonicallyIncreasingTime(), intervalToNextFireTime);
+ }
fired();
TRACE_EVENT_SET_SAMPLING_STATE("blink", "Sleeping");
}
« no previous file with comments | « third_party/WebKit/Source/core/dom/ScriptRunnerTest.cpp ('k') | third_party/WebKit/Source/platform/TimerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698