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 #include "vm/port.h" | |
7 #include "vm/dart.h" | 6 #include "vm/dart.h" |
8 | 7 |
9 namespace dart { | 8 namespace dart { |
10 | 9 |
11 DECLARE_FLAG(bool, trace_isolates); | 10 DECLARE_FLAG(bool, trace_isolates); |
12 | 11 |
13 | 12 |
14 class MessageHandlerTask : public ThreadPool::Task { | 13 class MessageHandlerTask : public ThreadPool::Task { |
15 public: | 14 public: |
16 explicit MessageHandlerTask(MessageHandler* handler) | 15 explicit MessageHandlerTask(MessageHandler* handler) |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 "\thandler: %s\n" | 143 "\thandler: %s\n" |
145 "\tport: %"Pd64"\n", | 144 "\tport: %"Pd64"\n", |
146 name(), message->dest_port()); | 145 name(), message->dest_port()); |
147 } | 146 } |
148 | 147 |
149 // Release the monitor_ temporarily while we handle the message. | 148 // Release the monitor_ temporarily while we handle the message. |
150 // The monitor was acquired in MessageHandler::TaskCallback(). | 149 // The monitor was acquired in MessageHandler::TaskCallback(). |
151 monitor_.Exit(); | 150 monitor_.Exit(); |
152 Message::Priority saved_priority = message->priority(); | 151 Message::Priority saved_priority = message->priority(); |
153 result = HandleMessage(message); | 152 result = HandleMessage(message); |
| 153 // ASSERT(Isolate::Current() == NULL); |
154 monitor_.Enter(); | 154 monitor_.Enter(); |
| 155 |
155 if (!result) { | 156 if (!result) { |
156 // If we hit an error, we're done processing messages. | 157 // If we hit an error, we're done processing messages. |
157 break; | 158 break; |
158 } | 159 } |
159 if (!allow_multiple_normal_messages && | 160 if (!allow_multiple_normal_messages && |
160 saved_priority == Message::kNormalPriority) { | 161 saved_priority == Message::kNormalPriority) { |
161 // Some callers want to process only one normal message and then quit. | 162 // Some callers want to process only one normal message and then quit. |
162 break; | 163 break; |
163 } | 164 } |
164 message = DequeueMessage(min_priority); | 165 message = DequeueMessage(min_priority); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 231 |
231 | 232 |
232 void MessageHandler::ClosePort(Dart_Port port) { | 233 void MessageHandler::ClosePort(Dart_Port port) { |
233 MonitorLocker ml(&monitor_); | 234 MonitorLocker ml(&monitor_); |
234 if (FLAG_trace_isolates) { | 235 if (FLAG_trace_isolates) { |
235 OS::Print("[-] Closing port:\n" | 236 OS::Print("[-] Closing port:\n" |
236 "\thandler: %s\n" | 237 "\thandler: %s\n" |
237 "\tport: %"Pd64"\n", | 238 "\tport: %"Pd64"\n", |
238 name(), port); | 239 name(), port); |
239 } | 240 } |
| 241 queue_->Flush(port); |
| 242 oob_queue_->Flush(port); |
240 } | 243 } |
241 | 244 |
242 | 245 |
243 void MessageHandler::CloseAllPorts() { | 246 void MessageHandler::CloseAllPorts() { |
244 MonitorLocker ml(&monitor_); | 247 MonitorLocker ml(&monitor_); |
245 if (FLAG_trace_isolates) { | 248 if (FLAG_trace_isolates) { |
246 OS::Print("[-] Closing all ports:\n" | 249 OS::Print("[-] Closing all ports:\n" |
247 "\thandler: %s\n", | 250 "\thandler: %s\n", |
248 name()); | 251 name()); |
249 } | 252 } |
250 queue_->Clear(); | 253 queue_->FlushAll(); |
251 oob_queue_->Clear(); | 254 oob_queue_->FlushAll(); |
252 } | 255 } |
253 | 256 |
254 | 257 |
255 void MessageHandler::increment_live_ports() { | 258 void MessageHandler::increment_live_ports() { |
256 MonitorLocker ml(&monitor_); | 259 MonitorLocker ml(&monitor_); |
257 #if defined(DEBUG) | 260 #if defined(DEBUG) |
258 CheckAccess(); | 261 CheckAccess(); |
259 #endif | 262 #endif |
260 live_ports_++; | 263 live_ports_++; |
261 } | 264 } |
262 | 265 |
263 | 266 |
264 void MessageHandler::decrement_live_ports() { | 267 void MessageHandler::decrement_live_ports() { |
265 MonitorLocker ml(&monitor_); | 268 MonitorLocker ml(&monitor_); |
266 #if defined(DEBUG) | 269 #if defined(DEBUG) |
267 CheckAccess(); | 270 CheckAccess(); |
268 #endif | 271 #endif |
269 live_ports_--; | 272 live_ports_--; |
270 } | 273 } |
271 | 274 |
272 } // namespace dart | 275 } // namespace dart |
OLD | NEW |