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