OLD | NEW |
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_HANDLER_H_ | 5 #ifndef VM_MESSAGE_HANDLER_H_ |
6 #define VM_MESSAGE_HANDLER_H_ | 6 #define VM_MESSAGE_HANDLER_H_ |
7 | 7 |
8 #include "vm/isolate.h" | 8 #include "vm/isolate.h" |
| 9 #include "vm/lockers.h" |
9 #include "vm/message.h" | 10 #include "vm/message.h" |
10 #include "vm/os_thread.h" | 11 #include "vm/os_thread.h" |
11 #include "vm/thread_pool.h" | 12 #include "vm/thread_pool.h" |
12 | 13 |
13 namespace dart { | 14 namespace dart { |
14 | 15 |
15 // Forward declarations. | |
16 class MonitorLocker; | |
17 | |
18 // A MessageHandler is an entity capable of accepting messages. | 16 // A MessageHandler is an entity capable of accepting messages. |
19 class MessageHandler { | 17 class MessageHandler { |
20 protected: | 18 protected: |
21 MessageHandler(); | 19 MessageHandler(); |
22 | 20 |
23 public: | 21 public: |
24 enum MessageStatus { | 22 enum MessageStatus { |
25 kOK, // We successfully handled a message. | 23 kOK, // We successfully handled a message. |
26 kError, // We encountered an error handling a message. | 24 kError, // We encountered an error handling a message. |
27 kRestart, // The VM is restarting. | 25 kRestart, // The VM is restarting. |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 113 } |
116 | 114 |
117 // Timestamp of the paused on start or paused on exit. | 115 // Timestamp of the paused on start or paused on exit. |
118 int64_t paused_timestamp() const { | 116 int64_t paused_timestamp() const { |
119 return paused_timestamp_; | 117 return paused_timestamp_; |
120 } | 118 } |
121 | 119 |
122 void PausedOnStart(bool paused); | 120 void PausedOnStart(bool paused); |
123 void PausedOnExit(bool paused); | 121 void PausedOnExit(bool paused); |
124 | 122 |
| 123 // Gives temporary ownership of |queue| and |oob_queue|. Using this object |
| 124 // has the side effect that no OOB messages will be handled if a stack |
| 125 // overflow interrupt is delivered. |
125 class AcquiredQueues : public ValueObject { | 126 class AcquiredQueues : public ValueObject { |
126 public: | 127 public: |
127 AcquiredQueues(); | 128 explicit AcquiredQueues(MessageHandler* handler); |
128 | 129 |
129 ~AcquiredQueues(); | 130 ~AcquiredQueues(); |
130 | 131 |
131 MessageQueue* queue() { | 132 MessageQueue* queue() { |
132 if (handler_ == NULL) { | 133 if (handler_ == NULL) { |
133 return NULL; | 134 return NULL; |
134 } | 135 } |
135 return handler_->queue_; | 136 return handler_->queue_; |
136 } | 137 } |
137 | 138 |
138 MessageQueue* oob_queue() { | 139 MessageQueue* oob_queue() { |
139 if (handler_ == NULL) { | 140 if (handler_ == NULL) { |
140 return NULL; | 141 return NULL; |
141 } | 142 } |
142 return handler_->oob_queue_; | 143 return handler_->oob_queue_; |
143 } | 144 } |
144 | 145 |
145 private: | 146 private: |
146 void Reset(MessageHandler* handler); | |
147 | |
148 MessageHandler* handler_; | 147 MessageHandler* handler_; |
| 148 SafepointMonitorLocker ml_; |
149 | 149 |
150 friend class MessageHandler; | 150 friend class MessageHandler; |
151 }; | 151 }; |
152 | 152 |
153 // Gives temporary ownership of |queue| and |oob_queue|. Calling this | |
154 // has the side effect that no OOB messages will be handled if a stack | |
155 // overflow interrupt is delivered. | |
156 void AcquireQueues(AcquiredQueues* acquired_queue); | |
157 | |
158 #if defined(DEBUG) | 153 #if defined(DEBUG) |
159 // Check that it is safe to access this message handler. | 154 // Check that it is safe to access this message handler. |
160 // | 155 // |
161 // For example, if this MessageHandler is an isolate, then it is | 156 // For example, if this MessageHandler is an isolate, then it is |
162 // only safe to access it when the MessageHandler is the current | 157 // only safe to access it when the MessageHandler is the current |
163 // isolate. | 158 // isolate. |
164 virtual void CheckAccess(); | 159 virtual void CheckAccess(); |
165 #endif | 160 #endif |
166 | 161 |
167 protected: | 162 protected: |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 private: | 206 private: |
212 friend class PortMap; | 207 friend class PortMap; |
213 friend class MessageHandlerTestPeer; | 208 friend class MessageHandlerTestPeer; |
214 friend class MessageHandlerTask; | 209 friend class MessageHandlerTask; |
215 | 210 |
216 // Called by MessageHandlerTask to process our task queue. | 211 // Called by MessageHandlerTask to process our task queue. |
217 void TaskCallback(); | 212 void TaskCallback(); |
218 | 213 |
219 // NOTE: These two functions release and reacquire the monitor, you may | 214 // NOTE: These two functions release and reacquire the monitor, you may |
220 // need to call HandleMessages to ensure all pending messages are handled. | 215 // need to call HandleMessages to ensure all pending messages are handled. |
221 void PausedOnStartLocked(bool paused); | 216 void PausedOnStartLocked(MonitorLocker* ml, bool paused); |
222 void PausedOnExitLocked(bool paused); | 217 void PausedOnExitLocked(MonitorLocker* ml, bool paused); |
223 | 218 |
224 // Dequeue the next message. Prefer messages from the oob_queue_ to | 219 // Dequeue the next message. Prefer messages from the oob_queue_ to |
225 // messages from the queue_. | 220 // messages from the queue_. |
226 Message* DequeueMessage(Message::Priority min_priority); | 221 Message* DequeueMessage(Message::Priority min_priority); |
227 | 222 |
228 void ClearOOBQueue(); | 223 void ClearOOBQueue(); |
229 | 224 |
230 // Handles any pending messages. | 225 // Handles any pending messages. |
231 MessageStatus HandleMessages(MonitorLocker* ml, | 226 MessageStatus HandleMessages(MonitorLocker* ml, |
232 bool allow_normal_messages, | 227 bool allow_normal_messages, |
(...skipping 17 matching lines...) Expand all Loading... |
250 StartCallback start_callback_; | 245 StartCallback start_callback_; |
251 EndCallback end_callback_; | 246 EndCallback end_callback_; |
252 CallbackData callback_data_; | 247 CallbackData callback_data_; |
253 | 248 |
254 DISALLOW_COPY_AND_ASSIGN(MessageHandler); | 249 DISALLOW_COPY_AND_ASSIGN(MessageHandler); |
255 }; | 250 }; |
256 | 251 |
257 } // namespace dart | 252 } // namespace dart |
258 | 253 |
259 #endif // VM_MESSAGE_HANDLER_H_ | 254 #endif // VM_MESSAGE_HANDLER_H_ |
OLD | NEW |