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

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

Issue 9662024: Refactor, rename, and generally rationalize code in the Frog isolates library, (Closed) Base URL: http://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 /** Common functionality to all send ports. */ 5 /** Common functionality to all send ports. */
6 class _BaseSendPort implements SendPort { 6 class _BaseSendPort implements SendPort {
7 /** Id for the destination isolate. */ 7 /** Id for the destination isolate. */
8 final int _isolateId; 8 final int _isolateId;
9 9
10 _BaseSendPort(this._isolateId); 10 _BaseSendPort(this._isolateId);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 }); 85 });
86 } 86 }
87 87
88 bool operator ==(var other) => (other is _NativeJsSendPort) && 88 bool operator ==(var other) => (other is _NativeJsSendPort) &&
89 (_receivePort == other._receivePort); 89 (_receivePort == other._receivePort);
90 90
91 int hashCode() => _receivePort._id; 91 int hashCode() => _receivePort._id;
92 } 92 }
93 93
94 /** A send port that delivers messages via worker.postMessage. */ 94 /** A send port that delivers messages via worker.postMessage. */
95 // TODO(eub): abstract this for iframes.
95 class _WorkerSendPort extends _BaseSendPort implements SendPort { 96 class _WorkerSendPort extends _BaseSendPort implements SendPort {
96 final int _workerId; 97 final int _workerId;
97 final int _receivePortId; 98 final int _receivePortId;
98 99
99 const _WorkerSendPort(this._workerId, int isolateId, this._receivePortId) 100 const _WorkerSendPort(this._workerId, int isolateId, this._receivePortId)
100 : super(isolateId); 101 : super(isolateId);
101 102
102 void send(var message, [SendPort replyTo = null]) { 103 void send(var message, [SendPort replyTo = null]) {
103 _waitForPendingPorts([message, replyTo], () { 104 _waitForPendingPorts([message, replyTo], () {
104 checkReplyTo(replyTo); 105 checkReplyTo(replyTo);
105 final workerMessage = _serializeMessage({ 106 final workerMessage = _serializeMessage({
106 'command': 'message', 107 'command': 'message',
107 'port': this, 108 'port': this,
108 'msg': message, 109 'msg': message,
109 'replyTo': replyTo}); 110 'replyTo': replyTo});
110 111
111 if (_globalState.isWorker) { 112 if (_globalState.isWorker) {
112 // communication from one worker to another go through the main worker: 113 // communication from one worker to another go through the main worker:
113 _globalState.mainWorker.postMessage(workerMessage); 114 _globalState.mainManager.postMessage(workerMessage);
114 } else { 115 } else {
115 _globalState.workers[_workerId].postMessage(workerMessage); 116 _globalState.managers[_workerId].postMessage(workerMessage);
116 } 117 }
117 }); 118 });
118 } 119 }
119 120
120 bool operator ==(var other) { 121 bool operator ==(var other) {
121 return (other is _WorkerSendPort) && 122 return (other is _WorkerSendPort) &&
122 (_workerId == other._workerId) && 123 (_workerId == other._workerId) &&
123 (_isolateId == other._isolateId) && 124 (_isolateId == other._isolateId) &&
124 (_receivePortId == other._receivePortId); 125 (_receivePortId == other._receivePortId);
125 } 126 }
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 // map.getValues().forEach(_dispatch); 276 // map.getValues().forEach(_dispatch);
276 map.getValues().forEach((e) => _dispatch(e)); 277 map.getValues().forEach((e) => _dispatch(e));
277 } 278 }
278 279
279 visitBufferingSendPort(_BufferingSendPort port) { 280 visitBufferingSendPort(_BufferingSendPort port) {
280 if (port._port == null) { 281 if (port._port == null) {
281 ports.add(port._futurePort); 282 ports.add(port._futurePort);
282 } 283 }
283 } 284 }
284 } 285 }
OLDNEW
« lib/isolate/frog/isolateimpl.dart ('K') | « lib/isolate/frog/messages.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698