Files
sdk/runtime/vm/message_queue.h
T
turnidge@google.com 0e98d4ae64 Allow embedders to provide custom message delivery for an isolate.
==============

Added Dart_SetPostMessageCallback and Dart_SetClosePortCallback.
These allow the embedder to provide custom message/port behavior
for their application. The vm provides standard implementations
that work with the standard run loop.

Added Dart_HandleMessage, which processes one message on the
current isolate. Embedders can use this to write their own
message processing loops. Rewrote code to use this internally.

Added Isolate::StandardRunLoop() to share code between
Dart_RunLoop and lib/isolate.cc

Changed the interface to PortMap::PostMessage. PostMessage is
now agnostic to message delivery mechanism. Note that PortMap is
now out of the "ReceiveMessage" business entirely. Moved
MessageQueue and friends out to message_queue.cc/h.

Moved the monitor from the Isolate into the MessageQueue. No
need for outsiders to mess. Added MessageQueue::Wait. Moved
monitor locking from PortMap into MessageQueue itself, which was
easier for me to reason about. Wrote some tests.

Removed PortMessage::Handle. The code turned into Dart_HandleMessage.

Regularized the nomenclature around ports. Type is now always
Dart_Port instead of intptr_t. Variables end in _port instead of
_id. Use the term "dest" instead of "target" or "send".

Added a family of new tests to port_test.

Added EXPECT_NE to the test framework.
Review URL: http://codereview.chromium.org//8297004

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@516 260f80e4-7a28-3924-810f-c04153c831b5
2011-10-18 17:54:07 +00:00

70 lines
1.6 KiB
C++

// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// 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_MESSAGE_QUEUE_H_
#define VM_MESSAGE_QUEUE_H_
#include "include/dart_api.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(Dart_Port dest_port, Dart_Port reply_port, Dart_Message data)
: next_(NULL),
dest_port_(dest_port),
reply_port_(reply_port),
data_(data) {}
~PortMessage() {
free(data_);
}
Dart_Port dest_port() const { return dest_port_; }
Dart_Port reply_port() const { return reply_port_; }
Dart_Message data() const { return data_; }
private:
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.
class MessageQueue {
public:
MessageQueue() : head_(NULL), tail_(NULL) {}
~MessageQueue();
void Enqueue(PortMessage* msg);
// 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);
};
} // namespace dart
#endif // VM_MESSAGE_QUEUE_H_