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 patch class ReceivePort { | 5 patch class ReceivePort { |
6 /* patch */ factory ReceivePort() = _ReceivePortImpl; | 6 /* patch */ factory ReceivePort() = _ReceivePortImpl; |
7 | 7 |
8 /* patch */ factory ReceivePort.fromRawReceivePort(RawReceivePort rawPort) = | 8 /* patch */ factory ReceivePort.fromRawReceivePort(RawReceivePort rawPort) = |
9 _ReceivePortImpl.fromRawReceivePort; | 9 _ReceivePortImpl.fromRawReceivePort; |
10 } | 10 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 final int _id; | 103 final int _id; |
104 Function _handler; | 104 Function _handler; |
105 | 105 |
106 // id to RawReceivePort mapping. | 106 // id to RawReceivePort mapping. |
107 static final Map _portMap = new HashMap(); | 107 static final Map _portMap = new HashMap(); |
108 } | 108 } |
109 | 109 |
110 | 110 |
111 class _SendPortImpl implements SendPort { | 111 class _SendPortImpl implements SendPort { |
112 /*--- public interface ---*/ | 112 /*--- public interface ---*/ |
113 void send(var message, [SendPort replyTo = null]) { | 113 void send(var message) { |
114 this._sendNow(message, replyTo); | 114 _sendInternal(_id, 0, message); |
115 } | |
116 | |
117 void _sendNow(var message, SendPort replyTo) { | |
118 int replyId = (replyTo == null) ? 0 : replyTo._id; | |
119 _sendInternal(_id, replyId, message); | |
120 } | 115 } |
121 | 116 |
122 bool operator==(var other) { | 117 bool operator==(var other) { |
123 return (other is _SendPortImpl) && _id == other._id; | 118 return (other is _SendPortImpl) && _id == other._id; |
124 } | 119 } |
125 | 120 |
126 int get hashCode { | 121 int get hashCode { |
127 const int MASK = 0x3FFFFFFF; | 122 const int MASK = 0x3FFFFFFF; |
128 int hash = _id; | 123 int hash = _id; |
129 hash = (hash + ((hash & (MASK >> 10)) << 10)) & MASK; | 124 hash = (hash + ((hash & (MASK >> 10)) << 10)) & MASK; |
130 hash ^= (hash >> 6); | 125 hash ^= (hash >> 6); |
131 hash = (hash + ((hash & (MASK >> 3)) << 3)) & MASK; | 126 hash = (hash + ((hash & (MASK >> 3)) << 3)) & MASK; |
132 hash ^= (hash >> 11); | 127 hash ^= (hash >> 11); |
133 hash = (hash + ((hash & (MASK >> 15)) << 15)) & MASK; | 128 hash = (hash + ((hash & (MASK >> 15)) << 15)) & MASK; |
134 return hash; | 129 return hash; |
135 } | 130 } |
136 | 131 |
137 /*--- private implementation ---*/ | 132 /*--- private implementation ---*/ |
138 const _SendPortImpl(int id) : _id = id; | 133 const _SendPortImpl(int id) : _id = id; |
139 | 134 |
140 // _SendPortImpl._create is called from the VM when a new SendPort instance is | 135 // _SendPortImpl._create is called from the VM when a new SendPort instance is |
141 // needed by the VM code. | 136 // needed by the VM code. |
142 static SendPort _create(int id) { | 137 static SendPort _create(int id) { |
143 return new _SendPortImpl(id); | 138 return new _SendPortImpl(id); |
144 } | 139 } |
145 | 140 |
146 // Forward the implementation of sending messages to the VM. Only port ids | 141 // Forward the implementation of sending messages to the VM. Only port ids |
147 // are being handed to the VM. | 142 // are being handed to the VM. |
| 143 // TODO(14731): Remove replyId argument. |
148 static _sendInternal(int sendId, int replyId, var message) | 144 static _sendInternal(int sendId, int replyId, var message) |
149 native "SendPortImpl_sendInternal_"; | 145 native "SendPortImpl_sendInternal_"; |
150 | 146 |
151 final int _id; | 147 final int _id; |
152 } | 148 } |
153 | 149 |
154 typedef _MainFunction(); | 150 typedef _MainFunction(); |
155 typedef _MainFunctionArgs(args); | 151 typedef _MainFunctionArgs(args); |
156 typedef _MainFunctionArgsMessage(args, message); | 152 typedef _MainFunctionArgsMessage(args, message); |
157 | 153 |
(...skipping 13 matching lines...) Expand all Loading... |
171 // initial startup message has been received. | 167 // initial startup message has been received. |
172 } | 168 } |
173 | 169 |
174 isolateStartHandler(message) { | 170 isolateStartHandler(message) { |
175 // We received the initial startup message. Ignore all further messages and | 171 // We received the initial startup message. Ignore all further messages and |
176 // close the port which kept this isolate alive. | 172 // close the port which kept this isolate alive. |
177 Isolate._self.handler = ignoreHandler; | 173 Isolate._self.handler = ignoreHandler; |
178 keepAlivePort.close(); | 174 keepAlivePort.close(); |
179 | 175 |
180 SendPort replyTo = message[0]; | 176 SendPort replyTo = message[0]; |
181 // TODO(floitsch): don't send ok-message if we can't find the entry point. | 177 if (replyTo != null) { |
182 replyTo.send("started"); | 178 // TODO(floitsch): don't send ok-message if we can't find the entry point. |
| 179 replyTo.send("started"); |
| 180 } |
183 if (isSpawnUri) { | 181 if (isSpawnUri) { |
184 assert(message.length == 3); | 182 assert(message.length == 3); |
185 List<String> args = message[1]; | 183 List<String> args = message[1]; |
186 var isolateMessage = message[2]; | 184 var isolateMessage = message[2]; |
187 if (entryPoint is _MainFunctionArgsMessage) { | 185 if (entryPoint is _MainFunctionArgsMessage) { |
188 entryPoint(args, isolateMessage); | 186 entryPoint(args, isolateMessage); |
189 } else if (entryPoint is _MainFunctionArgs) { | 187 } else if (entryPoint is _MainFunctionArgs) { |
190 entryPoint(args); | 188 entryPoint(args); |
191 } else { | 189 } else { |
192 entryPoint(); | 190 entryPoint(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 } | 241 } |
244 | 242 |
245 static final RawReceivePort _self = _mainPort; | 243 static final RawReceivePort _self = _mainPort; |
246 static RawReceivePort get _mainPort native "Isolate_mainPort"; | 244 static RawReceivePort get _mainPort native "Isolate_mainPort"; |
247 | 245 |
248 static SendPort _spawnFunction(Function topLevelFunction) | 246 static SendPort _spawnFunction(Function topLevelFunction) |
249 native "Isolate_spawnFunction"; | 247 native "Isolate_spawnFunction"; |
250 | 248 |
251 static SendPort _spawnUri(String uri) native "Isolate_spawnUri"; | 249 static SendPort _spawnUri(String uri) native "Isolate_spawnUri"; |
252 } | 250 } |
OLD | NEW |