| 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/os.h" |
| 9 #include "vm/port.h" | 10 #include "vm/port.h" |
| 10 #include "vm/thread_interrupter.h" | 11 #include "vm/thread_interrupter.h" |
| 11 | 12 |
| 13 |
| 12 namespace dart { | 14 namespace dart { |
| 13 | 15 |
| 14 DECLARE_FLAG(bool, trace_isolates); | 16 DECLARE_FLAG(bool, trace_isolates); |
| 15 DECLARE_FLAG(bool, trace_service_pause_events); | 17 DECLARE_FLAG(bool, trace_service_pause_events); |
| 16 | 18 |
| 17 class MessageHandlerTask : public ThreadPool::Task { | 19 class MessageHandlerTask : public ThreadPool::Task { |
| 18 public: | 20 public: |
| 19 explicit MessageHandlerTask(MessageHandler* handler) | 21 explicit MessageHandlerTask(MessageHandler* handler) |
| 20 : handler_(handler) { | 22 : handler_(handler) { |
| 21 ASSERT(handler != NULL); | 23 ASSERT(handler != NULL); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 35 MessageHandler::MessageHandler() | 37 MessageHandler::MessageHandler() |
| 36 : queue_(new MessageQueue()), | 38 : queue_(new MessageQueue()), |
| 37 oob_queue_(new MessageQueue()), | 39 oob_queue_(new MessageQueue()), |
| 38 oob_message_handling_allowed_(true), | 40 oob_message_handling_allowed_(true), |
| 39 live_ports_(0), | 41 live_ports_(0), |
| 40 paused_(0), | 42 paused_(0), |
| 41 pause_on_start_(false), | 43 pause_on_start_(false), |
| 42 pause_on_exit_(false), | 44 pause_on_exit_(false), |
| 43 paused_on_start_(false), | 45 paused_on_start_(false), |
| 44 paused_on_exit_(false), | 46 paused_on_exit_(false), |
| 47 paused_timestamp_(-1), |
| 45 pool_(NULL), | 48 pool_(NULL), |
| 46 task_(NULL), | 49 task_(NULL), |
| 47 start_callback_(NULL), | 50 start_callback_(NULL), |
| 48 end_callback_(NULL), | 51 end_callback_(NULL), |
| 49 callback_data_(0) { | 52 callback_data_(0) { |
| 50 ASSERT(queue_ != NULL); | 53 ASSERT(queue_ != NULL); |
| 51 ASSERT(oob_queue_ != NULL); | 54 ASSERT(oob_queue_ != NULL); |
| 52 } | 55 } |
| 53 | 56 |
| 54 | 57 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 // main() function. | 246 // main() function. |
| 244 if (pause_on_start()) { | 247 if (pause_on_start()) { |
| 245 if (!paused_on_start_) { | 248 if (!paused_on_start_) { |
| 246 // Temporarily drop the lock when calling out to NotifyPauseOnStart. | 249 // Temporarily drop the lock when calling out to NotifyPauseOnStart. |
| 247 // This avoids a dead lock that can occur when this message handler | 250 // This avoids a dead lock that can occur when this message handler |
| 248 // tries to post a message while a message is being posted to it. | 251 // tries to post a message while a message is being posted to it. |
| 249 monitor_.Exit(); | 252 monitor_.Exit(); |
| 250 NotifyPauseOnStart(); | 253 NotifyPauseOnStart(); |
| 251 monitor_.Enter(); | 254 monitor_.Enter(); |
| 252 paused_on_start_ = true; | 255 paused_on_start_ = true; |
| 256 paused_timestamp_ = OS::GetCurrentTimeMillis(); |
| 253 } | 257 } |
| 254 HandleMessages(false, false); | 258 HandleMessages(false, false); |
| 255 if (pause_on_start()) { | 259 if (pause_on_start()) { |
| 256 // Still paused. | 260 // Still paused. |
| 257 task_ = NULL; // No task in queue. | 261 task_ = NULL; // No task in queue. |
| 258 return; | 262 return; |
| 259 } else { | 263 } else { |
| 260 paused_on_start_ = false; | 264 paused_on_start_ = false; |
| 265 paused_timestamp_ = -1; |
| 261 } | 266 } |
| 262 } | 267 } |
| 263 | 268 |
| 264 if (start_callback_) { | 269 if (start_callback_) { |
| 265 // Release the monitor_ temporarily while we call the start callback. | 270 // Release the monitor_ temporarily while we call the start callback. |
| 266 // The monitor was acquired with the MonitorLocker above. | 271 // The monitor was acquired with the MonitorLocker above. |
| 267 monitor_.Exit(); | 272 monitor_.Exit(); |
| 268 ok = start_callback_(callback_data_); | 273 ok = start_callback_(callback_data_); |
| 269 ASSERT(Isolate::Current() == NULL); | 274 ASSERT(Isolate::Current() == NULL); |
| 270 start_callback_ = NULL; | 275 start_callback_ = NULL; |
| 271 monitor_.Enter(); | 276 monitor_.Enter(); |
| 272 } | 277 } |
| 273 | 278 |
| 274 // Handle any pending messages for this message handler. | 279 // Handle any pending messages for this message handler. |
| 275 if (ok) { | 280 if (ok) { |
| 276 ok = HandleMessages(true, true); | 281 ok = HandleMessages(true, true); |
| 277 } | 282 } |
| 278 task_ = NULL; // No task in queue. | 283 task_ = NULL; // No task in queue. |
| 279 | 284 |
| 280 if (!ok || !HasLivePorts()) { | 285 if (!ok || !HasLivePorts()) { |
| 281 if (pause_on_exit()) { | 286 if (pause_on_exit()) { |
| 282 if (!paused_on_exit_) { | 287 if (!paused_on_exit_) { |
| 283 if (FLAG_trace_service_pause_events) { | 288 if (FLAG_trace_service_pause_events) { |
| 284 OS::PrintErr("Isolate %s paused before exiting. " | 289 OS::PrintErr("Isolate %s paused before exiting. " |
| 285 "Use the Observatory to release it.\n", name()); | 290 "Use the Observatory to release it.\n", name()); |
| 286 } | 291 } |
| 287 notify_paused_on_exit = true; | 292 notify_paused_on_exit = true; |
| 288 paused_on_exit_ = true; | 293 paused_on_exit_ = true; |
| 294 paused_timestamp_ = OS::GetCurrentTimeMillis(); |
| 289 } | 295 } |
| 290 } else { | 296 } else { |
| 291 if (FLAG_trace_isolates) { | 297 if (FLAG_trace_isolates) { |
| 292 OS::Print("[-] Stopping message handler (%s):\n" | 298 OS::Print("[-] Stopping message handler (%s):\n" |
| 293 "\thandler: %s\n", | 299 "\thandler: %s\n", |
| 294 (ok ? "no live ports" : "error"), | 300 (ok ? "no live ports" : "error"), |
| 295 name()); | 301 name()); |
| 296 } | 302 } |
| 297 pool_ = NULL; | 303 pool_ = NULL; |
| 298 run_end_callback = true; | 304 run_end_callback = true; |
| 299 paused_on_exit_ = false; | 305 paused_on_exit_ = false; |
| 306 paused_timestamp_ = -1; |
| 300 } | 307 } |
| 301 } | 308 } |
| 302 } | 309 } |
| 303 // At this point we no longer hold the message handler lock. | 310 // At this point we no longer hold the message handler lock. |
| 304 if (notify_paused_on_exit) { | 311 if (notify_paused_on_exit) { |
| 305 NotifyPauseOnExit(); | 312 NotifyPauseOnExit(); |
| 306 } | 313 } |
| 307 if (run_end_callback && end_callback_ != NULL) { | 314 if (run_end_callback && end_callback_ != NULL) { |
| 308 end_callback_(callback_data_); | 315 end_callback_(callback_data_); |
| 309 // The handler may have been deleted after this point. | 316 // The handler may have been deleted after this point. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 | 388 |
| 382 | 389 |
| 383 void MessageHandler::AcquireQueues(AcquiredQueues* acquired_queues) { | 390 void MessageHandler::AcquireQueues(AcquiredQueues* acquired_queues) { |
| 384 ASSERT(acquired_queues != NULL); | 391 ASSERT(acquired_queues != NULL); |
| 385 // No double dipping. | 392 // No double dipping. |
| 386 ASSERT(acquired_queues->handler_ == NULL); | 393 ASSERT(acquired_queues->handler_ == NULL); |
| 387 acquired_queues->Reset(this); | 394 acquired_queues->Reset(this); |
| 388 } | 395 } |
| 389 | 396 |
| 390 } // namespace dart | 397 } // namespace dart |
| OLD | NEW |