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

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

Issue 1665773004: Add necessary support functions so that embedders can implemented pause on start and exit (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
« no previous file with comments | « runtime/vm/isolate.cc ('k') | runtime/vm/message_handler.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_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/message.h" 9 #include "vm/message.h"
10 #include "vm/os_thread.h" 10 #include "vm/os_thread.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 EndCallback end_callback, 49 EndCallback end_callback,
50 CallbackData data); 50 CallbackData data);
51 51
52 // Handles the next message for this message handler. Should only 52 // Handles the next message for this message handler. Should only
53 // be used when not running the handler on the thread pool (via Run 53 // be used when not running the handler on the thread pool (via Run
54 // or RunBlocking). 54 // or RunBlocking).
55 // 55 //
56 // Returns true on success. 56 // Returns true on success.
57 MessageStatus HandleNextMessage(); 57 MessageStatus HandleNextMessage();
58 58
59 // Handles all messages for this message handler. Should only
60 // be used when not running the handler on the thread pool (via Run
61 // or RunBlocking).
62 //
63 // Returns true on success.
64 MessageStatus HandleAllMessages();
65
59 // Handles any OOB messages for this message handler. Can be used 66 // Handles any OOB messages for this message handler. Can be used
60 // even if the message handler is running on the thread pool. 67 // even if the message handler is running on the thread pool.
61 // 68 //
62 // Returns true on success. 69 // Returns true on success.
63 MessageStatus HandleOOBMessages(); 70 MessageStatus HandleOOBMessages();
64 71
65 // Returns true if there are pending OOB messages for this message 72 // Returns true if there are pending OOB messages for this message
66 // handler. 73 // handler.
67 bool HasOOBMessages(); 74 bool HasOOBMessages();
68 75
69 // A message handler tracks how many live ports it has. 76 // A message handler tracks how many live ports it has.
70 bool HasLivePorts() const { return live_ports_ > 0; } 77 bool HasLivePorts() const { return live_ports_ > 0; }
71 78
72 intptr_t live_ports() const { 79 intptr_t live_ports() const {
73 return live_ports_; 80 return live_ports_;
74 } 81 }
75 82
76 bool paused() const { return paused_ > 0; } 83 bool paused() const { return paused_ > 0; }
77 84
78 void increment_paused() { paused_++; } 85 void increment_paused() { paused_++; }
79 void decrement_paused() { ASSERT(paused_ > 0); paused_--; } 86 void decrement_paused() { ASSERT(paused_ > 0); paused_--; }
80 87
81 bool pause_on_start() const { 88 bool ShouldPauseOnStart(MessageStatus status) const;
82 return pause_on_start_; 89 bool should_pause_on_start() const {
90 return should_pause_on_start_;
83 } 91 }
84 92
85 void set_pause_on_start(bool pause_on_start) { 93 void set_should_pause_on_start(bool should_pause_on_start) {
86 pause_on_start_ = pause_on_start; 94 should_pause_on_start_ = should_pause_on_start;
87 } 95 }
88 96
89 bool paused_on_start() const { 97 bool is_paused_on_start() const {
90 // If pause_on_start_ is still set, tell the user we are paused, 98 return is_paused_on_start_;
91 // even if we haven't hit the pause point yet.
92 return paused_on_start_;
93 } 99 }
94 100
95 bool pause_on_exit() const { 101 bool ShouldPauseOnExit(MessageStatus status) const;
96 return pause_on_exit_; 102 bool should_pause_on_exit() const {
103 return should_pause_on_exit_;
97 } 104 }
98 105
99 void set_pause_on_exit(bool pause_on_exit) { 106 void set_should_pause_on_exit(bool should_pause_on_exit) {
100 pause_on_exit_ = pause_on_exit; 107 should_pause_on_exit_ = should_pause_on_exit;
101 } 108 }
102 109
103 bool paused_on_exit() const { 110 bool is_paused_on_exit() const {
104 return paused_on_exit_; 111 return is_paused_on_exit_;
105 } 112 }
106 113
107 // Timestamp of the paused on start or paused on exit. 114 // Timestamp of the paused on start or paused on exit.
108 int64_t paused_timestamp() const { 115 int64_t paused_timestamp() const {
109 return paused_timestamp_; 116 return paused_timestamp_;
110 } 117 }
111 118
119 void PausedOnStart(bool paused);
120 void PausedOnExit(bool paused);
121
112 class AcquiredQueues : public ValueObject { 122 class AcquiredQueues : public ValueObject {
113 public: 123 public:
114 AcquiredQueues(); 124 AcquiredQueues();
115 125
116 ~AcquiredQueues(); 126 ~AcquiredQueues();
117 127
118 MessageQueue* queue() { 128 MessageQueue* queue() {
119 if (handler_ == NULL) { 129 if (handler_ == NULL) {
120 return NULL; 130 return NULL;
121 } 131 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 Thread* thread() const { return Thread::Current(); } 206 Thread* thread() const { return Thread::Current(); }
197 207
198 private: 208 private:
199 friend class PortMap; 209 friend class PortMap;
200 friend class MessageHandlerTestPeer; 210 friend class MessageHandlerTestPeer;
201 friend class MessageHandlerTask; 211 friend class MessageHandlerTask;
202 212
203 // Called by MessageHandlerTask to process our task queue. 213 // Called by MessageHandlerTask to process our task queue.
204 void TaskCallback(); 214 void TaskCallback();
205 215
216 // NOTE: These two functions release and reacquire the monitor, you may
217 // need to call HandleMessages to ensure all pending messages are handled.
218 void PausedOnStartLocked(bool paused);
219 void PausedOnExitLocked(bool paused);
220
206 // Dequeue the next message. Prefer messages from the oob_queue_ to 221 // Dequeue the next message. Prefer messages from the oob_queue_ to
207 // messages from the queue_. 222 // messages from the queue_.
208 Message* DequeueMessage(Message::Priority min_priority); 223 Message* DequeueMessage(Message::Priority min_priority);
209 224
210 void ClearOOBQueue(); 225 void ClearOOBQueue();
211 226
212 // Handles any pending messages. 227 // Handles any pending messages.
213 MessageStatus HandleMessages(bool allow_normal_messages, 228 MessageStatus HandleMessages(bool allow_normal_messages,
214 bool allow_multiple_normal_messages); 229 bool allow_multiple_normal_messages);
215 230
216 Monitor monitor_; // Protects all fields in MessageHandler. 231 Monitor monitor_; // Protects all fields in MessageHandler.
217 MessageQueue* queue_; 232 MessageQueue* queue_;
218 MessageQueue* oob_queue_; 233 MessageQueue* oob_queue_;
219 // This flag is not thread safe and can only reliably be accessed on a single 234 // This flag is not thread safe and can only reliably be accessed on a single
220 // thread. 235 // thread.
221 bool oob_message_handling_allowed_; 236 bool oob_message_handling_allowed_;
222 intptr_t live_ports_; // The number of open ports, including control ports. 237 intptr_t live_ports_; // The number of open ports, including control ports.
223 intptr_t paused_; // The number of pause messages received. 238 intptr_t paused_; // The number of pause messages received.
224 bool pause_on_start_; 239 bool should_pause_on_start_;
225 bool pause_on_exit_; 240 bool should_pause_on_exit_;
226 bool paused_on_start_; 241 bool is_paused_on_start_;
227 bool paused_on_exit_; 242 bool is_paused_on_exit_;
228 int64_t paused_timestamp_; 243 int64_t paused_timestamp_;
229 ThreadPool* pool_; 244 ThreadPool* pool_;
230 ThreadPool::Task* task_; 245 ThreadPool::Task* task_;
231 StartCallback start_callback_; 246 StartCallback start_callback_;
232 EndCallback end_callback_; 247 EndCallback end_callback_;
233 CallbackData callback_data_; 248 CallbackData callback_data_;
234 249
235 DISALLOW_COPY_AND_ASSIGN(MessageHandler); 250 DISALLOW_COPY_AND_ASSIGN(MessageHandler);
236 }; 251 };
237 252
238 } // namespace dart 253 } // namespace dart
239 254
240 #endif // VM_MESSAGE_HANDLER_H_ 255 #endif // VM_MESSAGE_HANDLER_H_
OLDNEW
« no previous file with comments | « runtime/vm/isolate.cc ('k') | runtime/vm/message_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698