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

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

Issue 507913003: Create isolates in a separate thread. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months 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 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 void entryPoint(message), var message, { bool paused: false }) { 249 void entryPoint(message), var message, { bool paused: false }) {
250 // `paused` isn't handled yet. 250 // `paused` isn't handled yet.
251 RawReceivePort readyPort; 251 RawReceivePort readyPort;
252 try { 252 try {
253 // The VM will invoke [_startIsolate] with entryPoint as argument. 253 // The VM will invoke [_startIsolate] with entryPoint as argument.
254 readyPort = new RawReceivePort(); 254 readyPort = new RawReceivePort();
255 _spawnFunction(readyPort.sendPort, entryPoint, message); 255 _spawnFunction(readyPort.sendPort, entryPoint, message);
256 Completer completer = new Completer<Isolate>.sync(); 256 Completer completer = new Completer<Isolate>.sync();
257 readyPort.handler = (readyMessage) { 257 readyPort.handler = (readyMessage) {
258 readyPort.close(); 258 readyPort.close();
259 assert(readyMessage is List); 259 if (readyMessage is String) {
260 assert(readyMessage.length == 2); 260 // We encountered an error starting the new isolate.
261 SendPort controlPort = readyMessage[0]; 261 completer.completeError(new IsolateSpawnException(
262 List capabilities = readyMessage[1]; 262 "Unable to spawn child isolate:\n${readyMessage}"));
263 completer.complete(new Isolate(controlPort, 263 } else {
264 pauseCapability: capabilities[0], 264 assert(readyMessage is List);
Cutch 2014/08/27 18:18:43 These asserts will only trigger in checked mode. S
turnidge 2014/08/27 19:28:59 Done. On 2014/08/27 18:18:43, Cutch wrote:
265 terminateCapability: capabilities[1])); 265 assert(readyMessage.length == 2);
266 SendPort controlPort = readyMessage[0];
267 List capabilities = readyMessage[1];
268 completer.complete(new Isolate(controlPort,
269 pauseCapability: capabilities[0],
270 terminateCapability: capabilities[1]));
271 }
266 }; 272 };
267 return completer.future; 273 return completer.future;
268 } catch (e, st) { 274 } catch (e, st) {
269 if (readyPort != null) { 275 if (readyPort != null) {
270 readyPort.close(); 276 readyPort.close();
271 } 277 }
272 return new Future<Isolate>.error(e, st); 278 return new Future<Isolate>.error(e, st);
273 }; 279 };
274 } 280 }
275 281
276 /* patch */ static Future<Isolate> spawnUri( 282 /* patch */ static Future<Isolate> spawnUri(
277 Uri uri, List<String> args, var message, { bool paused: false }) { 283 Uri uri, List<String> args, var message, { bool paused: false }) {
278 // `paused` isn't handled yet. 284 // `paused` isn't handled yet.
279 RawReceivePort readyPort; 285 RawReceivePort readyPort;
280 try { 286 try {
281 // The VM will invoke [_startIsolate] and not `main`. 287 // The VM will invoke [_startIsolate] and not `main`.
282 readyPort = new RawReceivePort(); 288 readyPort = new RawReceivePort();
283 _spawnUri(readyPort.sendPort, uri.toString(), args, message); 289 _spawnUri(readyPort.sendPort, uri.toString(), args, message);
284 Completer completer = new Completer<Isolate>.sync(); 290 Completer completer = new Completer<Isolate>.sync();
285 readyPort.handler = (readyMessage) { 291 readyPort.handler = (readyMessage) {
286 readyPort.close(); 292 readyPort.close();
287 assert(readyMessage is List); 293 if (readyMessage is String) {
288 assert(readyMessage.length == 2); 294 // We encountered an error starting the new isolate.
289 SendPort controlPort = readyMessage[0]; 295 completer.completeError(new IsolateSpawnException(
290 List capabilities = readyMessage[1]; 296 "Unable to spawn child isolate:\n${readyMessage}"));
291 completer.complete(new Isolate(controlPort, 297 } else {
292 pauseCapability: capabilities[0], 298 assert(readyMessage is List);
293 terminateCapability: capabilities[1])); 299 assert(readyMessage.length == 2);
300 SendPort controlPort = readyMessage[0];
301 List capabilities = readyMessage[1];
302 completer.complete(new Isolate(controlPort,
Cutch 2014/08/27 18:18:43 Duplicate code from above? Perhaps you can extract
turnidge 2014/08/27 19:28:59 Extracted common code into new function spawnCommo
303 pauseCapability: capabilities[0],
304 terminateCapability: capabilities[1]));
305 }
294 }; 306 };
295 return completer.future; 307 return completer.future;
296 } catch (e, st) { 308 } catch (e, st) {
297 if (readyPort != null) { 309 if (readyPort != null) {
298 readyPort.close(); 310 readyPort.close();
299 } 311 }
300 return new Future<Isolate>.error(e, st); 312 return new Future<Isolate>.error(e, st);
301 }; 313 };
302 return completer.future; 314 return completer.future;
303 } 315 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 } 369 }
358 370
359 /* patch */ void addErrorListener(SendPort port) { 371 /* patch */ void addErrorListener(SendPort port) {
360 throw new UnsupportedError("addErrorListener"); 372 throw new UnsupportedError("addErrorListener");
361 } 373 }
362 374
363 /* patch */ void removeErrorListener(SendPort port) { 375 /* patch */ void removeErrorListener(SendPort port) {
364 throw new UnsupportedError("removeErrorListener"); 376 throw new UnsupportedError("removeErrorListener");
365 } 377 }
366 } 378 }
OLDNEW
« runtime/lib/isolate.cc ('K') | « runtime/lib/isolate.cc ('k') | runtime/vm/isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698