| 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 library MandelIsolateTest; | 5 library MandelIsolateTest; |
| 6 import 'dart:isolate'; | 6 import 'dart:isolate'; |
| 7 import 'dart:math'; | 7 import 'dart:math'; |
| 8 import '../../pkg/unittest/lib/unittest.dart'; | 8 import '../../pkg/unittest/lib/unittest.dart'; |
| 9 | 9 |
| 10 const TERMINATION_MESSAGE = -1; | 10 const TERMINATION_MESSAGE = -1; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 _validated = new Completer<bool>(); | 32 _validated = new Completer<bool>(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void startClient(int id) { | 35 void startClient(int id) { |
| 36 assert(_sent < N); | 36 assert(_sent < N); |
| 37 final client = new LineProcessorClient(this, id); | 37 final client = new LineProcessorClient(this, id); |
| 38 client.processLine(_sent++); | 38 client.processLine(_sent++); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void notifyProcessedLine(LineProcessorClient client, int y, List<int> line) { | 41 void notifyProcessedLine(LineProcessorClient client, int y, List<int> line) { |
| 42 assert(_result[y] === null); | 42 assert(_result[y] == null); |
| 43 _result[y] = line; | 43 _result[y] = line; |
| 44 _lineProcessedBy[y] = client; | 44 _lineProcessedBy[y] = client; |
| 45 | 45 |
| 46 if (_sent != N) { | 46 if (_sent != N) { |
| 47 client.processLine(_sent++); | 47 client.processLine(_sent++); |
| 48 } else { | 48 } else { |
| 49 client.shutdown(); | 49 client.shutdown(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 // If all lines have been computed, validate the result. | 52 // If all lines have been computed, validate the result. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 void processLines() { | 133 void processLines() { |
| 134 port.receive((message, SendPort replyTo) { | 134 port.receive((message, SendPort replyTo) { |
| 135 if (message == TERMINATION_MESSAGE) { | 135 if (message == TERMINATION_MESSAGE) { |
| 136 assert(replyTo == null); | 136 assert(replyTo == null); |
| 137 port.close(); | 137 port.close(); |
| 138 } else { | 138 } else { |
| 139 replyTo.send(processLine(message), null); | 139 replyTo.send(processLine(message), null); |
| 140 } | 140 } |
| 141 }); | 141 }); |
| 142 } | 142 } |
| OLD | NEW |