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

Unified Diff: runtime/vm/message_queue.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/isolate.cc ('k') | runtime/vm/message_queue.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/message_queue.h
===================================================================
--- runtime/vm/message_queue.h (revision 446)
+++ runtime/vm/message_queue.h (working copy)
@@ -2,13 +2,10 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-#ifndef VM_PORT_H_
-#define VM_PORT_H_
+#ifndef VM_MESSAGE_QUEUE_H_
+#define VM_MESSAGE_QUEUE_H_
-#include "vm/allocation.h"
-#include "vm/globals.h"
-#include "vm/growable_array.h"
-#include "vm/isolate.h"
+#include "include/dart_api.h"
#include "vm/thread.h"
namespace dart {
@@ -18,107 +15,55 @@
// 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)
+ PortMessage(Dart_Port dest_port, Dart_Port reply_port, Dart_Message data)
: next_(NULL),
- dest_id_(dest_id),
- reply_id_(reply_id),
+ dest_port_(dest_port),
+ reply_port_(reply_port),
data_(data) {}
~PortMessage() {
free(data_);
}
- intptr_t dest_id() const { return dest_id_; }
- intptr_t reply_id() const { return reply_id_; }
- void* data() const { return data_; }
+ Dart_Port dest_port() const { return dest_port_; }
+ Dart_Port reply_port() const { return reply_port_; }
+ Dart_Message data() const { return data_; }
- void Handle();
-
private:
- PortMessage* next_;
- intptr_t dest_id_;
- intptr_t reply_id_;
- void* data_;
-
friend class MessageQueue;
+ PortMessage* next_;
+ Dart_Port dest_port_;
+ Dart_Port reply_port_;
+ Dart_Message data_;
+
DISALLOW_COPY_AND_ASSIGN(PortMessage);
};
-// There is a message queue per isolate. Access to the message queue should be
-// protected by the isolate monitor.
+// There is a message queue per isolate.
class MessageQueue {
public:
MessageQueue() : head_(NULL), tail_(NULL) {}
~MessageQueue();
void Enqueue(PortMessage* msg);
- PortMessage* Dequeue();
- void Flush(intptr_t id);
+ // May block if no message is available.
+ PortMessage* Dequeue(int64_t millis);
+
+ void Flush(Dart_Port port);
void FlushAll();
private:
+ friend class MessageQueueTestPeer;
+
+ Monitor monitor_;
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();
-
- // Close the port with id. All pending messages will be dropped.
- static void ClosePort(intptr_t id);
-
- // Close all the ports of the current isolate.
- static void ClosePorts();
-
- static bool IsActivePort(intptr_t id);
-
- // Enqueues the message in the port with id. Returns false if the port is not
- // active any longer.
- static bool PostMessage(PortMessage* msg);
-
- // 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:
- // Mapping between port numbers and isolates.
- // Free entries have id == 0 and isolate == NULL. Deleted entries have id == 0
- // and isolate == deleted_entry_.
- typedef struct {
- intptr_t id;
- Isolate* isolate;
- } Entry;
-
- // Allocate a new unique port id.
- static intptr_t AllocateId();
-
- static intptr_t FindId(intptr_t id);
- static void Rehash(intptr_t new_capacity);
-
- static void MaintainInvariants();
-
- // Lock protecting access to the port map.
- static Mutex* mutex_;
-
- // Hashmap of ports.
- static Entry* map_;
- static Isolate* deleted_entry_;
- static intptr_t capacity_;
- static intptr_t used_;
- static intptr_t deleted_;
-
- static intptr_t next_id_;
-};
-
} // namespace dart
-#endif // VM_PORT_H_
+#endif // VM_MESSAGE_QUEUE_H_
« no previous file with comments | « runtime/vm/isolate.cc ('k') | runtime/vm/message_queue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698