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

Unified Diff: compiler/lib/implementation/isolate.dart

Issue 9422019: isolates refactor: this change introduces 'dart:isolate' as a library. This is a (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: '' Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « compiler/lib/corelib_impl.dart ('k') | compiler/lib/implementation/isolate.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/lib/implementation/isolate.dart
diff --git a/compiler/lib/implementation/isolate.dart b/compiler/lib/implementation/isolate.dart
deleted file mode 100644
index a3586985f3a09631d752a4b12022f15059c0048d..0000000000000000000000000000000000000000
--- a/compiler/lib/implementation/isolate.dart
+++ /dev/null
@@ -1,197 +0,0 @@
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-class SendPortImpl implements SendPort {
-
- const SendPortImpl(this._workerId, this._isolateId, this._receivePortId);
-
- void send(var message, [SendPort replyTo = null]) {
- // TODO(kasperl): get rid of _sendNow.
- this._sendNow(message, replyTo);
- }
-
- void _sendNow(var message, SendPort replyTo) native;
-
- ReceivePortSingleShotImpl call(var message) {
- final result = new ReceivePortSingleShotImpl();
- this.send(message, result.toSendPort());
- return result;
- }
-
- ReceivePortSingleShotImpl _callNow(var message) {
- final result = new ReceivePortSingleShotImpl();
- this._sendNow(message, result.toSendPort());
- return result;
- }
-
- bool operator==(var other) {
- return (other is SendPortImpl) &&
- (_workerId == other._workerId) &&
- (_isolateId == other._isolateId) &&
- (_receivePortId == other._receivePortId);
- }
-
- int hashCode() {
- return (_workerId << 16) ^ (_isolateId << 8) ^ _receivePortId;
- }
-
- final int _receivePortId;
- final int _isolateId;
- final int _workerId;
-
- static _create(int workerId, int isolateId, int receivePortId) native {
- return new SendPortImpl(workerId, isolateId, receivePortId);
- }
- static _getReceivePortId(SendPortImpl port) native {
- return port._receivePortId;
- }
- static _getIsolateId(SendPortImpl port) native {
- return port._isolateId;
- }
- static _getWorkerId(SendPortImpl port) native {
- return port._workerId;
- }
-}
-
-
-class ReceivePortFactory {
-
- factory ReceivePort() {
- return new ReceivePortImpl();
- }
-
- factory ReceivePort.singleShot() {
- return new ReceivePortSingleShotImpl();
- }
-
-}
-
-
-class ReceivePortImpl implements ReceivePort {
- ReceivePortImpl()
- : _id = _nextFreeId++ {
- _register(_id);
- }
-
- void receive(void onMessage(var message, SendPort replyTo)) {
- _callback = onMessage;
- }
-
- void close() {
- _callback = null;
- _unregister(_id);
- }
-
- SendPort toSendPort() {
- return _toNewSendPort();
- }
-
- /**
- * Returns a fresh [SendPort]. The implementation is not allowed to cache
- * existing ports.
- */
- SendPort _toNewSendPort() {
- return new SendPortImpl(_currentWorkerId(), _currentIsolateId(), _id);
- }
-
- int _id;
- Function _callback = null;
-
- static int _nextFreeId = 1;
-
- void _register(int id) native;
- void _unregister(int id) native;
-
- static int _currentWorkerId() native;
- static int _currentIsolateId() native;
-
- static void _invokeCallback(ReceivePortImpl port, message, replyTo) native {
- if (port._callback !== null) (port._callback)(message, replyTo);
- }
-
- static int _getId(ReceivePortImpl port) native {
- return port._id;
- }
- static Function _getCallback(ReceivePortImpl port) native {
- return port._callback;
- }
-}
-
-
-class ReceivePortSingleShotImpl implements ReceivePort {
-
- ReceivePortSingleShotImpl() : _port = new ReceivePortImpl() { }
-
- void receive(void callback(var message, SendPort replyTo)) {
- _port.receive((var message, SendPort replyTo) {
- _port.close();
- callback(message, replyTo);
- });
- }
-
- void close() {
- _port.close();
- }
-
- SendPort toSendPort() {
- return _toNewSendPort();
- }
-
- /**
- * Returns a fresh [SendPort]. The implementation is not allowed to cache
- * existing ports.
- */
- SendPort _toNewSendPort() {
- return _port._toNewSendPort();
- }
-
- final ReceivePortImpl _port;
-
-}
-
-final String _SPAWNED_SIGNAL = "spawned";
-
-class IsolateNatives {
- static Future<SendPort> spawn(Isolate isolate, bool isLight) {
- Completer<SendPort> result = new Completer<SendPort>();
- ReceivePort port = new ReceivePort.singleShot();
- port.receive((msg, SendPort replyPort) {
- assert(msg == _SPAWNED_SIGNAL);
- result.complete(replyPort);
- });
- _spawn(isolate, isLight, port.toSendPort());
- return result.future;
- }
-
- static SendPort _spawn(Isolate isolate, bool light, SendPort port) native;
-}
-
-
-class _IsolateJsUtil {
- static void _startIsolate(Isolate isolate, SendPort replyTo) native {
- ReceivePort port = new ReceivePort();
- replyTo.send(_SPAWNED_SIGNAL, port.toSendPort());
- isolate._run(port);
- }
-
- static SendPort _toSendPort(port) native {
- return port.toSendPort();
- }
-
- static void _print(String msg) native {
- print(msg);
- }
-
- static _copyObject(obj) native {
- return new Copier().traverse(obj);
- }
-
- static _serializeObject(obj) native {
- return new Serializer().traverse(obj);
- }
-
- static _deserializeMessage(message) native {
- return new Deserializer().deserialize(message);
- }
-}
« no previous file with comments | « compiler/lib/corelib_impl.dart ('k') | compiler/lib/implementation/isolate.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698