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

Unified Diff: runtime/vm/port.h

Issue 8297004: Allow embedders to provide custom message delivery for an isolate. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 2 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
« no previous file with comments | « runtime/vm/message_queue_test.cc ('k') | runtime/vm/port.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/port.h
===================================================================
--- runtime/vm/port.h (revision 513)
+++ runtime/vm/port.h (working copy)
@@ -5,88 +5,37 @@
#ifndef VM_PORT_H_
#define VM_PORT_H_
+#include "include/dart_api.h"
#include "vm/allocation.h"
#include "vm/globals.h"
-#include "vm/growable_array.h"
-#include "vm/isolate.h"
-#include "vm/thread.h"
namespace dart {
-class PortMessage {
- public:
- // A new message to be sent between two isolates. The data handed to this
- // message will be disposed by calling free() once the message object is
- // being destructed (after delivery or when the receiving port is closed).
- PortMessage(intptr_t dest_id, intptr_t reply_id, void* data)
- : next_(NULL),
- dest_id_(dest_id),
- reply_id_(reply_id),
- data_(data) {}
- ~PortMessage() {
- free(data_);
- }
+class Isolate;
+class Mutex;
- intptr_t dest_id() const { return dest_id_; }
- intptr_t reply_id() const { return reply_id_; }
- void* data() const { return data_; }
-
- void Handle();
-
- private:
- PortMessage* next_;
- intptr_t dest_id_;
- intptr_t reply_id_;
- void* data_;
-
- friend class MessageQueue;
-
- DISALLOW_COPY_AND_ASSIGN(PortMessage);
-};
-
-
-// There is a message queue per isolate. Access to the message queue should be
-// protected by the isolate monitor.
-class MessageQueue {
- public:
- MessageQueue() : head_(NULL), tail_(NULL) {}
- ~MessageQueue();
-
- void Enqueue(PortMessage* msg);
- PortMessage* Dequeue();
-
- void Flush(intptr_t id);
- void FlushAll();
-
- private:
- PortMessage* head_;
- PortMessage* tail_;
-
- DISALLOW_COPY_AND_ASSIGN(MessageQueue);
-};
-
-
class PortMap: public AllStatic {
public:
// Allocate a port in the current isolate and return its VM-global id.
- static intptr_t CreatePort();
+ static Dart_Port CreatePort();
// Close the port with id. All pending messages will be dropped.
- static void ClosePort(intptr_t id);
+ static void ClosePort(Dart_Port id);
// Close all the ports of the current isolate.
static void ClosePorts();
- static bool IsActivePort(intptr_t id);
+ static bool IsActivePort(Dart_Port id);
// Enqueues the message in the port with id. Returns false if the port is not
// active any longer.
- static bool PostMessage(PortMessage* msg);
+ //
+ // Claims ownership of the memory pointed to by 'message' and will
+ // ensure that free(message) is called.
+ static bool PostMessage(Dart_Port dest_port,
+ Dart_Port reply_port,
+ Dart_Message message);
- // Dequeue the next message pending for this isolate. Returns null if timeout
- // was reached before a message was posted.
- static PortMessage* ReceiveMessage(int64_t millis);
-
static void InitOnce();
private:
@@ -94,14 +43,14 @@
// Free entries have id == 0 and isolate == NULL. Deleted entries have id == 0
// and isolate == deleted_entry_.
typedef struct {
- intptr_t id;
+ Dart_Port port;
Isolate* isolate;
} Entry;
- // Allocate a new unique port id.
- static intptr_t AllocateId();
+ // Allocate a new unique port.
+ static Dart_Port AllocatePort();
- static intptr_t FindId(intptr_t id);
+ static intptr_t FindPort(Dart_Port port);
static void Rehash(intptr_t new_capacity);
static void MaintainInvariants();
@@ -116,7 +65,7 @@
static intptr_t used_;
static intptr_t deleted_;
- static intptr_t next_id_;
+ static Dart_Port next_port_;
};
} // namespace dart
« no previous file with comments | « runtime/vm/message_queue_test.cc ('k') | runtime/vm/port.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698