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

Unified Diff: frog/lib/isolate.dart

Issue 8467034: Isolates in frog - tweaks in existing js code to make things run (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: '' Created 9 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
Index: frog/lib/isolate.dart
diff --git a/frog/lib/isolate.dart b/frog/lib/isolate.dart
index ce13bf00de404592979a99b12ee2f3a0250bc026..fd52f4e7bb120a915afb15b43ee0e94ee4e6373f 100644
--- a/frog/lib/isolate.dart
+++ b/frog/lib/isolate.dart
@@ -7,11 +7,23 @@ 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);
+ if (replyTo !== null && !(replyTo is SendPortImpl)) {
+ throw "SendPort::send: Illegal replyTo type.";
Jennifer Messerly 2011/11/08 05:04:35 probably want to throw an actual exception type?
Siggi Cherem (dart-lang) 2011/11/08 17:56:42 will do - the current throw was basically copied o
+ }
+ IsolateNatives.sendMessage(_workerId, _isolateId, _receivePortId,
+ _serializeMessage(message), _serializeMessage(replyTo));
}
- void _sendNow(var message, SendPort replyTo) native;
+ // TODO(sigmund): get rid of _sendNow
Jennifer Messerly 2011/11/08 05:04:35 I think you can just remove it? I didn't see any c
Siggi Cherem (dart-lang) 2011/11/08 17:56:42 Unfortunately some other code in corelib is still
+ void _sendNow(var message, replyTo) { send(message, replyTo); }
+
+ _serializeMessage(message) {
+ if (IsolateNatives.shouldSerialize) {
+ return _IsolateJsUtil._serializeObject(message);
+ } else {
+ return _IsolateJsUtil._copyObject(message);
+ }
+ }
ReceivePortSingleShotImpl call(var message) {
final result = new ReceivePortSingleShotImpl();
@@ -21,7 +33,7 @@ class SendPortImpl implements SendPort {
ReceivePortSingleShotImpl _callNow(var message) {
final result = new ReceivePortSingleShotImpl();
- this._sendNow(message, result.toSendPort());
+ send(message, result.toSendPort());
return result;
}
@@ -71,7 +83,7 @@ class ReceivePortFactory {
class ReceivePortImpl implements ReceivePort {
ReceivePortImpl()
: _id = _nextFreeId++ {
- _register(_id);
+ IsolateNatives.registerPort(_id, this);
}
void receive(void onMessage(var message, SendPort replyTo)) {
@@ -80,7 +92,7 @@ class ReceivePortImpl implements ReceivePort {
void close() {
_callback = null;
- _unregister(_id);
+ IsolateNatives.unregisterPort(_id);
}
SendPort toSendPort() {
@@ -92,27 +104,20 @@ class ReceivePortImpl implements ReceivePort {
* existing ports.
*/
SendPort _toNewSendPort() {
- return new SendPortImpl(_currentWorkerId(), _currentIsolateId(), _id);
+ return new SendPortImpl(
+ IsolateNatives._currentWorkerId(),
+ IsolateNatives._currentIsolateId(), _id);
}
int _id;
- Function _callback = null;
+ Function _callback;
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;
}
@@ -152,7 +157,7 @@ class ReceivePortSingleShotImpl implements ReceivePort {
final String _SPAWNED_SIGNAL = "spawned";
-class IsolateNatives {
+class IsolateNatives native "IsolateNatives" {
static Future<SendPort> spawn(Isolate isolate, bool isLight) {
Completer<SendPort> completer = new Completer<SendPort>();
ReceivePort port = new ReceivePort.singleShot();
@@ -161,25 +166,42 @@ class IsolateNatives {
completer.complete(replyPort);
});
_spawn(isolate, isLight, port.toSendPort());
+ if (false) {
+ // TODO(sigmund): delete this code. This is temporarily added because we
+ // are tree-shaking methods that are only reachable from js
+ _IsolateJsUtil._startIsolate(null, null);
+ _IsolateJsUtil._deserializeMessage(null);
+ _IsolateJsUtil._print(null);
+ }
return completer.future;
}
static SendPort _spawn(Isolate isolate, bool light, SendPort port) native;
- static Function bind(Function f) native;
+
+ static bool get shouldSerialize() native;
+
+ static void sendMessage(int workerId, int isolateId, int receivePortId,
+ message, replyTo) native;
+
+ /** Registers an active receive port. */
+ static void registerPort(int id, ReceivePort port) native;
+
+ /** Unregister an inactive receive port. */
+ static void unregisterPort(int id) native;
+
+ static int _currentWorkerId() native;
+
+ static int _currentIsolateId() native;
}
-class _IsolateJsUtil {
+class _IsolateJsUtil native "_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);
}

Powered by Google App Engine
This is Rietveld 408576698