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

Unified Diff: runtime/lib/isolate_patch.dart

Issue 1447353002: Start isolates in a separate thread. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: reupload Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/lib/isolate.cc ('k') | runtime/tests/vm/dart/spawn_shutdown_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/isolate_patch.dart
diff --git a/runtime/lib/isolate_patch.dart b/runtime/lib/isolate_patch.dart
index a98bb5a052f6d855e324ea0d53d6c70f1d7e4efc..bb3737159a0c5c13f52dda777906b26862bd822e 100644
--- a/runtime/lib/isolate_patch.dart
+++ b/runtime/lib/isolate_patch.dart
@@ -284,18 +284,7 @@ patch class Isolate {
readyPort = new RawReceivePort();
_spawnFunction(readyPort.sendPort, entryPoint, message,
paused, errorsAreFatal, onExit, onError);
- Completer completer = new Completer<Isolate>.sync();
- readyPort.handler = (readyMessage) {
- readyPort.close();
- assert(readyMessage is List);
- assert(readyMessage.length == 2);
- SendPort controlPort = readyMessage[0];
- List capabilities = readyMessage[1];
- completer.complete(new Isolate(controlPort,
- pauseCapability: capabilities[0],
- terminateCapability: capabilities[1]));
- };
- return completer.future;
+ return _spawnCommon(readyPort);
} catch (e, st) {
if (readyPort != null) {
readyPort.close();
@@ -328,24 +317,36 @@ patch class Isolate {
errorsAreFatal, checked,
null, /* environment */
packageRootString, packagesList);
- Completer completer = new Completer<Isolate>.sync();
- readyPort.handler = (readyMessage) {
+ return _spawnCommon(readyPort);
+ } catch (e, st) {
+ if (readyPort != null) {
readyPort.close();
- assert(readyMessage is List);
- assert(readyMessage.length == 2);
+ }
+ return new Future<Isolate>.error(e, st);
+ }
+ }
+
+ static Future<Isolate> _spawnCommon(RawReceivePort readyPort) {
+ Completer completer = new Completer<Isolate>.sync();
+ readyPort.handler = (readyMessage) {
+ readyPort.close();
+ if (readyMessage is List && readyMessage.length == 2) {
SendPort controlPort = readyMessage[0];
List capabilities = readyMessage[1];
completer.complete(new Isolate(controlPort,
pauseCapability: capabilities[0],
terminateCapability: capabilities[1]));
- };
- return completer.future;
- } catch (e, st) {
- if (readyPort != null) {
- readyPort.close();
+ } else if (readyMessage is String) {
+ // We encountered an error while starting the new isolate.
+ completer.completeError(new IsolateSpawnException(
+ 'Unable to spawn isolate: ${readyMessage}'));
+ } else {
+ // This shouldn't happen.
+ completer.completeError(new IsolateSpawnException(
+ "Internal error: unexpected format for ready message: "
+ "'${readyMessage}'"));
}
- return new Future<Isolate>.error(e, st);
- }
+ };
return completer.future;
}
« no previous file with comments | « runtime/lib/isolate.cc ('k') | runtime/tests/vm/dart/spawn_shutdown_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698