| 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 17 matching lines...) Expand all Loading... |
| 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 "platform/scheduler/Scheduler.h" |
| 35 #include "wtf/CurrentTime.h" | 35 #include "wtf/CurrentTime.h" |
| 36 #include "wtf/MainThread.h" | 36 #include "wtf/MainThread.h" |
| 37 | 37 |
| 38 using namespace std; | |
| 39 | |
| 40 namespace blink { | 38 namespace blink { |
| 41 | 39 |
| 42 // Fire timers for this length of time, and then quit to let the run loop proces
s user input events. | 40 // Fire timers for this length of time, and then quit to let the run loop proces
s user input events. |
| 43 // 100ms is about a perceptable delay in UI, so use a half of that as a threshol
d. | 41 // 100ms is about a perceptable delay in UI, so use a half of that as a threshol
d. |
| 44 // This is to prevent UI freeze when there are too many timers or machine perfor
mance is low. | 42 // This is to prevent UI freeze when there are too many timers or machine perfor
mance is low. |
| 45 static const double maxDurationOfFiringTimers = 0.050; | 43 static const double maxDurationOfFiringTimers = 0.050; |
| 46 | 44 |
| 47 // Timers are created, started and fired on the same thread, and each thread has
its own ThreadTimers | 45 // Timers are created, started and fired on the same thread, and each thread has
its own ThreadTimers |
| 48 // copy to keep the heap and a set of currently firing timers. | 46 // copy to keep the heap and a set of currently firing timers. |
| 49 | 47 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 m_sharedTimer->stop(); | 88 m_sharedTimer->stop(); |
| 91 } else { | 89 } else { |
| 92 double nextFireTime = m_timerHeap.first()->m_nextFireTime; | 90 double nextFireTime = m_timerHeap.first()->m_nextFireTime; |
| 93 double currentMonotonicTime = monotonicallyIncreasingTime(); | 91 double currentMonotonicTime = monotonicallyIncreasingTime(); |
| 94 if (m_pendingSharedTimerFireTime) { | 92 if (m_pendingSharedTimerFireTime) { |
| 95 // No need to restart the timer if both the pending fire time and th
e new fire time are in the past. | 93 // No need to restart the timer if both the pending fire time and th
e new fire time are in the past. |
| 96 if (m_pendingSharedTimerFireTime <= currentMonotonicTime && nextFire
Time <= currentMonotonicTime) | 94 if (m_pendingSharedTimerFireTime <= currentMonotonicTime && nextFire
Time <= currentMonotonicTime) |
| 97 return; | 95 return; |
| 98 } | 96 } |
| 99 m_pendingSharedTimerFireTime = nextFireTime; | 97 m_pendingSharedTimerFireTime = nextFireTime; |
| 100 m_sharedTimer->setFireInterval(max(nextFireTime - currentMonotonicTime,
0.0)); | 98 m_sharedTimer->setFireInterval(std::max(nextFireTime - currentMonotonicT
ime, 0.0)); |
| 101 } | 99 } |
| 102 } | 100 } |
| 103 | 101 |
| 104 void ThreadTimers::sharedTimerFired() | 102 void ThreadTimers::sharedTimerFired() |
| 105 { | 103 { |
| 106 TRACE_EVENT_SET_SAMPLING_STATE("blink", "BlinkInternal"); | 104 TRACE_EVENT_SET_SAMPLING_STATE("blink", "BlinkInternal"); |
| 107 | 105 |
| 108 // Redirect to non-static method. | 106 // Redirect to non-static method. |
| 109 PlatformThreadData::current().threadTimers().sharedTimerFiredInternal(); | 107 PlatformThreadData::current().threadTimers().sharedTimerFiredInternal(); |
| 110 | 108 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 148 |
| 151 void ThreadTimers::fireTimersInNestedEventLoop() | 149 void ThreadTimers::fireTimersInNestedEventLoop() |
| 152 { | 150 { |
| 153 // Reset the reentrancy guard so the timers can fire again. | 151 // Reset the reentrancy guard so the timers can fire again. |
| 154 m_firingTimers = false; | 152 m_firingTimers = false; |
| 155 updateSharedTimer(); | 153 updateSharedTimer(); |
| 156 } | 154 } |
| 157 | 155 |
| 158 } // namespace blink | 156 } // namespace blink |
| 159 | 157 |
| OLD | NEW |