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

Unified Diff: runtime/vm/port.cc

Issue 9169063: Add support for native ports in the vm. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Patch Set Four Rules Created 8 years, 11 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
Index: runtime/vm/port.cc
===================================================================
--- runtime/vm/port.cc (revision 3603)
+++ runtime/vm/port.cc (working copy)
@@ -7,21 +7,20 @@
#include "platform/utils.h"
#include "vm/dart_api_impl.h"
#include "vm/isolate.h"
-#include "vm/message_queue.h"
+#include "vm/message.h"
#include "vm/thread.h"
namespace dart {
DECLARE_FLAG(bool, trace_isolates);
+
siva 2012/01/28 00:21:05 extra blank line?
turnidge 2012/01/31 20:04:31 So when is it two and when is it one? Functions g
siva 2012/02/01 00:38:56 I think functions get 2 and vars get 1. On 2012/0
turnidge 2012/02/01 18:51:26 Done.
Mutex* PortMap::mutex_ = NULL;
-
PortMap::Entry* PortMap::map_ = NULL;
-Isolate* PortMap::deleted_entry_ = reinterpret_cast<Isolate*>(1);
+MessageHandler* PortMap::deleted_entry_ = reinterpret_cast<MessageHandler*>(1);
intptr_t PortMap::capacity_ = 0;
intptr_t PortMap::used_ = 0;
intptr_t PortMap::deleted_ = 0;
-
Dart_Port PortMap::next_port_ = 7111;
@@ -29,7 +28,7 @@
intptr_t index = port % capacity_;
intptr_t start_index = index;
Entry entry = map_[index];
- while (entry.isolate != NULL) {
+ while (entry.handler != NULL) {
if (entry.port == port) {
return index;
}
@@ -83,7 +82,7 @@
intptr_t index = FindPort(port);
ASSERT(index >= 0);
map_[index].live = true;
- map_[index].isolate->increment_live_ports();
+ map_[index].handler->increment_live_ports();
}
@@ -100,13 +99,13 @@
}
-Dart_Port PortMap::CreatePort() {
- Isolate* isolate = Isolate::Current();
- MutexLocker ml(mutex_);
+Dart_Port PortMap::CreatePort(MessageHandler* handler) {
+ ASSERT(handler != NULL);
siva 2012/01/28 00:21:05 #ifdef DEBUG handler->CheckAccess(); #endif
turnidge 2012/01/31 20:04:31 Done.
+ mutex_->Lock();
Entry entry;
entry.port = AllocatePort();
- entry.isolate = isolate;
+ entry.handler = handler;
entry.live = false;
// Search for the first unused slot. Make use of the knowledge that here is
@@ -124,70 +123,81 @@
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_) {
+ ASSERT((map_[index].handler == NULL) ||
+ (map_[index].handler == deleted_entry_));
+ if (map_[index].handler == deleted_entry_) {
// Consuming a deleted entry.
deleted_--;
}
map_[index] = entry;
- isolate->increment_num_ports();
// Increment number of used slots and grow if necessary.
used_++;
MaintainInvariants();
+ mutex_->Unlock();
return entry.port;
}
-void PortMap::ClosePort(Dart_Port port) {
- Isolate* isolate = Isolate::Current();
+bool PortMap::ClosePort(Dart_Port port) {
+ MessageHandler* handler = NULL;
{
- MutexLocker ml(mutex_);
+ mutex_->Lock();
intptr_t index = FindPort(port);
if (index < 0) {
- return;
+ mutex_->Unlock();
+ return false;
}
ASSERT(index < capacity_);
ASSERT(map_[index].port != 0);
- ASSERT(map_[index].isolate == isolate);
+ ASSERT(map_[index].handler != deleted_entry_);
+ ASSERT(map_[index].handler != NULL);
+
+ handler = map_[index].handler;
+#if defined(DEBUG)
+ handler->CheckAccess();
+#endif
// Before releasing the lock mark the slot in the map as deleted. This makes
// it possible to release the port map lock before flushing all of its
// pending messages below.
map_[index].port = 0;
- map_[index].isolate = deleted_entry_;
- isolate->decrement_num_ports();
+ map_[index].handler = deleted_entry_;
if (map_[index].live) {
- isolate->decrement_live_ports();
+ handler->decrement_live_ports();
}
used_--;
deleted_++;
MaintainInvariants();
+ mutex_->Unlock();
}
- isolate->ClosePort(port);
+ handler->ClosePort(port);
+ if (!handler->HasLivePorts() && handler->OwnedByPortMap()) {
+ delete handler;
+ }
+ return true;
}
-void PortMap::ClosePorts() {
- Isolate* isolate = Isolate::Current();
+void PortMap::ClosePorts(MessageHandler* handler) {
{
MutexLocker ml(mutex_);
for (intptr_t i = 0; i < capacity_; i++) {
- if (map_[i].isolate == isolate) {
+ if (map_[i].handler == handler) {
// Mark the slot as deleted.
map_[i].port = 0;
- map_[i].isolate = deleted_entry_;
- isolate->decrement_num_ports();
-
+ map_[i].handler = deleted_entry_;
+ if (map_[i].live) {
+ handler->decrement_live_ports();
+ }
used_--;
deleted_++;
}
}
MaintainInvariants();
}
- isolate->CloseAllPorts();
+ handler->CloseAllPorts();
}
@@ -204,10 +214,10 @@
}
ASSERT(index >= 0);
ASSERT(index < capacity_);
- Isolate* isolate = map_[index].isolate;
+ MessageHandler* handler = map_[index].handler;
ASSERT(map_[index].port != 0);
- ASSERT((isolate != NULL) && (isolate != deleted_entry_));
- isolate->PostMessage(message);
+ ASSERT((handler != NULL) && (handler != deleted_entry_));
+ handler->PostMessage(message);
mutex_->Unlock();
return true;
}
@@ -226,5 +236,4 @@
deleted_ = 0;
}
-
} // namespace dart

Powered by Google App Engine
This is Rietveld 408576698