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

Side by Side Diff: dart/sdk/lib/_internal/lib/isolate_helper.dart

Issue 59073003: Version 0.8.10.4 (Closed) Base URL: http://dart.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 1 month 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 library _isolate_helper; 5 library _isolate_helper;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection' show Queue, HashMap; 8 import 'dart:collection' show Queue, HashMap;
9 import 'dart:isolate'; 9 import 'dart:isolate';
10 import 'dart:_js_helper' show 10 import 'dart:_js_helper' show
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 bool operator ==(var other); 722 bool operator ==(var other);
723 int get hashCode; 723 int get hashCode;
724 } 724 }
725 725
726 /** A send port that delivers messages in-memory via native JavaScript calls. */ 726 /** A send port that delivers messages in-memory via native JavaScript calls. */
727 class _NativeJsSendPort extends _BaseSendPort implements SendPort { 727 class _NativeJsSendPort extends _BaseSendPort implements SendPort {
728 final ReceivePortImpl _receivePort; 728 final ReceivePortImpl _receivePort;
729 729
730 const _NativeJsSendPort(this._receivePort, int isolateId) : super(isolateId); 730 const _NativeJsSendPort(this._receivePort, int isolateId) : super(isolateId);
731 731
732 void send(var message, [SendPort replyTo]) { 732 void send(var message) {
733 _waitForPendingPorts(message, () { 733 _waitForPendingPorts(message, () {
734 // Check that the isolate still runs and the port is still open 734 // Check that the isolate still runs and the port is still open
735 final isolate = _globalState.isolates[_isolateId]; 735 final isolate = _globalState.isolates[_isolateId];
736 if (isolate == null) return; 736 if (isolate == null) return;
737 if (_receivePort._controller.isClosed) return; 737 if (_receivePort._controller.isClosed) return;
738 738
739 // We force serialization/deserialization as a simple way to ensure 739 // We force serialization/deserialization as a simple way to ensure
740 // isolate communication restrictions are respected between isolates that 740 // isolate communication restrictions are respected between isolates that
741 // live in the same worker. [_NativeJsSendPort] delivers both messages 741 // live in the same worker. [_NativeJsSendPort] delivers both messages
742 // from the same worker and messages from other workers. In particular, 742 // from the same worker and messages from other workers. In particular,
(...skipping 25 matching lines...) Expand all
768 768
769 /** A send port that delivers messages via worker.postMessage. */ 769 /** A send port that delivers messages via worker.postMessage. */
770 // TODO(eub): abstract this for iframes. 770 // TODO(eub): abstract this for iframes.
771 class _WorkerSendPort extends _BaseSendPort implements SendPort { 771 class _WorkerSendPort extends _BaseSendPort implements SendPort {
772 final int _workerId; 772 final int _workerId;
773 final int _receivePortId; 773 final int _receivePortId;
774 774
775 const _WorkerSendPort(this._workerId, int isolateId, this._receivePortId) 775 const _WorkerSendPort(this._workerId, int isolateId, this._receivePortId)
776 : super(isolateId); 776 : super(isolateId);
777 777
778 void send(var message, [SendPort replyTo]) { 778 void send(var message) {
779 _waitForPendingPorts(message, () { 779 _waitForPendingPorts(message, () {
780 final workerMessage = _serializeMessage({ 780 final workerMessage = _serializeMessage({
781 'command': 'message', 781 'command': 'message',
782 'port': this, 782 'port': this,
783 'msg': message}); 783 'msg': message});
784 784
785 if (_globalState.isWorker) { 785 if (_globalState.isWorker) {
786 // Communication from one worker to another go through the 786 // Communication from one worker to another go through the
787 // main worker. 787 // main worker.
788 _globalState.mainManager.postMessage(workerMessage); 788 _globalState.mainManager.postMessage(workerMessage);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 } 839 }
840 pending = null; 840 pending = null;
841 }); 841 });
842 } 842 }
843 843
844 _BufferingSendPort.fromPort(isolateId, this._port) 844 _BufferingSendPort.fromPort(isolateId, this._port)
845 : super(isolateId), _id = _idCount { 845 : super(isolateId), _id = _idCount {
846 _idCount++; 846 _idCount++;
847 } 847 }
848 848
849 void send(var message, [SendPort replyTo]) { 849 void send(var message) {
850 if (_port != null) { 850 if (_port != null) {
851 _port.send(message, replyTo); 851 _port.send(message);
852 } else { 852 } else {
853 pending.add(message); 853 pending.add(message);
854 } 854 }
855 } 855 }
856 856
857 bool operator ==(var other) => 857 bool operator ==(var other) =>
858 other is _BufferingSendPort && _id == other._id; 858 other is _BufferingSendPort && _id == other._id;
859 int get hashCode => _id; 859 int get hashCode => _id;
860 } 860 }
861 861
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 _handle = null; 1374 _handle = null;
1375 } else { 1375 } else {
1376 throw new UnsupportedError("Canceling a timer."); 1376 throw new UnsupportedError("Canceling a timer.");
1377 } 1377 }
1378 } 1378 }
1379 1379
1380 bool get isActive => _handle != null; 1380 bool get isActive => _handle != null;
1381 } 1381 }
1382 1382
1383 bool hasTimer() => JS('', '#.setTimeout', globalThis) != null; 1383 bool hasTimer() => JS('', '#.setTimeout', globalThis) != null;
OLDNEW
« no previous file with comments | « dart/sdk/lib/_internal/lib/async_patch.dart ('k') | dart/sdk/lib/html/dart2js/html_dart2js.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698