Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(491)

Side by Side Diff: sdk/lib/io/timer_impl.dart

Issue 359673002: - Remove Dart_ReceivePortGetId, Dart_GetReceivePort and Dart_PostMessage. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/eventhandler.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 part of dart.io; 5 part of dart.io;
6 6
7 // Timer heap implemented as a array-based binary heap[0]. 7 // Timer heap implemented as a array-based binary heap[0].
8 // This allows for O(1) `first`, O(log(n)) `remove`/`removeFirst` and O(log(n)) 8 // This allows for O(1) `first`, O(log(n)) `remove`/`removeFirst` and O(log(n))
9 // `add`. 9 // `add`.
10 // 10 //
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 // While we are already handling callbacks we will not notify the event 228 // While we are already handling callbacks we will not notify the event
229 // handler. _handleTimeout will call _notifyEventHandler once all pending 229 // handler. _handleTimeout will call _notifyEventHandler once all pending
230 // timers are processed. 230 // timers are processed.
231 return; 231 return;
232 } 232 }
233 233
234 if (_firstZeroTimer == null && _heap.isEmpty) { 234 if (_firstZeroTimer == null && _heap.isEmpty) {
235 // No pending timers: Close the receive port and let the event handler 235 // No pending timers: Close the receive port and let the event handler
236 // know. 236 // know.
237 if (_receivePort != null) { 237 if (_receivePort != null) {
238 _EventHandler._sendData(null, _receivePort, _NO_TIMER); 238 _EventHandler._sendData(null, _sendPort, _NO_TIMER);
239 _shutdownTimerHandler(); 239 _shutdownTimerHandler();
240 } 240 }
241 } else { 241 } else {
242 if (_receivePort == null) { 242 if (_receivePort == null) {
243 // Create a receive port and register a message handler for the timer 243 // Create a receive port and register a message handler for the timer
244 // events. 244 // events.
245 _createTimerHandler(); 245 _createTimerHandler();
246 } 246 }
247 if (_firstZeroTimer != null) { 247 if (_firstZeroTimer != null) {
248 _sendPort.send(null); 248 _sendPort.send(null);
249 } else { 249 } else {
250 _EventHandler._sendData(null, 250 _EventHandler._sendData(null,
251 _receivePort, 251 _sendPort,
252 _heap.first._wakeupTime); 252 _heap.first._wakeupTime);
253 } 253 }
254 } 254 }
255 } 255 }
256 256
257 static void _handleTimeout(_) { 257 static void _handleTimeout(_) {
258 int currentTime = new DateTime.now().millisecondsSinceEpoch; 258 int currentTime = new DateTime.now().millisecondsSinceEpoch;
259 // Collect all pending timers. 259 // Collect all pending timers.
260 var timer = _firstZeroTimer; 260 var timer = _firstZeroTimer;
261 var nextTimer = _lastZeroTimer; 261 var nextTimer = _lastZeroTimer;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 static void _createTimerHandler() { 309 static void _createTimerHandler() {
310 if(_receivePort == null) { 310 if(_receivePort == null) {
311 _receivePort = new RawReceivePort(_handleTimeout); 311 _receivePort = new RawReceivePort(_handleTimeout);
312 _sendPort = _receivePort.sendPort; 312 _sendPort = _receivePort.sendPort;
313 } 313 }
314 } 314 }
315 315
316 static void _shutdownTimerHandler() { 316 static void _shutdownTimerHandler() {
317 _receivePort.close(); 317 _receivePort.close();
318 _receivePort = null; 318 _receivePort = null;
319 _sendPort = null;
319 } 320 }
320 } 321 }
321 322
322 // Provide a closure which will allocate a Timer object to be able to hook 323 // Provide a closure which will allocate a Timer object to be able to hook
323 // up the Timer interface in dart:isolate with the implementation here. 324 // up the Timer interface in dart:isolate with the implementation here.
324 _getTimerFactoryClosure() { 325 _getTimerFactoryClosure() {
325 return (int milliSeconds, void callback(Timer timer), bool repeating) { 326 return (int milliSeconds, void callback(Timer timer), bool repeating) {
326 if (repeating) { 327 if (repeating) {
327 return new _Timer.periodic(milliSeconds, callback); 328 return new _Timer.periodic(milliSeconds, callback);
328 } 329 }
329 return new _Timer(milliSeconds, callback); 330 return new _Timer(milliSeconds, callback);
330 }; 331 };
331 } 332 }
332 333
333 334
OLDNEW
« no previous file with comments | « sdk/lib/io/eventhandler.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698