Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 13 matching lines...) Expand all Loading... | |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 #include "platform/ThreadTimers.h" | 28 #include "platform/ThreadTimers.h" |
| 29 | 29 |
| 30 #include "platform/PlatformThreadData.h" | 30 #include "platform/PlatformThreadData.h" |
| 31 #include "platform/SharedTimer.h" | 31 #include "platform/SharedTimer.h" |
| 32 #include "platform/Timer.h" | 32 #include "platform/Timer.h" |
| 33 #include "platform/TraceEvent.h" | 33 #include "platform/TraceEvent.h" |
| 34 #include "platform/scheduler/Scheduler.h" | 34 #include "public/platform/Platform.h" |
| 35 #include "public/platform/WebScheduler.h" | |
| 35 #include "wtf/CurrentTime.h" | 36 #include "wtf/CurrentTime.h" |
| 36 #include "wtf/MainThread.h" | 37 #include "wtf/MainThread.h" |
| 37 | 38 |
| 38 namespace blink { | 39 namespace blink { |
| 39 | 40 |
| 40 // Fire timers for this length of time, and then quit to let the run loop proces s user input events. | 41 // Fire timers for this length of time, and then quit to let the run loop proces s user input events. |
| 41 // 100ms is about a perceptable delay in UI, so use a half of that as a threshol d. | 42 // 100ms is about a perceptable delay in UI, so use a half of that as a threshol d. |
| 42 // This is to prevent UI freeze when there are too many timers or machine perfor mance is low. | 43 // This is to prevent UI freeze when there are too many timers or machine perfor mance is low. |
| 43 static const double maxDurationOfFiringTimers = 0.050; | 44 static const double maxDurationOfFiringTimers = 0.050; |
| 44 | 45 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 timer.setNextFireTime(interval ? fireTime + interval : 0); | 131 timer.setNextFireTime(interval ? fireTime + interval : 0); |
| 131 | 132 |
| 132 TRACE_EVENT2("blink", "ThreadTimers::sharedTimerFiredInternal", | 133 TRACE_EVENT2("blink", "ThreadTimers::sharedTimerFiredInternal", |
| 133 "src_file", timer.location().fileName(), | 134 "src_file", timer.location().fileName(), |
| 134 "src_func", timer.location().functionName()); | 135 "src_func", timer.location().functionName()); |
| 135 | 136 |
| 136 // Once the timer has been fired, it may be deleted, so do nothing else with it after this point. | 137 // Once the timer has been fired, it may be deleted, so do nothing else with it after this point. |
| 137 timer.fired(); | 138 timer.fired(); |
| 138 | 139 |
| 139 // Catch the case where the timer asked timers to fire in a nested event loop, or we are over time limit. | 140 // Catch the case where the timer asked timers to fire in a nested event loop, or we are over time limit. |
| 140 if (!m_firingTimers || timeToQuit < monotonicallyIncreasingTime() || (is MainThread() && Scheduler::shared()->shouldYieldForHighPriorityWork())) | 141 if (!m_firingTimers || timeToQuit < monotonicallyIncreasingTime()) |
| 142 break; | |
| 143 | |
| 144 // Yield if there is more critical work pending on the main thread. | |
| 145 if (isMainThread() && Platform::current()->scheduler() && Platform::curr ent()->scheduler()->shouldYieldForHighPriorityWork()) | |
|
eseidel
2014/10/21 16:11:02
When does this ever fire not on the main thread?
Sami
2014/10/21 18:49:34
Web workers can have timers too.
| |
| 141 break; | 146 break; |
| 142 } | 147 } |
| 143 | 148 |
| 144 m_firingTimers = false; | 149 m_firingTimers = false; |
| 145 | 150 |
| 146 updateSharedTimer(); | 151 updateSharedTimer(); |
| 147 } | 152 } |
| 148 | 153 |
| 149 void ThreadTimers::fireTimersInNestedEventLoop() | 154 void ThreadTimers::fireTimersInNestedEventLoop() |
| 150 { | 155 { |
| 151 // Reset the reentrancy guard so the timers can fire again. | 156 // Reset the reentrancy guard so the timers can fire again. |
| 152 m_firingTimers = false; | 157 m_firingTimers = false; |
| 153 updateSharedTimer(); | 158 updateSharedTimer(); |
| 154 } | 159 } |
| 155 | 160 |
| 156 } // namespace blink | 161 } // namespace blink |
| 157 | 162 |
| OLD | NEW |