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) = |
| 11 _ReceivePortImpl.fromRawReceivePort; | 11 _ReceivePortImpl.fromRawReceivePort; |
| 12 } | 12 } |
| 13 | 13 |
| 14 patch class Capability { | 14 patch class Capability { |
| 15 /* patch */ factory Capability() { | 15 /* patch */ factory Capability() = _CapabilityImpl; |
|
Lasse Reichstein Nielsen
2014/07/02 08:11:55
Could you make the patch constructor native:
/*p
Ivan Posva
2014/07/03 12:51:16
Since I will need to implement hash code and equal
| |
| 16 throw new UnimplementedError(); | |
| 17 } | |
| 18 } | 16 } |
| 19 | 17 |
| 20 class _CapabilityImpl { | 18 class _CapabilityImpl implements Capability { |
| 21 factory _CapabilityImpl() native "CapabilityImpl_factory"; | 19 factory _CapabilityImpl() native "CapabilityImpl_factory"; |
| 22 } | 20 } |
| 23 | 21 |
| 24 patch class RawReceivePort { | 22 patch class RawReceivePort { |
| 25 /** | 23 /** |
| 26 * Opens a long-lived port for receiving messages. | 24 * Opens a long-lived port for receiving messages. |
| 27 * | 25 * |
| 28 * A [RawReceivePort] is low level and does not work with [Zone]s. It | 26 * A [RawReceivePort] is low level and does not work with [Zone]s. It |
| 29 * can not be paused. The data-handler must be set before the first | 27 * can not be paused. The data-handler must be set before the first |
| 30 * event is received. | 28 * event is received. |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 | 222 |
| 225 Isolate._self.handler = isolateStartHandler; | 223 Isolate._self.handler = isolateStartHandler; |
| 226 } | 224 } |
| 227 | 225 |
| 228 patch class Isolate { | 226 patch class Isolate { |
| 229 /* patch */ static Future<Isolate> spawn( | 227 /* patch */ static Future<Isolate> spawn( |
| 230 void entryPoint(message), var message, { bool paused: false }) { | 228 void entryPoint(message), var message, { bool paused: false }) { |
| 231 // `paused` isn't handled yet. | 229 // `paused` isn't handled yet. |
| 232 try { | 230 try { |
| 233 // The VM will invoke [_startIsolate] with entryPoint as argument. | 231 // The VM will invoke [_startIsolate] with entryPoint as argument. |
| 234 SendPort controlPort = _spawnFunction(entryPoint); | 232 List spawnData = _spawnFunction(entryPoint); |
| 233 assert(spawnData.length == 3); | |
| 234 SendPort controlPort = spawnData[0]; | |
| 235 RawReceivePort readyPort = new RawReceivePort(); | 235 RawReceivePort readyPort = new RawReceivePort(); |
| 236 controlPort.send([readyPort.sendPort, message]); | 236 controlPort.send([readyPort.sendPort, message]); |
| 237 Completer completer = new Completer<Isolate>.sync(); | 237 Completer completer = new Completer<Isolate>.sync(); |
| 238 readyPort.handler = (readyMessage) { | 238 readyPort.handler = (readyMessage) { |
| 239 assert(readyMessage == 'started'); | 239 assert(readyMessage == 'started'); |
| 240 readyPort.close(); | 240 readyPort.close(); |
| 241 completer.complete(new Isolate(controlPort)); | 241 completer.complete(new Isolate(controlPort, |
| 242 pauseCapability: spawnData[1], | |
| 243 terminateCapability: spawnData[2])); | |
| 242 }; | 244 }; |
| 243 return completer.future; | 245 return completer.future; |
| 244 } catch (e, st) { | 246 } catch (e, st) { |
| 245 return new Future<Isolate>.error(e, st); | 247 return new Future<Isolate>.error(e, st); |
| 246 }; | 248 }; |
| 247 } | 249 } |
| 248 | 250 |
| 249 /* patch */ static Future<Isolate> spawnUri( | 251 /* patch */ static Future<Isolate> spawnUri( |
| 250 Uri uri, List<String> args, var message, { bool paused: false }) { | 252 Uri uri, List<String> args, var message, { bool paused: false }) { |
| 251 // `paused` isn't handled yet. | 253 // `paused` isn't handled yet. |
| 252 try { | 254 try { |
| 253 // The VM will invoke [_startIsolate] and not `main`. | 255 // The VM will invoke [_startIsolate] and not `main`. |
| 254 SendPort controlPort = _spawnUri(uri.toString()); | 256 List spawnData = _spawnUri(uri.toString()); |
| 257 assert(spawnData.length == 3); | |
| 258 SendPort controlPort = spawnData[0]; | |
| 255 RawReceivePort readyPort = new RawReceivePort(); | 259 RawReceivePort readyPort = new RawReceivePort(); |
| 256 controlPort.send([readyPort.sendPort, args, message]); | 260 controlPort.send([readyPort.sendPort, args, message]); |
| 257 Completer completer = new Completer<Isolate>.sync(); | 261 Completer completer = new Completer<Isolate>.sync(); |
| 258 readyPort.handler = (readyMessage) { | 262 readyPort.handler = (readyMessage) { |
| 259 assert(readyMessage == 'started'); | 263 assert(readyMessage == 'started'); |
| 260 readyPort.close(); | 264 readyPort.close(); |
| 261 completer.complete(new Isolate(controlPort)); | 265 completer.complete(new Isolate(controlPort, |
| 266 pauseCapability: spawnData[1], | |
| 267 terminateCapability: spawnData[2])); | |
| 262 }; | 268 }; |
| 263 return completer.future; | 269 return completer.future; |
| 264 } catch (e, st) { | 270 } catch (e, st) { |
| 265 return new Future<Isolate>.error(e, st); | 271 return new Future<Isolate>.error(e, st); |
| 266 }; | 272 }; |
| 267 return completer.future; | 273 return completer.future; |
| 268 } | 274 } |
| 269 | 275 |
| 270 static final RawReceivePort _self = _mainPort; | 276 static final RawReceivePort _self = _mainPort; |
| 271 static RawReceivePort get _mainPort native "Isolate_mainPort"; | 277 static RawReceivePort get _mainPort native "Isolate_mainPort"; |
| 272 | 278 |
| 273 static SendPort _spawnFunction(Function topLevelFunction) | 279 // TODO(iposva): Cleanup to have only one definition. |
| 280 // These values need to be kept in sync with the class IsolateMessageHandler | |
| 281 // in vm/isolate.cc. | |
| 282 static const _PAUSE = 1; | |
| 283 static const _RESUME = 2; | |
| 284 | |
| 285 static List _spawnFunction(Function topLevelFunction) | |
| 274 native "Isolate_spawnFunction"; | 286 native "Isolate_spawnFunction"; |
| 275 | 287 |
| 276 static SendPort _spawnUri(String uri) native "Isolate_spawnUri"; | 288 static List _spawnUri(String uri) native "Isolate_spawnUri"; |
| 289 | |
| 290 static void _sendOOB(port, msg) native "Isolate_sendOOB"; | |
| 277 | 291 |
| 278 /* patch */ void _pause(Capability resumeCapability) { | 292 /* patch */ void _pause(Capability resumeCapability) { |
| 279 throw new UnsupportedError("pause"); | 293 var msg = new List(4) |
| 294 ..[0] = 0 // Make room for OOM message type. | |
| 295 ..[1] = _PAUSE | |
| 296 ..[2] = pauseCapability | |
| 297 ..[3] = resumeCapability; | |
| 298 _sendOOB(controlPort, msg); | |
| 280 } | 299 } |
| 281 | 300 |
| 282 /* patch */ void resume(Capability resumeCapability) { | 301 /* patch */ void resume(Capability resumeCapability) { |
| 283 throw new UnsupportedError("resume"); | 302 var msg = new List(4) |
| 303 ..[0] = 0 // Make room for OOM message type. | |
| 304 ..[1] = _RESUME | |
| 305 ..[2] = pauseCapability | |
| 306 ..[3] = resumeCapability; | |
| 307 _sendOOB(controlPort, msg); | |
| 284 } | 308 } |
| 285 | 309 |
| 286 /* patch */ void addOnExitListener(SendPort responsePort) { | 310 /* patch */ void addOnExitListener(SendPort responsePort) { |
| 287 throw new UnsupportedError("addOnExitListener"); | 311 throw new UnsupportedError("addOnExitListener"); |
| 288 } | 312 } |
| 289 | 313 |
| 290 /* patch */ void removeOnExitListener(SendPort responsePort) { | 314 /* patch */ void removeOnExitListener(SendPort responsePort) { |
| 291 throw new UnsupportedError("removeOnExitListener"); | 315 throw new UnsupportedError("removeOnExitListener"); |
| 292 } | 316 } |
| 293 | 317 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 304 } | 328 } |
| 305 | 329 |
| 306 /* patch */ void addErrorListener(SendPort port) { | 330 /* patch */ void addErrorListener(SendPort port) { |
| 307 throw new UnsupportedError("addErrorListener"); | 331 throw new UnsupportedError("addErrorListener"); |
| 308 } | 332 } |
| 309 | 333 |
| 310 /* patch */ void removeErrorListener(SendPort port) { | 334 /* patch */ void removeErrorListener(SendPort port) { |
| 311 throw new UnsupportedError("removeErrorListener"); | 335 throw new UnsupportedError("removeErrorListener"); |
| 312 } | 336 } |
| 313 } | 337 } |
| OLD | NEW |