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

Unified Diff: runtime/vm/port.cc

Issue 8588040: Add a mid-sized integration test for the Dart Embedding Api which (Closed) Base URL: http://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: 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++) {

Powered by Google App Engine
This is Rietveld 408576698