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

Side by Side Diff: runtime/vm/message.h

Issue 9169063: Add support for native ports in the vm. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/isolate.cc ('k') | runtime/vm/message.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_MESSAGE_QUEUE_H_ 5 #ifndef VM_MESSAGE_H_
6 #define VM_MESSAGE_QUEUE_H_ 6 #define VM_MESSAGE_H_
7 7
8 #include "include/dart_api.h"
9 #include "vm/thread.h" 8 #include "vm/thread.h"
10 9
10 // Duplicated from dart_api.h to avoid including the whole header.
11 typedef int64_t Dart_Port;
12
11 namespace dart { 13 namespace dart {
12 14
13 class Message { 15 class Message {
14 public: 16 public:
15 typedef enum { 17 typedef enum {
16 kNormalPriority = 0, // Deliver message when idle. 18 kNormalPriority = 0, // Deliver message when idle.
17 kOOBPriority = 1, // Deliver message asap. 19 kOOBPriority = 1, // Deliver message asap.
18 20
19 // Iteration. 21 // Iteration.
20 kFirstPriority = 0, 22 kFirstPriority = 0,
21 kNumPriorities = 2, 23 kNumPriorities = 2,
22 } Priority; 24 } Priority;
23 25
24 // A port number which is never used. 26 // A port number which is never used.
25 static const int kIllegalPort = 0; 27 static const Dart_Port kIllegalPort = 0;
26 28
27 // A new message to be sent between two isolates. The data handed to this 29 // A new message to be sent between two isolates. The data handed to this
28 // message will be disposed by calling free() once the message object is 30 // message will be disposed by calling free() once the message object is
29 // being destructed (after delivery or when the receiving port is closed). 31 // being destructed (after delivery or when the receiving port is closed).
30 // 32 //
31 // If reply_port is kIllegalPort, then there is no reply port. 33 // If reply_port is kIllegalPort, then there is no reply port.
32 Message(Dart_Port dest_port, Dart_Port reply_port, 34 Message(Dart_Port dest_port, Dart_Port reply_port,
33 uint8_t* data, Priority priority) 35 uint8_t* data, Priority priority)
34 : next_(NULL), 36 : next_(NULL),
35 dest_port_(dest_port), 37 dest_port_(dest_port),
(...skipping 14 matching lines...) Expand all
50 52
51 Message* next_; 53 Message* next_;
52 Dart_Port dest_port_; 54 Dart_Port dest_port_;
53 Dart_Port reply_port_; 55 Dart_Port reply_port_;
54 uint8_t* data_; 56 uint8_t* data_;
55 Priority priority_; 57 Priority priority_;
56 58
57 DISALLOW_COPY_AND_ASSIGN(Message); 59 DISALLOW_COPY_AND_ASSIGN(Message);
58 }; 60 };
59 61
60
61 // There is a message queue per isolate. 62 // There is a message queue per isolate.
62 class MessageQueue { 63 class MessageQueue {
63 public: 64 public:
64 MessageQueue(); 65 MessageQueue();
65 ~MessageQueue(); 66 ~MessageQueue();
66 67
67 void Enqueue(Message* msg); 68 void Enqueue(Message* msg);
68 69
69 // Gets the next message from the message queue, possibly blocking 70 // Gets the next message from the message queue, possibly blocking
70 // if no message is available. 'millis' is a timeout in 71 // if no message is available. 'millis' is a timeout in
(...skipping 14 matching lines...) Expand all
85 86
86 Message* DequeueNoWaitHoldsLock(); 87 Message* DequeueNoWaitHoldsLock();
87 88
88 Monitor monitor_; 89 Monitor monitor_;
89 Message* head_[Message::kNumPriorities]; 90 Message* head_[Message::kNumPriorities];
90 Message* tail_[Message::kNumPriorities]; 91 Message* tail_[Message::kNumPriorities];
91 92
92 DISALLOW_COPY_AND_ASSIGN(MessageQueue); 93 DISALLOW_COPY_AND_ASSIGN(MessageQueue);
93 }; 94 };
94 95
96 // A MessageHandler is an entity capable of accepting messages.
97 class MessageHandler {
98 protected:
99 MessageHandler();
100
101 // Allows subclasses to provide custom message notification.
102 virtual void MessageNotify(Message::Priority priority);
103
104 public:
105 virtual ~MessageHandler();
106
107 // Allow subclasses to provide a handler name.
108 virtual const char* name() const;
109
110 #if defined(DEBUG)
111 // Check that it is safe to access this message handler.
112 //
113 // For example, if this MessageHandler is an isolate, then it is
114 // only safe to access it when the MessageHandler is the current
115 // isolate.
116 virtual void CheckAccess();
117 #endif
118
119 void PostMessage(Message* message);
120 void ClosePort(Dart_Port port);
121 void CloseAllPorts();
122
123 // A message handler tracks how many live ports it has.
124 bool HasLivePorts() const { return live_ports_ > 0; }
125 void increment_live_ports() {
126 #if defined(DEBUG)
127 CheckAccess();
128 #endif
129 live_ports_++;
130 }
131 void decrement_live_ports() {
132 #if defined(DEBUG)
133 CheckAccess();
134 #endif
135 live_ports_--;
136 }
137
138 // Returns true if the handler is owned by the PortMap.
139 //
140 // This is used to delete handlers when their last live port is closed.
141 virtual bool OwnedByPortMap() const { return false; }
142
143 MessageQueue* queue() const { return queue_; }
144
145 private:
146 intptr_t live_ports_;
147 MessageQueue* queue_;
148 };
149
95 } // namespace dart 150 } // namespace dart
96 151
97 #endif // VM_MESSAGE_QUEUE_H_ 152 #endif // VM_MESSAGE_H_
OLDNEW
« no previous file with comments | « runtime/vm/isolate.cc ('k') | runtime/vm/message.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698