mirror of
https://github.com/dart-lang/sdk
synced 2024-09-04 16:03:44 +00:00
Make sure we send fresh Sendports to other Isolates.
For now I prefer not to share *any* data between two different isolates. We can relax this later. Review URL: https://chromereviews.googleplex.com/3522014 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@33 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
b87f38077c
commit
ea24bda4b2
|
@ -93,6 +93,14 @@ class ReceivePortImpl implements ReceivePort {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -122,24 +130,32 @@ class ReceivePortImpl implements ReceivePort {
|
|||
|
||||
class ReceivePortSingleShotImpl implements ReceivePort {
|
||||
|
||||
ReceivePortSingleShotImpl() : port_ = new ReceivePortImpl() { }
|
||||
ReceivePortSingleShotImpl() : _port = new ReceivePortImpl() { }
|
||||
|
||||
void receive(void callback(var message, SendPort replyTo)) {
|
||||
port_.receive((var message, SendPort replyTo) {
|
||||
port_.close();
|
||||
_port.receive((var message, SendPort replyTo) {
|
||||
_port.close();
|
||||
callback(message, replyTo);
|
||||
});
|
||||
}
|
||||
|
||||
void close() {
|
||||
port_.close();
|
||||
_port.close();
|
||||
}
|
||||
|
||||
SendPort toSendPort() {
|
||||
return port_.toSendPort();
|
||||
return _toNewSendPort();
|
||||
}
|
||||
|
||||
final ReceivePortImpl port_;
|
||||
/**
|
||||
* Returns a fresh [SendPort]. The implementation is not allowed to cache
|
||||
* existing ports.
|
||||
*/
|
||||
SendPort _toNewSendPort() {
|
||||
return _port._toNewSendPort();
|
||||
}
|
||||
|
||||
final ReceivePortImpl _port;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -96,20 +96,17 @@ class Copier extends MessageTraverser {
|
|||
}
|
||||
|
||||
SendPort visitSendPort(SendPortImpl port) {
|
||||
// No need to copy the sendport.
|
||||
return port;
|
||||
return new SendPortImpl(port._workerId,
|
||||
port._isolateId,
|
||||
port._receivePortId);
|
||||
}
|
||||
|
||||
SendPort visitReceivePort(ReceivePortImpl port) {
|
||||
// TODO(floitsch): should we instead call toFreshSendPort? to be certain
|
||||
// that objects are not shared.
|
||||
return port.toSendPort();
|
||||
return port._toNewSendPort();
|
||||
}
|
||||
|
||||
SendPort visitReceivePortSingleShot(ReceivePortSingleShotImpl port) {
|
||||
// TODO(floitsch): should we instead call toFreshSendPort? to be certain
|
||||
// that objects are not shared.
|
||||
return port.toSendPort();
|
||||
return port._toNewSendPort();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue