Chromium Code Reviews| 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 import "dart:collection" show HashMap; | 5 import "dart:collection" show HashMap; |
| 6 | 6 |
| 7 patch class ReceivePort { | 7 patch class ReceivePort { |
| 8 /* patch */ factory ReceivePort() = _ReceivePortImpl; | 8 /* patch */ factory ReceivePort() = _ReceivePortImpl; |
| 9 | 9 |
| 10 /* patch */ factory ReceivePort.fromRawReceivePort(RawReceivePort rawPort) = | 10 /* patch */ factory ReceivePort.fromRawReceivePort(RawReceivePort rawPort) = |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 | 50 |
| 51 close() { | 51 close() { |
| 52 _rawPort.close(); | 52 _rawPort.close(); |
| 53 _controller.close(); | 53 _controller.close(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 final RawReceivePort _rawPort; | 56 final RawReceivePort _rawPort; |
| 57 StreamController _controller; | 57 StreamController _controller; |
| 58 } | 58 } |
| 59 | 59 |
| 60 typedef void ImmediateCallback(); | |
| 61 | |
| 62 /// The callback that has been registered through `scheduleImmediate`. | |
| 63 ImmediateCallback _pendingImmediateCallback; | |
| 64 | |
| 65 /// The closure that should be used as scheduleImmediateClosure, when the VM | |
| 66 /// is responsible for the event loop. | |
| 67 void _isolateScheduleImmediate(void callback()) { | |
| 68 assert(_pendingImmediateCallback == null); | |
| 69 _pendingImmediateCallback = callback; | |
| 70 } | |
| 71 | |
| 72 /// Provide closurized access to _isolateScheduleImmediate. | |
| 73 /// This makes it easier for embedders to set the scheduleImmediate closure. | |
| 74 Function get _isolateScheduleImmediateClosure => _isolateScheduleImmediate; | |
|
Ivan Posva
2013/11/27 22:08:32
There is one too many ways to get at the closure.
floitsch
2013/11/28 19:05:54
Dartium usually uses getters, but I should be able
| |
| 75 | |
| 76 /// The embedder can execute this function to get hold of | |
| 77 /// [_isolateScheduleImmediate] above. | |
| 78 Function _getIsolateScheduleImmediateClosure() { | |
| 79 return _isolateScheduleImmediate; | |
| 80 } | |
| 81 | |
| 60 class _RawReceivePortImpl implements RawReceivePort { | 82 class _RawReceivePortImpl implements RawReceivePort { |
| 61 factory _RawReceivePortImpl() native "RawReceivePortImpl_factory"; | 83 factory _RawReceivePortImpl() native "RawReceivePortImpl_factory"; |
| 62 | 84 |
| 63 close() { | 85 close() { |
| 64 _portMap.remove(_id); | 86 _portMap.remove(_id); |
| 65 _closeInternal(_id); | 87 _closeInternal(_id); |
| 66 } | 88 } |
| 67 | 89 |
| 68 SendPort get sendPort { | 90 SendPort get sendPort { |
| 69 return new _SendPortImpl(_id); | 91 return new _SendPortImpl(_id); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 85 | 107 |
| 86 // Called from the VM to retrieve the RawReceivePort for a message. | 108 // Called from the VM to retrieve the RawReceivePort for a message. |
| 87 static _RawReceivePortImpl _lookupReceivePort(int id) { | 109 static _RawReceivePortImpl _lookupReceivePort(int id) { |
| 88 return _portMap[id]; | 110 return _portMap[id]; |
| 89 } | 111 } |
| 90 | 112 |
| 91 // Called from the VM to dispatch to the handler. | 113 // Called from the VM to dispatch to the handler. |
| 92 static void _handleMessage( | 114 static void _handleMessage( |
| 93 _RawReceivePortImpl port, int replyId, var message) { | 115 _RawReceivePortImpl port, int replyId, var message) { |
| 94 assert(port != null); | 116 assert(port != null); |
| 117 // TODO(floitsch): this relies on the fact that any exception aborts the | |
| 118 // VM. Once we have non-fatal global exceptions we need to catch errors | |
| 119 // so that we can run the immediate callbacks. | |
| 95 port._handler(message); | 120 port._handler(message); |
| 121 if (_pendingImmediateCallback != null) { | |
| 122 var callback = _pendingImmediateCallback; | |
| 123 _pendingImmediateCallback = null; | |
| 124 callback(); | |
| 125 } | |
| 96 } | 126 } |
| 97 | 127 |
| 98 // Call into the VM to close the VM maintained mappings. | 128 // Call into the VM to close the VM maintained mappings. |
| 99 static _closeInternal(int id) native "RawReceivePortImpl_closeInternal"; | 129 static _closeInternal(int id) native "RawReceivePortImpl_closeInternal"; |
| 100 | 130 |
| 101 void set handler(Function newHandler) { | 131 void set handler(Function newHandler) { |
| 102 this._handler = newHandler; | 132 this._handler = newHandler; |
| 103 } | 133 } |
| 104 | 134 |
| 105 final int _id; | 135 final int _id; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 } | 272 } |
| 243 | 273 |
| 244 static final RawReceivePort _self = _mainPort; | 274 static final RawReceivePort _self = _mainPort; |
| 245 static RawReceivePort get _mainPort native "Isolate_mainPort"; | 275 static RawReceivePort get _mainPort native "Isolate_mainPort"; |
| 246 | 276 |
| 247 static SendPort _spawnFunction(Function topLevelFunction) | 277 static SendPort _spawnFunction(Function topLevelFunction) |
| 248 native "Isolate_spawnFunction"; | 278 native "Isolate_spawnFunction"; |
| 249 | 279 |
| 250 static SendPort _spawnUri(String uri) native "Isolate_spawnUri"; | 280 static SendPort _spawnUri(String uri) native "Isolate_spawnUri"; |
| 251 } | 281 } |
| OLD | NEW |