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 import "dart:collection" show HashMap; | 5 import "dart:collection" show HashMap; |
6 | 6 |
7 patch class ReceivePort { | 7 patch class ReceivePort { |
8 /* patch */ factory ReceivePort() = _ReceivePortImpl; | 8 /* patch */ factory ReceivePort() = _ReceivePortImpl; |
9 | 9 |
10 /* patch */ factory ReceivePort.fromRawReceivePort(RawReceivePort rawPort) = | 10 /* patch */ factory ReceivePort.fromRawReceivePort(RawReceivePort rawPort) = |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 class _RawReceivePortImpl implements RawReceivePort { | 78 class _RawReceivePortImpl implements RawReceivePort { |
79 factory _RawReceivePortImpl() native "RawReceivePortImpl_factory"; | 79 factory _RawReceivePortImpl() native "RawReceivePortImpl_factory"; |
80 | 80 |
81 close() { | 81 close() { |
82 _portMap.remove(_id); | 82 _portMap.remove(_id); |
83 _closeInternal(_id); | 83 _closeInternal(_id); |
84 } | 84 } |
85 | 85 |
86 SendPort get sendPort { | 86 SendPort get sendPort { |
87 return new _SendPortImpl(_id); | 87 return new _SendPortImpl._from(this); |
88 } | 88 } |
89 | 89 |
90 /**** Internal implementation details ****/ | 90 /**** Internal implementation details ****/ |
91 // Called from the VM to create a new RawReceivePort instance. | 91 // Called from the VM to create a new RawReceivePort instance. |
92 static _RawReceivePortImpl _get_or_create(int id) { | 92 static _RawReceivePortImpl _get(int id) { |
93 _RawReceivePortImpl port = _portMap[id]; | 93 return _portMap[id]; |
94 if (port != null) { | 94 } |
95 return port; | 95 |
96 } | 96 static _RawReceivePortImpl _create(int id) { |
| 97 assert(_portMap[id]== null); |
97 return new _RawReceivePortImpl._internal(id); | 98 return new _RawReceivePortImpl._internal(id); |
98 } | 99 } |
99 | 100 |
100 _RawReceivePortImpl._internal(int id) : _id = id { | 101 _RawReceivePortImpl._internal(int id) : _id = id { |
101 _portMap[id] = this; | 102 _portMap[id] = this; |
102 } | 103 } |
103 | 104 |
104 // Called from the VM to retrieve the RawReceivePort for a message. | 105 // Called from the VM to retrieve the RawReceivePort for a message. |
105 static _RawReceivePortImpl _lookupReceivePort(int id) { | 106 static _RawReceivePortImpl _lookupReceivePort(int id) { |
106 return _portMap[id]; | 107 return _portMap[id]; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 int hash = _id; | 151 int hash = _id; |
151 hash = (hash + ((hash & (MASK >> 10)) << 10)) & MASK; | 152 hash = (hash + ((hash & (MASK >> 10)) << 10)) & MASK; |
152 hash ^= (hash >> 6); | 153 hash ^= (hash >> 6); |
153 hash = (hash + ((hash & (MASK >> 3)) << 3)) & MASK; | 154 hash = (hash + ((hash & (MASK >> 3)) << 3)) & MASK; |
154 hash ^= (hash >> 11); | 155 hash ^= (hash >> 11); |
155 hash = (hash + ((hash & (MASK >> 15)) << 15)) & MASK; | 156 hash = (hash + ((hash & (MASK >> 15)) << 15)) & MASK; |
156 return hash; | 157 return hash; |
157 } | 158 } |
158 | 159 |
159 /*--- private implementation ---*/ | 160 /*--- private implementation ---*/ |
160 const _SendPortImpl(int id) : _id = id; | 161 _SendPortImpl._from(_RawReceivePortImpl from) : _id = from._id; |
| 162 _SendPortImpl._with(int id) : _id = id; |
161 | 163 |
162 // _SendPortImpl._create is called from the VM when a new SendPort instance is | 164 // _SendPortImpl._create is called from the VM when a new SendPort instance is |
163 // needed by the VM code. | 165 // needed by the VM code. |
164 static SendPort _create(int id) { | 166 static SendPort _create(int id) { |
165 return new _SendPortImpl(id); | 167 return new _SendPortImpl._with(id); |
166 } | 168 } |
167 | 169 |
168 // Forward the implementation of sending messages to the VM. Only port ids | 170 // Forward the implementation of sending messages to the VM. Only port ids |
169 // are being handed to the VM. | 171 // are being handed to the VM. |
170 static _sendInternal(int sendId, var message) | 172 static _sendInternal(int sendId, var message) |
171 native "SendPortImpl_sendInternal_"; | 173 native "SendPortImpl_sendInternal_"; |
172 | 174 |
173 final int _id; | 175 final int _id; |
174 } | 176 } |
175 | 177 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 native "Isolate_spawnFunction"; | 276 native "Isolate_spawnFunction"; |
275 | 277 |
276 static SendPort _spawnUri(String uri) native "Isolate_spawnUri"; | 278 static SendPort _spawnUri(String uri) native "Isolate_spawnUri"; |
277 } | 279 } |
278 | 280 |
279 patch class Capability { | 281 patch class Capability { |
280 /* patch */ factory Capability() { | 282 /* patch */ factory Capability() { |
281 throw new UnimplementedError(); | 283 throw new UnimplementedError(); |
282 } | 284 } |
283 } | 285 } |
OLD | NEW |