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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 { | 58 { |
59 stop(); | 59 stop(); |
60 } | 60 } |
61 | 61 |
62 void TimerBase::start(double nextFireInterval, double repeatInterval, const WebT
raceLocation& caller) | 62 void TimerBase::start(double nextFireInterval, double repeatInterval, const WebT
raceLocation& caller) |
63 { | 63 { |
64 ASSERT(m_thread == currentThread()); | 64 ASSERT(m_thread == currentThread()); |
65 | 65 |
66 m_location = caller; | 66 m_location = caller; |
67 m_repeatInterval = repeatInterval; | 67 m_repeatInterval = repeatInterval; |
68 setNextFireTime(monotonicallyIncreasingTime(), nextFireInterval); | 68 setNextFireTime(timerMonotonicallyIncreasingTime(), nextFireInterval); |
69 } | 69 } |
70 | 70 |
71 void TimerBase::stop() | 71 void TimerBase::stop() |
72 { | 72 { |
73 ASSERT(m_thread == currentThread()); | 73 ASSERT(m_thread == currentThread()); |
74 | 74 |
75 m_repeatInterval = 0; | 75 m_repeatInterval = 0; |
76 m_nextFireTime = 0; | 76 m_nextFireTime = 0; |
77 if (m_cancellableTimerTask) | 77 if (m_cancellableTimerTask) |
78 m_cancellableTimerTask->cancel(); | 78 m_cancellableTimerTask->cancel(); |
79 m_cancellableTimerTask = nullptr; | 79 m_cancellableTimerTask = nullptr; |
80 } | 80 } |
81 | 81 |
82 double TimerBase::nextFireInterval() const | 82 double TimerBase::nextFireInterval() const |
83 { | 83 { |
84 ASSERT(isActive()); | 84 ASSERT(isActive()); |
85 double current = monotonicallyIncreasingTime(); | 85 double current = timerMonotonicallyIncreasingTime(); |
86 if (m_nextFireTime < current) | 86 if (m_nextFireTime < current) |
87 return 0; | 87 return 0; |
88 return m_nextFireTime - current; | 88 return m_nextFireTime - current; |
89 } | 89 } |
90 | 90 |
91 WebTaskRunner* TimerBase::timerTaskRunner() | 91 WebTaskRunner* TimerBase::timerTaskRunner() const |
92 { | 92 { |
93 return m_webTaskRunner; | 93 return m_webTaskRunner; |
94 } | 94 } |
95 | 95 |
96 void TimerBase::setNextFireTime(double now, double delay) | 96 void TimerBase::setNextFireTime(double now, double delay) |
97 { | 97 { |
98 ASSERT(m_thread == currentThread()); | 98 ASSERT(m_thread == currentThread()); |
99 | 99 |
100 double newTime = now + delay; | 100 double newTime = now + delay; |
101 | 101 |
(...skipping 12 matching lines...) Expand all Loading... |
114 void TimerBase::runInternal() | 114 void TimerBase::runInternal() |
115 { | 115 { |
116 if (!canFire()) | 116 if (!canFire()) |
117 return; | 117 return; |
118 | 118 |
119 TRACE_EVENT0("blink", "TimerBase::run"); | 119 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()); | 120 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"); | 121 TRACE_EVENT_SET_SAMPLING_STATE("blink", "BlinkInternal"); |
122 | 122 |
123 if (m_repeatInterval) { | 123 if (m_repeatInterval) { |
124 double now = monotonicallyIncreasingTime(); | 124 double now = timerMonotonicallyIncreasingTime(); |
125 // This computation should be drift free, and it will cope if we miss a
beat, | 125 // This computation should be drift free, and it will cope if we miss a
beat, |
126 // which can easily happen if the thread is busy. It will also cope if
we get | 126 // which can easily happen if the thread is busy. It will also cope if
we get |
127 // called slightly before m_unalignedNextFireTime, which can happen due
to lack | 127 // called slightly before m_unalignedNextFireTime, which can happen due
to lack |
128 // of timer precision. | 128 // of timer precision. |
129 double intervalToNextFireTime = m_repeatInterval - fmod(now - m_nextFire
Time, m_repeatInterval); | 129 double intervalToNextFireTime = m_repeatInterval - fmod(now - m_nextFire
Time, m_repeatInterval); |
130 setNextFireTime(monotonicallyIncreasingTime(), intervalToNextFireTime); | 130 setNextFireTime(timerMonotonicallyIncreasingTime(), intervalToNextFireTi
me); |
131 } else { | 131 } else { |
132 m_nextFireTime = 0; | 132 m_nextFireTime = 0; |
133 } | 133 } |
134 fired(); | 134 fired(); |
135 TRACE_EVENT_SET_SAMPLING_STATE("blink", "Sleeping"); | 135 TRACE_EVENT_SET_SAMPLING_STATE("blink", "Sleeping"); |
136 } | 136 } |
137 | 137 |
138 bool TimerBase::Comparator::operator()(const TimerBase* a, const TimerBase* b) c
onst | 138 bool TimerBase::Comparator::operator()(const TimerBase* a, const TimerBase* b) c
onst |
139 { | 139 { |
140 return a->m_nextFireTime < b->m_nextFireTime; | 140 return a->m_nextFireTime < b->m_nextFireTime; |
141 } | 141 } |
142 | 142 |
143 // static | 143 // static |
144 WebTaskRunner* TimerBase::UnthrottledWebTaskRunner() | 144 WebTaskRunner* TimerBase::UnthrottledWebTaskRunner() |
145 { | 145 { |
146 return Platform::current()->currentThread()->taskRunner(); | 146 return Platform::current()->currentThread()->taskRunner(); |
147 } | 147 } |
148 | 148 |
| 149 double TimerBase::timerMonotonicallyIncreasingTime() const |
| 150 { |
| 151 return timerTaskRunner()->monotonicallyIncreasingVirtualTimeSeconds(); |
| 152 } |
| 153 |
149 } // namespace blink | 154 } // namespace blink |
OLD | NEW |