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 #include "vm/message_handler.h" | 5 #include "vm/message_handler.h" |
6 | 6 |
7 #include "vm/dart.h" | 7 #include "vm/dart.h" |
8 #include "vm/lockers.h" | 8 #include "vm/lockers.h" |
9 #include "vm/port.h" | 9 #include "vm/port.h" |
10 #include "vm/thread_interrupter.h" | 10 #include "vm/thread_interrupter.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 114 } |
115 | 115 |
116 saved_priority = message->priority(); | 116 saved_priority = message->priority(); |
117 if (message->IsOOB()) { | 117 if (message->IsOOB()) { |
118 oob_queue_->Enqueue(message, before_events); | 118 oob_queue_->Enqueue(message, before_events); |
119 } else { | 119 } else { |
120 queue_->Enqueue(message, before_events); | 120 queue_->Enqueue(message, before_events); |
121 } | 121 } |
122 message = NULL; // Do not access message. May have been deleted. | 122 message = NULL; // Do not access message. May have been deleted. |
123 | 123 |
124 if (pool_ != NULL && task_ == NULL) { | 124 if ((pool_ != NULL) && (task_ == NULL)) { |
125 task_ = new MessageHandlerTask(this); | 125 task_ = new MessageHandlerTask(this); |
126 pool_->Run(task_); | 126 pool_->Run(task_); |
127 } | 127 } |
128 } | 128 } |
129 // Invoke any custom message notification. | 129 // Invoke any custom message notification. |
130 MessageNotify(saved_priority); | 130 MessageNotify(saved_priority); |
131 } | 131 } |
132 | 132 |
133 | 133 |
134 Message* MessageHandler::DequeueMessage(Message::Priority min_priority) { | 134 Message* MessageHandler::DequeueMessage(Message::Priority min_priority) { |
135 // TODO(turnidge): Add assert that monitor_ is held here. | 135 // TODO(turnidge): Add assert that monitor_ is held here. |
136 Message* message = oob_queue_->Dequeue(); | 136 Message* message = oob_queue_->Dequeue(); |
137 if ((message == NULL) && (min_priority < Message::kOOBPriority)) { | 137 if ((message == NULL) && (min_priority < Message::kOOBPriority)) { |
138 message = queue_->Dequeue(); | 138 message = queue_->Dequeue(); |
139 } | 139 } |
140 return message; | 140 return message; |
141 } | 141 } |
142 | 142 |
143 | 143 |
144 bool MessageHandler::HandleMessages(bool allow_normal_messages, | 144 bool MessageHandler::HandleMessages(bool allow_normal_messages, |
145 bool allow_multiple_normal_messages) { | 145 bool allow_multiple_normal_messages) { |
146 // If isolate() returns NULL StartIsolateScope does nothing. | 146 // If isolate() returns NULL StartIsolateScope does nothing. |
147 StartIsolateScope start_isolate(isolate()); | 147 StartIsolateScope start_isolate(isolate()); |
148 | 148 |
149 // ThreadInterrupter may have gone to sleep waiting while waiting for | 149 // ThreadInterrupter may have gone to sleep while waiting for |
150 // an isolate to start handling messages. | 150 // an isolate to start handling messages. |
151 ThreadInterrupter::WakeUp(); | 151 ThreadInterrupter::WakeUp(); |
152 | 152 |
153 // TODO(turnidge): Add assert that monitor_ is held here. | 153 // TODO(turnidge): Add assert that monitor_ is held here. |
154 bool result = true; | 154 bool result = true; |
155 Message::Priority min_priority = (allow_normal_messages && !paused()) ? | 155 Message::Priority min_priority = (allow_normal_messages && !paused()) ? |
156 Message::kNormalPriority : Message::kOOBPriority; | 156 Message::kNormalPriority : Message::kOOBPriority; |
157 Message* message = DequeueMessage(min_priority); | 157 Message* message = DequeueMessage(min_priority); |
158 while (message != NULL) { | 158 while (message != NULL) { |
159 intptr_t message_len = message->len(); | 159 intptr_t message_len = message->len(); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 | 371 |
372 | 372 |
373 void MessageHandler::AcquireQueues(AcquiredQueues* acquired_queues) { | 373 void MessageHandler::AcquireQueues(AcquiredQueues* acquired_queues) { |
374 ASSERT(acquired_queues != NULL); | 374 ASSERT(acquired_queues != NULL); |
375 // No double dipping. | 375 // No double dipping. |
376 ASSERT(acquired_queues->handler_ == NULL); | 376 ASSERT(acquired_queues->handler_ == NULL); |
377 acquired_queues->Reset(this); | 377 acquired_queues->Reset(this); |
378 } | 378 } |
379 | 379 |
380 } // namespace dart | 380 } // namespace dart |
OLD | NEW |