| Index: runtime/vm/port.cc
|
| ===================================================================
|
| --- runtime/vm/port.cc (revision 1518)
|
| +++ runtime/vm/port.cc (working copy)
|
| @@ -90,42 +90,50 @@
|
|
|
| Dart_Port PortMap::CreatePort() {
|
| Isolate* isolate = Isolate::Current();
|
| + Dart_Port port;
|
| + {
|
| + MutexLocker ml(mutex_);
|
|
|
| - MutexLocker ml(mutex_);
|
| + Entry entry;
|
| + port = AllocatePort();
|
| + entry.port = port;
|
| + entry.isolate = isolate;
|
|
|
| - Entry entry;
|
| - entry.port = AllocatePort();
|
| - entry.isolate = isolate;
|
| + // Search for the first unused slot. Make use of the knowledge that here is
|
| + // currently no port with this id in the port map.
|
| + ASSERT(FindPort(entry.port) < 0);
|
| + intptr_t index = entry.port % capacity_;
|
| + Entry cur = map_[index];
|
| + // Stop the search at the first found unused (free or deleted) slot.
|
| + while (cur.port != 0) {
|
| + index = (index + 1) % capacity_;
|
| + cur = map_[index];
|
| + }
|
|
|
| - // Search for the first unused slot. Make use of the knowledge that here is
|
| - // currently no port with this id in the port map.
|
| - ASSERT(FindPort(entry.port) < 0);
|
| - intptr_t index = entry.port % capacity_;
|
| - Entry cur = map_[index];
|
| - // Stop the search at the first found unused (free or deleted) slot.
|
| - while (cur.port != 0) {
|
| - index = (index + 1) % capacity_;
|
| - cur = map_[index];
|
| - }
|
| + // Insert the newly created port at the index.
|
| + ASSERT(index >= 0);
|
| + ASSERT(index < capacity_);
|
| + ASSERT(map_[index].port == 0);
|
| + ASSERT((map_[index].isolate == NULL) ||
|
| + (map_[index].isolate == deleted_entry_));
|
| + if (map_[index].isolate == deleted_entry_) {
|
| + // Consuming a deleted entry.
|
| + deleted_--;
|
| + }
|
| + map_[index] = entry;
|
| + isolate->increment_active_ports();
|
|
|
| - // Insert the newly created port at the index.
|
| - ASSERT(index >= 0);
|
| - ASSERT(index < capacity_);
|
| - ASSERT(map_[index].port == 0);
|
| - ASSERT((map_[index].isolate == NULL) ||
|
| - (map_[index].isolate == deleted_entry_));
|
| - if (map_[index].isolate == deleted_entry_) {
|
| - // Consuming a deleted entry.
|
| - deleted_--;
|
| + // Increment number of used slots and grow if necessary.
|
| + used_++;
|
| + MaintainInvariants();
|
| }
|
| - map_[index] = entry;
|
| - isolate->increment_active_ports();
|
|
|
| - // Increment number of used slots and grow if necessary.
|
| - used_++;
|
| - MaintainInvariants();
|
| + // Notify the embedder that this port has been created.
|
| + Dart_CreatePortCallback callback = isolate->create_port_callback();
|
| + ASSERT(callback);
|
| + (*callback)(isolate, port);
|
|
|
| - return entry.port;
|
| + return port;
|
| }
|
|
|
|
|
| @@ -162,6 +170,9 @@
|
|
|
| void PortMap::ClosePorts() {
|
| Isolate* isolate = Isolate::Current();
|
| + if (isolate->active_ports() == 0) {
|
| + return;
|
| + }
|
| {
|
| MutexLocker ml(mutex_);
|
| for (intptr_t i = 0; i < capacity_; i++) {
|
|
|