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

Side by Side Diff: lib/isolate/frog/isolateimpl.dart

Issue 9652001: SendPort + ReceivePort changes: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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
OLDNEW
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 /** 5 /**
6 * A native object that is shared across isolates. This object is visible to all 6 * A native object that is shared across isolates. This object is visible to all
7 * isolates running on the same worker (either UI or background web worker). 7 * isolates running on the same worker (either UI or background web worker).
8 * 8 *
9 * This is code that is intended to 'escape' the isolate boundaries in order to 9 * This is code that is intended to 'escape' the isolate boundaries in order to
10 * implement the semantics of isolates in JavaScript. Without this we would have 10 * implement the semantics of isolates in JavaScript. Without this we would have
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 void postMessage(msg) native "return this.postMessage(msg);"; 286 void postMessage(msg) native "return this.postMessage(msg);";
287 } 287 }
288 288
289 final String _SPAWNED_SIGNAL = "spawned"; 289 final String _SPAWNED_SIGNAL = "spawned";
290 290
291 class _IsolateNatives { 291 class _IsolateNatives {
292 292
293 /** JavaScript-specific implementation to spawn an isolate. */ 293 /** JavaScript-specific implementation to spawn an isolate. */
294 static Future<SendPort> spawn(Isolate isolate, bool isLight) { 294 static Future<SendPort> spawn(Isolate isolate, bool isLight) {
295 Completer<SendPort> completer = new Completer<SendPort>(); 295 Completer<SendPort> completer = new Completer<SendPort>();
296 ReceivePort port = new ReceivePort.singleShot(); 296 ReceivePort port = new ReceivePort();
297 port.receive((msg, SendPort replyPort) { 297 port.receive((msg, SendPort replyPort) {
298 port.close();
eub 2012/03/09 18:33:10 I wonder how often people are going to write this
eub 2012/03/09 18:33:10 I saw about a dozen instances looking over this CL
Siggi Cherem (dart-lang) 2012/03/10 03:10:00 Yeah - this is something that I saw commonly in te
298 assert(msg == _SPAWNED_SIGNAL); 299 assert(msg == _SPAWNED_SIGNAL);
299 completer.complete(replyPort); 300 completer.complete(replyPort);
300 }); 301 });
301 302
302 // TODO(floitsch): throw exception if isolate's class doesn't have a 303 // TODO(floitsch): throw exception if isolate's class doesn't have a
303 // default constructor. 304 // default constructor.
304 if (_globalState.useWorkers && !isLight) { 305 if (_globalState.useWorkers && !isLight) {
305 _startWorker(isolate, port.toSendPort()); 306 _startWorker(isolate, port.toSendPort());
306 } else { 307 } else {
307 _startNonWorker(isolate, port.toSendPort()); 308 _startNonWorker(isolate, port.toSendPort());
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 _fillStatics(_globalState.currentContext); 537 _fillStatics(_globalState.currentContext);
537 ReceivePort port = new ReceivePort(); 538 ReceivePort port = new ReceivePort();
538 replyTo.send(_SPAWNED_SIGNAL, port.toSendPort()); 539 replyTo.send(_SPAWNED_SIGNAL, port.toSendPort());
539 isolate._run(port); 540 isolate._run(port);
540 } 541 }
541 542
542 // TODO(sigmund): clean up above, after we make the new API the default: 543 // TODO(sigmund): clean up above, after we make the new API the default:
543 544
544 static _spawn2(String functionName, String uri, bool isLight) { 545 static _spawn2(String functionName, String uri, bool isLight) {
545 Completer<SendPort> completer = new Completer<SendPort>(); 546 Completer<SendPort> completer = new Completer<SendPort>();
546 ReceivePort port = new ReceivePort.singleShot(); 547 ReceivePort port = new ReceivePort();
547 port.receive((msg, SendPort replyPort) { 548 port.receive((msg, SendPort replyPort) {
549 port.close();
548 assert(msg == _SPAWNED_SIGNAL); 550 assert(msg == _SPAWNED_SIGNAL);
549 completer.complete(replyPort); 551 completer.complete(replyPort);
550 }); 552 });
551 553
552 SendPort signalReply = port.toSendPort(); 554 SendPort signalReply = port.toSendPort();
553 555
554 if (_globalState.useWorkers && !isLight) { 556 if (_globalState.useWorkers && !isLight) {
555 _startWorker2(functionName, uri, signalReply); 557 _startWorker2(functionName, uri, signalReply);
556 } else { 558 } else {
557 _startNonWorker2(functionName, uri, signalReply); 559 _startNonWorker2(functionName, uri, signalReply);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 'command': 'start2', 616 'command': 'start2',
615 'id': workerId, 617 'id': workerId,
616 // Note: we serialize replyPort twice because the child worker needs to 618 // Note: we serialize replyPort twice because the child worker needs to
617 // first deserialize the worker id, before it can correctly deserialize 619 // first deserialize the worker id, before it can correctly deserialize
618 // the port (port deserialization is sensitive to what is the current 620 // the port (port deserialization is sensitive to what is the current
619 // workerId). 621 // workerId).
620 'replyTo': _serializeMessage(replyPort), 622 'replyTo': _serializeMessage(replyPort),
621 'functionName': functionName })); 623 'functionName': functionName }));
622 } 624 }
623 } 625 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698