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

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
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 87
86 Message* DequeueNoWaitHoldsLock(); 88 Message* DequeueNoWaitHoldsLock();
87 89
88 Monitor monitor_; 90 Monitor monitor_;
89 Message* head_[Message::kNumPriorities]; 91 Message* head_[Message::kNumPriorities];
90 Message* tail_[Message::kNumPriorities]; 92 Message* tail_[Message::kNumPriorities];
91 93
92 DISALLOW_COPY_AND_ASSIGN(MessageQueue); 94 DISALLOW_COPY_AND_ASSIGN(MessageQueue);
93 }; 95 };
94 96
97
98 // A MessageHandler is an entity capable of accepting messages.
99 class MessageHandler {
100 protected:
101 MessageHandler();
102
103 // Allows subclasses to provide custom message notification.
104 virtual void MessageNotify(Message::Priority priority);
105
106 public:
107 virtual ~MessageHandler();
108
109 // Allow subclasses to provide a handler name.
110 virtual const char* name() const;
111
112 #if defined(DEBUG)
113 // Check that it is safe to access this message handler.
114 //
115 // For example, if this MessageHandler is an isolate, then it is
116 // only safe to access it when the MessageHandler is the current
117 // isolate.
118 virtual void CheckAccess();
119 #endif
120
121 void PostMessage(Message* message);
122 void ClosePort(Dart_Port port);
123 void CloseAllPorts();
124
125 // A message handler tracks how many live ports it has.
126 bool HasLivePorts() const { return live_ports_ > 0; }
127 void increment_live_ports() {
128 #if defined(DEBUG)
129 CheckAccess();
130 #endif
131 live_ports_++;
132 }
133 void decrement_live_ports() {
134 #if defined(DEBUG)
135 CheckAccess();
136 #endif
137 live_ports_--;
138 }
139
140 // Returns true if the handler is owned by the PortMap.
141 //
142 // This is used to delete handlers when their last live port is closed.
143 virtual bool OwnedByPortMap() const { return false; }
144
145 MessageQueue* queue() const { return queue_; }
146
147 private:
148 intptr_t live_ports_;
149 MessageQueue* queue_;
150 };
151
95 } // namespace dart 152 } // namespace dart
96 153
97 #endif // VM_MESSAGE_QUEUE_H_ 154 #endif // VM_MESSAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698