| 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 /** 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 }); | 79 }); |
| 80 } | 80 } |
| 81 | 81 |
| 82 bool operator ==(var other) => (other is _NativeJsSendPort) && | 82 bool operator ==(var other) => (other is _NativeJsSendPort) && |
| 83 (_receivePort == other._receivePort); | 83 (_receivePort == other._receivePort); |
| 84 | 84 |
| 85 int hashCode() => _receivePort._id; | 85 int hashCode() => _receivePort._id; |
| 86 } | 86 } |
| 87 | 87 |
| 88 /** A send port that delivers messages via worker.postMessage. */ | 88 /** A send port that delivers messages via worker.postMessage. */ |
| 89 // TODO(eub): abstract this for iframes. |
| 89 class _WorkerSendPort extends _BaseSendPort implements SendPort { | 90 class _WorkerSendPort extends _BaseSendPort implements SendPort { |
| 90 final int _workerId; | 91 final int _workerId; |
| 91 final int _receivePortId; | 92 final int _receivePortId; |
| 92 | 93 |
| 93 const _WorkerSendPort(this._workerId, int isolateId, this._receivePortId) | 94 const _WorkerSendPort(this._workerId, int isolateId, this._receivePortId) |
| 94 : super(isolateId); | 95 : super(isolateId); |
| 95 | 96 |
| 96 void send(var message, [SendPort replyTo = null]) { | 97 void send(var message, [SendPort replyTo = null]) { |
| 97 _waitForPendingPorts([message, replyTo], () { | 98 _waitForPendingPorts([message, replyTo], () { |
| 98 checkReplyTo(replyTo); | 99 checkReplyTo(replyTo); |
| 99 final workerMessage = _serializeMessage({ | 100 final workerMessage = _serializeMessage({ |
| 100 'command': 'message', | 101 'command': 'message', |
| 101 'port': this, | 102 'port': this, |
| 102 'msg': message, | 103 'msg': message, |
| 103 'replyTo': replyTo}); | 104 'replyTo': replyTo}); |
| 104 | 105 |
| 105 if (_globalState.isWorker) { | 106 if (_globalState.isWorker) { |
| 106 // communication from one worker to another go through the main worker: | 107 // communication from one worker to another go through the main worker: |
| 107 _globalState.mainWorker.postMessage(workerMessage); | 108 _globalState.mainManager.postMessage(workerMessage); |
| 108 } else { | 109 } else { |
| 109 _globalState.workers[_workerId].postMessage(workerMessage); | 110 _globalState.managers[_workerId].postMessage(workerMessage); |
| 110 } | 111 } |
| 111 }); | 112 }); |
| 112 } | 113 } |
| 113 | 114 |
| 114 bool operator ==(var other) { | 115 bool operator ==(var other) { |
| 115 return (other is _WorkerSendPort) && | 116 return (other is _WorkerSendPort) && |
| 116 (_workerId == other._workerId) && | 117 (_workerId == other._workerId) && |
| 117 (_isolateId == other._isolateId) && | 118 (_isolateId == other._isolateId) && |
| 118 (_receivePortId == other._receivePortId); | 119 (_receivePortId == other._receivePortId); |
| 119 } | 120 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 // map.getValues().forEach(_dispatch); | 244 // map.getValues().forEach(_dispatch); |
| 244 map.getValues().forEach((e) => _dispatch(e)); | 245 map.getValues().forEach((e) => _dispatch(e)); |
| 245 } | 246 } |
| 246 | 247 |
| 247 visitBufferingSendPort(_BufferingSendPort port) { | 248 visitBufferingSendPort(_BufferingSendPort port) { |
| 248 if (port._port == null) { | 249 if (port._port == null) { |
| 249 ports.add(port._futurePort); | 250 ports.add(port._futurePort); |
| 250 } | 251 } |
| 251 } | 252 } |
| 252 } | 253 } |
| OLD | NEW |