Files
sdk/runtime/vm/message_queue.h
T
turnidge@google.com 8920623dc5 OOB messages and general message refactor.
(1)
No longer give embedders direct access to inter-isolate messages.
Instead, keep these messages in an internal queue and rely on the
embedder only to provide notifications.  This simplifies the api in
numerous ways:

 - post message callback drops parameters and becomes message notify callback.
 - close port callback goes away
 - Dart_Message type goes away
 - Dart_HandleMessage gets a simpler signature

Updated the custom_isolate_test to show what use of the new apis looks like.

(2)
Begin to add support for out-of-band (OOB) messages.  These messages
supercede regular messages in the queue.  We will attempt to deliver
these messages even while code is running, by using the isolate
interrupt mechanism.  These messages are not user-visible.  They will
be used by the runtime internally to implement things like reflection.

Renamed PortMessage to Message.

Refactored message sending apis in PortMap and Isolate.

Modified MessageQueue to be aware of multiple priorities.

Modify Dart_HandleMessage to process multiple OOB messages
Review URL: https://chromiumcodereview.appspot.com//9182001

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@3562 260f80e4-7a28-3924-810f-c04153c831b5
2012-01-24 19:31:01 +00:00

98 lines
2.5 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 Message {
public:
typedef enum {
kNormalPriority = 0, // Deliver message when idle.
kOOBPriority = 1, // Deliver message asap.
// Iteration.
kFirstPriority = 0,
kNumPriorities = 2,
} Priority;
// A port number which is never used.
static const int kIllegalPort = 0;
// 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).
//
// If reply_port is kIllegalPort, then there is no reply port.
Message(Dart_Port dest_port, Dart_Port reply_port,
uint8_t* data, Priority priority)
: next_(NULL),
dest_port_(dest_port),
reply_port_(reply_port),
data_(data),
priority_(priority) {}
~Message() {
free(data_);
}
Dart_Port dest_port() const { return dest_port_; }
Dart_Port reply_port() const { return reply_port_; }
uint8_t* data() const { return data_; }
Priority priority() const { return priority_; }
private:
friend class MessageQueue;
Message* next_;
Dart_Port dest_port_;
Dart_Port reply_port_;
uint8_t* data_;
Priority priority_;
DISALLOW_COPY_AND_ASSIGN(Message);
};
// There is a message queue per isolate.
class MessageQueue {
public:
MessageQueue();
~MessageQueue();
void Enqueue(Message* msg);
// Gets the next message from the message queue, possibly blocking
// if no message is available. 'millis' is a timeout in
// milliseconds. If 'millis' is 0, then this means to block
// indefinitely. May block if no message is available. May return
// NULL even if 'millis' is 0 due to spurious wakeups.
Message* Dequeue(int64_t millis);
// Gets the next message from the message queue if available. Will
// not block.
Message* DequeueNoWait();
void Flush(Dart_Port port);
void FlushAll();
private:
friend class MessageQueueTestPeer;
Message* DequeueNoWaitHoldsLock();
Monitor monitor_;
Message* head_[Message::kNumPriorities];
Message* tail_[Message::kNumPriorities];
DISALLOW_COPY_AND_ASSIGN(MessageQueue);
};
} // namespace dart
#endif // VM_MESSAGE_QUEUE_H_