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(time(), 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 = time(); |
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() |
92 { | 92 { |
93 return m_webTaskRunner; | 93 return m_webTaskRunner; |
94 } | 94 } |
95 | 95 |
(...skipping 18 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 = time(); |
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(time(), intervalToNextFireTime); |
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 double TimerBase::time() const | |
144 { | |
145 return Platform::current()->monotonicallyIncreasingVirtualTimeSeconds(); | |
Sami
2016/02/03 18:03:44
This is going to get called fairly often so it mig
alex clarke (OOO till 29th)
2016/02/04 15:00:10
Done.
| |
146 } | |
147 | |
143 // static | 148 // static |
144 WebTaskRunner* TimerBase::UnthrottledWebTaskRunner() | 149 WebTaskRunner* TimerBase::UnthrottledWebTaskRunner() |
145 { | 150 { |
146 return Platform::current()->currentThread()->taskRunner(); | 151 return Platform::current()->currentThread()->taskRunner(); |
147 } | 152 } |
148 | 153 |
149 } // namespace blink | 154 } // namespace blink |
OLD | NEW |