| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 class _Timer implements Timer { | 5 class _Timer implements Timer { |
| 6 // Set jitter to wake up timer events that would happen in _TIMER_JITTER ms. | 6 // Set jitter to wake up timer events that would happen in _TIMER_JITTER ms. |
| 7 static final int _TIMER_JITTER = 0; | 7 static final int _TIMER_JITTER = 0; |
| 8 | 8 |
| 9 // Disables the timer. | 9 // Disables the timer. |
| 10 static final int _NO_TIMER = -1; | 10 static final int _NO_TIMER = -1; |
| 11 | 11 |
| 12 static Timer _createTimer(void callback(Timer timer), | 12 static Timer _createTimer(void callback(Timer timer), |
| 13 int milliSeconds, | 13 int milliSeconds, |
| 14 bool repeating) { | 14 bool repeating) { |
| 15 _EventHandler._start(); | 15 _EventHandler._start(); |
| 16 if (_timers === null) { | 16 if (_timers === null) { |
| 17 _timers = new DoubleLinkedQueue<_Timer>(); | 17 _timers = new DoubleLinkedQueue<_Timer>(); |
| 18 } | 18 } |
| 19 Timer timer = new _Timer._internal(); | 19 Timer timer = new _Timer._internal(); |
| 20 timer._callback = callback; | 20 timer._callback = callback; |
| 21 timer._milliSeconds = milliSeconds; | 21 timer._milliSeconds = milliSeconds; |
| 22 timer._wakeupTime = (new Date.now()).value + milliSeconds; | 22 timer._wakeupTime = (new Date.now()).millisecondsSinceEpoch + milliSeconds; |
| 23 timer._repeating = repeating; | 23 timer._repeating = repeating; |
| 24 timer._addTimerToList(); | 24 timer._addTimerToList(); |
| 25 timer._notifyEventHandler(); | 25 timer._notifyEventHandler(); |
| 26 return timer; | 26 return timer; |
| 27 } | 27 } |
| 28 | 28 |
| 29 factory _Timer(int milliSeconds, void callback(Timer timer)) { | 29 factory _Timer(int milliSeconds, void callback(Timer timer)) { |
| 30 return _createTimer(callback, milliSeconds, false); | 30 return _createTimer(callback, milliSeconds, false); |
| 31 } | 31 } |
| 32 | 32 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 _timers.firstEntry().element._wakeupTime); | 113 _timers.firstEntry().element._wakeupTime); |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 | 117 |
| 118 // Creates a receive port and registers the timer handler on that | 118 // Creates a receive port and registers the timer handler on that |
| 119 // receive port. | 119 // receive port. |
| 120 void _createTimerHandler() { | 120 void _createTimerHandler() { |
| 121 | 121 |
| 122 void _handleTimeout() { | 122 void _handleTimeout() { |
| 123 int currentTime = (new Date.now()).value + _TIMER_JITTER; | 123 int currentTime = |
| 124 (new Date.now()).millisecondsSinceEpoch + _TIMER_JITTER; |
| 124 | 125 |
| 125 // Collect all pending timers. | 126 // Collect all pending timers. |
| 126 DoubleLinkedQueueEntry<_Timer> entry = _timers.firstEntry(); | 127 DoubleLinkedQueueEntry<_Timer> entry = _timers.firstEntry(); |
| 127 var pending_timers = new List(); | 128 var pending_timers = new List(); |
| 128 while (entry !== null) { | 129 while (entry !== null) { |
| 129 _Timer timer = entry.element; | 130 _Timer timer = entry.element; |
| 130 if (timer._wakeupTime <= currentTime) { | 131 if (timer._wakeupTime <= currentTime) { |
| 131 entry.remove(); | 132 entry.remove(); |
| 132 pending_timers.addLast(timer); | 133 pending_timers.addLast(timer); |
| 133 entry = _timers.firstEntry(); | 134 entry = _timers.firstEntry(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 179 |
| 179 static ReceivePort _receivePort; | 180 static ReceivePort _receivePort; |
| 180 static bool _handling_callbacks = false; | 181 static bool _handling_callbacks = false; |
| 181 | 182 |
| 182 var _callback; | 183 var _callback; |
| 183 int _milliSeconds; | 184 int _milliSeconds; |
| 184 int _wakeupTime; | 185 int _wakeupTime; |
| 185 bool _repeating; | 186 bool _repeating; |
| 186 } | 187 } |
| 187 | 188 |
| OLD | NEW |