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

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

Issue 47573002: Reland https://code.google.com/p/dart/source/detail?r=29315: (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 startup message is received through the control port.
165 */ 163 */
166 void _startIsolate(Function entryPoint, bool isSpawnUri) { 164 void _startIsolate(Function entryPoint, bool isSpawnUri) {
167 Isolate._port.first.then((message) { 165 // This port keeps the isolate alive until the initial startup message has
166 // been received.
167 var keepAlivePort = new RawReceivePort();
Ivan Posva 2013/10/27 14:33:17 This is the main change from the previously review
168
169 ignoreHandler(message) {
170 // Messages on the current Isolate's control port are dropped after the
171 // initial startup message has been received.
172 }
173
174 isolateStartHandler(message) {
175 // We received the initial startup message. Ignore all further messages and
176 // close the port which kept this isolate alive.
177 Isolate._self.handler = ignoreHandler;
178 keepAlivePort.close();
Ivan Posva 2013/10/27 14:33:17 ditto.
179
168 SendPort replyTo = message[0]; 180 SendPort replyTo = message[0];
169 // TODO(floitsch): don't send ok-message if we can't find the entry point. 181 // TODO(floitsch): don't send ok-message if we can't find the entry point.
170 replyTo.send("started"); 182 replyTo.send("started");
171 if (isSpawnUri) { 183 if (isSpawnUri) {
172 assert(message.length == 3); 184 assert(message.length == 3);
173 List<String> args = message[1]; 185 List<String> args = message[1];
174 var isolateMessage = message[2]; 186 var isolateMessage = message[2];
175 if (entryPoint is _MainFunctionArgsMessage) { 187 if (entryPoint is _MainFunctionArgsMessage) {
176 entryPoint(args, isolateMessage); 188 entryPoint(args, isolateMessage);
177 } else if (entryPoint is _MainFunctionArgs) { 189 } else if (entryPoint is _MainFunctionArgs) {
178 entryPoint(args); 190 entryPoint(args);
179 } else { 191 } else {
180 entryPoint(); 192 entryPoint();
181 } 193 }
182 } else { 194 } else {
183 assert(message.length == 2); 195 assert(message.length == 2);
184 var entryMessage = message[1]; 196 var entryMessage = message[1];
185 entryPoint(entryMessage); 197 entryPoint(entryMessage);
186 } 198 }
187 }); 199 }
200
201 Isolate._self.handler = isolateStartHandler;
188 } 202 }
189 203
190 patch class Isolate { 204 patch class Isolate {
191 /* patch */ static Future<Isolate> spawn( 205 /* patch */ static Future<Isolate> spawn(
192 void entryPoint(message), var message) { 206 void entryPoint(message), var message) {
193 Completer completer = new Completer<Isolate>.sync(); 207 Completer completer = new Completer<Isolate>.sync();
194 try { 208 try {
195 // The VM will invoke [_startIsolate] with entryPoint as argument. 209 // The VM will invoke [_startIsolate] with entryPoint as argument.
196 SendPort controlPort = _spawnFunction(entryPoint); 210 SendPort controlPort = _spawnFunction(entryPoint);
197 RawReceivePort readyPort = new RawReceivePort(); 211 RawReceivePort readyPort = new RawReceivePort();
(...skipping 23 matching lines...) Expand all
221 readyPort.close(); 235 readyPort.close();
222 completer.complete(new Isolate._fromControlPort(controlPort)); 236 completer.complete(new Isolate._fromControlPort(controlPort));
223 }; 237 };
224 } catch(e, st) { 238 } catch(e, st) {
225 // TODO(floitsch): we want errors to go into the returned future. 239 // TODO(floitsch): we want errors to go into the returned future.
226 rethrow; 240 rethrow;
227 }; 241 };
228 return completer.future; 242 return completer.future;
229 } 243 }
230 244
231 static final ReceivePort _port = 245 static final RawReceivePort _self = _mainPort;
232 new ReceivePort.fromRawReceivePort(_getPortInternal()); 246 static RawReceivePort get _mainPort native "Isolate_mainPort";
233 247
234 static SendPort _spawnFunction(Function topLevelFunction) 248 static SendPort _spawnFunction(Function topLevelFunction)
235 native "isolate_spawnFunction"; 249 native "Isolate_spawnFunction";
236 250
237 static SendPort _spawnUri(String uri) native "isolate_spawnUri"; 251 static SendPort _spawnUri(String uri) native "Isolate_spawnUri";
238 } 252 }
OLDNEW
« no previous file with comments | « runtime/lib/isolate.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | runtime/vm/debugger.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698