| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |