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

Side by Side Diff: Source/platform/Timer.cpp

Issue 1290633002: Revert of Fix the drift in repeating timers. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | Source/platform/TimerTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 m_nextFireTime = newTime; 98 m_nextFireTime = newTime;
99 if (m_cancellableTimerTask) 99 if (m_cancellableTimerTask)
100 m_cancellableTimerTask->cancel(); 100 m_cancellableTimerTask->cancel();
101 m_cancellableTimerTask = new CancellableTimerTask(this); 101 m_cancellableTimerTask = new CancellableTimerTask(this);
102 if (newTime != m_unalignedNextFireTime) { 102 if (newTime != m_unalignedNextFireTime) {
103 // If the timer is being aligned, use postTimerTaskAt() to schedule it 103 // If the timer is being aligned, use postTimerTaskAt() to schedule it
104 // so that the relative order of aligned timers is preserved. 104 // so that the relative order of aligned timers is preserved.
105 // TODO(skyostil): Move timer alignment into the scheduler. 105 // TODO(skyostil): Move timer alignment into the scheduler.
106 m_webScheduler->postTimerTaskAt(m_location, m_cancellableTimerTask, m_nextFireTime); 106 m_webScheduler->postTimerTaskAt(m_location, m_cancellableTimerTask, m_nextFireTime);
107 } else { 107 } else {
108 m_webScheduler->postTimerTask(m_location, m_cancellableTimerTask, ne wTime - now); 108 // Round the delay up to the nearest millisecond to be consistant wi th the
109 // previous behavior of BlinkPlatformImpl::setSharedTimerFireInterva l.
110 long long delayMs = static_cast<long long>(ceil((newTime - now) * 10 00.0));
111 if (delayMs < 0)
112 delayMs = 0;
113 m_webScheduler->postTimerTask(m_location, m_cancellableTimerTask, de layMs);
109 } 114 }
110 } 115 }
111 } 116 }
112 117
113 NO_LAZY_SWEEP_SANITIZE_ADDRESS 118 NO_LAZY_SWEEP_SANITIZE_ADDRESS
114 void TimerBase::runInternal() 119 void TimerBase::runInternal()
115 { 120 {
116 if (!canFire()) 121 if (!canFire())
117 return; 122 return;
118 123
119 TRACE_EVENT0("blink", "TimerBase::run"); 124 TRACE_EVENT0("blink", "TimerBase::run");
120 ASSERT_WITH_MESSAGE(m_thread == currentThread(), "Timer posted by %s %s was run on a different thread", m_location.functionName(), m_location.fileName()); 125 ASSERT_WITH_MESSAGE(m_thread == currentThread(), "Timer posted by %s %s was run on a different thread", m_location.functionName(), m_location.fileName());
121 TRACE_EVENT_SET_SAMPLING_STATE("blink", "BlinkInternal"); 126 TRACE_EVENT_SET_SAMPLING_STATE("blink", "BlinkInternal");
122 127
123 m_nextFireTime = 0; 128 m_nextFireTime = 0;
124 if (m_repeatInterval) { 129 // Note: repeating timers drift, but this is preserving the functionality of the old timer heap.
125 double now = monotonicallyIncreasingTime(); 130 // See crbug.com/328700.
126 ASSERT(now >= m_unalignedNextFireTime); 131 if (m_repeatInterval)
127 // This computation should be drift free, and it will cope if we miss a beat, 132 setNextFireTime(monotonicallyIncreasingTime(), m_repeatInterval);
128 // which can easily happen if the thread is busy.
129 double intervalToNextFireTime = m_repeatInterval - fmod(now - m_unaligne dNextFireTime, m_repeatInterval);
130 setNextFireTime(now, intervalToNextFireTime);
131 }
132 fired(); 133 fired();
133 TRACE_EVENT_SET_SAMPLING_STATE("blink", "Sleeping"); 134 TRACE_EVENT_SET_SAMPLING_STATE("blink", "Sleeping");
134 } 135 }
135 136
136 void TimerBase::didChangeAlignmentInterval(double now) 137 void TimerBase::didChangeAlignmentInterval(double now)
137 { 138 {
138 setNextFireTime(now, m_unalignedNextFireTime - now); 139 setNextFireTime(now, m_unalignedNextFireTime - now);
139 } 140 }
140 141
141 double TimerBase::nextUnalignedFireInterval() const 142 double TimerBase::nextUnalignedFireInterval() const
142 { 143 {
143 ASSERT(isActive()); 144 ASSERT(isActive());
144 return std::max(m_unalignedNextFireTime - monotonicallyIncreasingTime(), 0.0 ); 145 return std::max(m_unalignedNextFireTime - monotonicallyIncreasingTime(), 0.0 );
145 } 146 }
146 147
147 bool TimerBase::Comparator::operator()(const TimerBase* a, const TimerBase* b) c onst 148 bool TimerBase::Comparator::operator()(const TimerBase* a, const TimerBase* b) c onst
148 { 149 {
149 return a->m_unalignedNextFireTime < b->m_unalignedNextFireTime; 150 return a->m_unalignedNextFireTime < b->m_unalignedNextFireTime;
150 } 151 }
151 152
152 } // namespace blink 153 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/platform/TimerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698