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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 Function _handler; | 106 Function _handler; |
107 | 107 |
108 // id to RawReceivePort mapping. | 108 // id to RawReceivePort mapping. |
109 static final Map _portMap = new HashMap(); | 109 static final Map _portMap = new HashMap(); |
110 } | 110 } |
111 | 111 |
112 | 112 |
113 class _SendPortImpl implements SendPort { | 113 class _SendPortImpl implements SendPort { |
114 /*--- public interface ---*/ | 114 /*--- public interface ---*/ |
115 void send(var message) { | 115 void send(var message) { |
116 _sendInternal(_id, 0, message); | 116 _sendInternal(_id, message); |
117 } | 117 } |
118 | 118 |
119 bool operator==(var other) { | 119 bool operator==(var other) { |
120 return (other is _SendPortImpl) && _id == other._id; | 120 return (other is _SendPortImpl) && _id == other._id; |
121 } | 121 } |
122 | 122 |
123 int get hashCode { | 123 int get hashCode { |
124 const int MASK = 0x3FFFFFFF; | 124 const int MASK = 0x3FFFFFFF; |
125 int hash = _id; | 125 int hash = _id; |
126 hash = (hash + ((hash & (MASK >> 10)) << 10)) & MASK; | 126 hash = (hash + ((hash & (MASK >> 10)) << 10)) & MASK; |
127 hash ^= (hash >> 6); | 127 hash ^= (hash >> 6); |
128 hash = (hash + ((hash & (MASK >> 3)) << 3)) & MASK; | 128 hash = (hash + ((hash & (MASK >> 3)) << 3)) & MASK; |
129 hash ^= (hash >> 11); | 129 hash ^= (hash >> 11); |
130 hash = (hash + ((hash & (MASK >> 15)) << 15)) & MASK; | 130 hash = (hash + ((hash & (MASK >> 15)) << 15)) & MASK; |
131 return hash; | 131 return hash; |
132 } | 132 } |
133 | 133 |
134 /*--- private implementation ---*/ | 134 /*--- private implementation ---*/ |
135 const _SendPortImpl(int id) : _id = id; | 135 const _SendPortImpl(int id) : _id = id; |
136 | 136 |
137 // _SendPortImpl._create is called from the VM when a new SendPort instance is | 137 // _SendPortImpl._create is called from the VM when a new SendPort instance is |
138 // needed by the VM code. | 138 // needed by the VM code. |
139 static SendPort _create(int id) { | 139 static SendPort _create(int id) { |
140 return new _SendPortImpl(id); | 140 return new _SendPortImpl(id); |
141 } | 141 } |
142 | 142 |
143 // Forward the implementation of sending messages to the VM. Only port ids | 143 // Forward the implementation of sending messages to the VM. Only port ids |
144 // are being handed to the VM. | 144 // are being handed to the VM. |
145 // TODO(14731): Remove replyId argument. | 145 static _sendInternal(int sendId, var message) |
146 static _sendInternal(int sendId, int replyId, var message) | |
147 native "SendPortImpl_sendInternal_"; | 146 native "SendPortImpl_sendInternal_"; |
148 | 147 |
149 final int _id; | 148 final int _id; |
150 } | 149 } |
151 | 150 |
152 typedef _MainFunction(); | 151 typedef _MainFunction(); |
153 typedef _MainFunctionArgs(args); | 152 typedef _MainFunctionArgs(args); |
154 typedef _MainFunctionArgsMessage(args, message); | 153 typedef _MainFunctionArgsMessage(args, message); |
155 | 154 |
156 /** | 155 /** |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 } | 242 } |
244 | 243 |
245 static final RawReceivePort _self = _mainPort; | 244 static final RawReceivePort _self = _mainPort; |
246 static RawReceivePort get _mainPort native "Isolate_mainPort"; | 245 static RawReceivePort get _mainPort native "Isolate_mainPort"; |
247 | 246 |
248 static SendPort _spawnFunction(Function topLevelFunction) | 247 static SendPort _spawnFunction(Function topLevelFunction) |
249 native "Isolate_spawnFunction"; | 248 native "Isolate_spawnFunction"; |
250 | 249 |
251 static SendPort _spawnUri(String uri) native "Isolate_spawnUri"; | 250 static SendPort _spawnUri(String uri) native "Isolate_spawnUri"; |
252 } | 251 } |
OLD | NEW |