Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(501)

Side by Side Diff: runtime/lib/isolate_patch.dart

Issue 46173002: - Make sure to keep the main/control port opened until the (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 } 144 }
145 145
146 // Forward the implementation of sending messages to the VM. Only port ids 146 // Forward the implementation of sending messages to the VM. Only port ids
147 // are being handed to the VM. 147 // are being handed to the VM.
148 static _sendInternal(int sendId, int replyId, var message) 148 static _sendInternal(int sendId, int replyId, var message)
149 native "SendPortImpl_sendInternal_"; 149 native "SendPortImpl_sendInternal_";
150 150
151 final int _id; 151 final int _id;
152 } 152 }
153 153
154 _getPortInternal() native "isolate_getPortInternal";
155
156 typedef _MainFunction(); 154 typedef _MainFunction();
157 typedef _MainFunctionArgs(args); 155 typedef _MainFunctionArgs(args);
158 typedef _MainFunctionArgsMessage(args, message); 156 typedef _MainFunctionArgsMessage(args, message);
159 157
160 /** 158 /**
161 * Takes the real entry point as argument and invokes it with the initial 159 * Takes the real entry point as argument and invokes it with the initial
162 * message. 160 * message.
163 * 161 *
164 * The initial message is (currently) received through the global port variable. 162 * The initial message is received through the control port variable.
165 */ 163 */
166 void _startIsolate(Function entryPoint, bool isSpawnUri) { 164 void _startIsolate(Function entryPoint, bool isSpawnUri) {
167 Isolate._port.first.then((message) { 165 ignoreHandler(message) {
166 // Messages on the current Isolate's control port are dropped after the
167 // initial startup message has been received.
168 }
169
170 isolateStartHandler(message) {
171 // We received the initial startup message. Ignore all further messages.
172 Isolate._self.handler = ignoreHandler;
173
168 SendPort replyTo = message[0]; 174 SendPort replyTo = message[0];
169 // TODO(floitsch): don't send ok-message if we can't find the entry point. 175 // TODO(floitsch): don't send ok-message if we can't find the entry point.
170 replyTo.send("started"); 176 replyTo.send("started");
171 if (isSpawnUri) { 177 if (isSpawnUri) {
172 assert(message.length == 3); 178 assert(message.length == 3);
173 List<String> args = message[1]; 179 List<String> args = message[1];
174 var isolateMessage = message[2]; 180 var isolateMessage = message[2];
175 if (entryPoint is _MainFunctionArgsMessage) { 181 if (entryPoint is _MainFunctionArgsMessage) {
176 entryPoint(args, isolateMessage); 182 entryPoint(args, isolateMessage);
177 } else if (entryPoint is _MainFunctionArgs) { 183 } else if (entryPoint is _MainFunctionArgs) {
178 entryPoint(args); 184 entryPoint(args);
179 } else { 185 } else {
180 entryPoint(); 186 entryPoint();
181 } 187 }
182 } else { 188 } else {
183 assert(message.length == 2); 189 assert(message.length == 2);
184 var entryMessage = message[1]; 190 var entryMessage = message[1];
185 entryPoint(entryMessage); 191 entryPoint(entryMessage);
186 } 192 }
187 }); 193 }
194
195 Isolate._self.handler = isolateStartHandler;
188 } 196 }
189 197
190 patch class Isolate { 198 patch class Isolate {
191 /* patch */ static Future<Isolate> spawn( 199 /* patch */ static Future<Isolate> spawn(
192 void entryPoint(message), var message) { 200 void entryPoint(message), var message) {
193 Completer completer = new Completer<Isolate>.sync(); 201 Completer completer = new Completer<Isolate>.sync();
194 try { 202 try {
195 // The VM will invoke [_startIsolate] with entryPoint as argument. 203 // The VM will invoke [_startIsolate] with entryPoint as argument.
196 SendPort controlPort = _spawnFunction(entryPoint); 204 SendPort controlPort = _spawnFunction(entryPoint);
197 RawReceivePort readyPort = new RawReceivePort(); 205 RawReceivePort readyPort = new RawReceivePort();
(...skipping 23 matching lines...) Expand all
221 readyPort.close(); 229 readyPort.close();
222 completer.complete(new Isolate._fromControlPort(controlPort)); 230 completer.complete(new Isolate._fromControlPort(controlPort));
223 }; 231 };
224 } catch(e, st) { 232 } catch(e, st) {
225 // TODO(floitsch): we want errors to go into the returned future. 233 // TODO(floitsch): we want errors to go into the returned future.
226 rethrow; 234 rethrow;
227 }; 235 };
228 return completer.future; 236 return completer.future;
229 } 237 }
230 238
231 static final ReceivePort _port = 239 static final RawReceivePort _self = _mainPort;
232 new ReceivePort.fromRawReceivePort(_getPortInternal()); 240 static RawReceivePort get _mainPort native "Isolate_mainPort";
233 241
234 static SendPort _spawnFunction(Function topLevelFunction) 242 static SendPort _spawnFunction(Function topLevelFunction)
235 native "isolate_spawnFunction"; 243 native "Isolate_spawnFunction";
236 244
237 static SendPort _spawnUri(String uri) native "isolate_spawnUri"; 245 static SendPort _spawnUri(String uri) native "Isolate_spawnUri";
238 } 246 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698