| 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/object.h" | 9 #include "vm/object.h" |
| 10 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 } | 510 } |
| 511 | 511 |
| 512 void MessageHandler::PausedOnStart(bool paused) { | 512 void MessageHandler::PausedOnStart(bool paused) { |
| 513 MonitorLocker ml(&monitor_); | 513 MonitorLocker ml(&monitor_); |
| 514 PausedOnStartLocked(&ml, paused); | 514 PausedOnStartLocked(&ml, paused); |
| 515 } | 515 } |
| 516 | 516 |
| 517 void MessageHandler::PausedOnStartLocked(MonitorLocker* ml, bool paused) { | 517 void MessageHandler::PausedOnStartLocked(MonitorLocker* ml, bool paused) { |
| 518 if (paused) { | 518 if (paused) { |
| 519 ASSERT(!is_paused_on_start_); | 519 ASSERT(!is_paused_on_start_); |
| 520 is_paused_on_start_ = true; | 520 ASSERT(paused_timestamp_ == -1); |
| 521 paused_timestamp_ = OS::GetCurrentTimeMillis(); | 521 paused_timestamp_ = OS::GetCurrentTimeMillis(); |
| 522 } else { | |
| 523 ASSERT(is_paused_on_start_); | |
| 524 is_paused_on_start_ = false; | |
| 525 paused_timestamp_ = -1; | |
| 526 } | |
| 527 if (is_paused_on_start_) { | |
| 528 // Temporarily release the monitor when calling out to | 522 // Temporarily release the monitor when calling out to |
| 529 // NotifyPauseOnStart. This avoids a dead lock that can occur | 523 // NotifyPauseOnStart. This avoids a dead lock that can occur |
| 530 // when this message handler tries to post a message while a | 524 // when this message handler tries to post a message while a |
| 531 // message is being posted to it. | 525 // message is being posted to it. |
| 532 ml->Exit(); | 526 ml->Exit(); |
| 533 NotifyPauseOnStart(); | 527 NotifyPauseOnStart(); |
| 534 ml->Enter(); | 528 ml->Enter(); |
| 529 is_paused_on_start_ = true; |
| 535 } else { | 530 } else { |
| 531 ASSERT(is_paused_on_start_); |
| 532 ASSERT(paused_timestamp_ != -1); |
| 533 paused_timestamp_ = -1; |
| 536 // Resumed. Clear the resume request of the owning isolate. | 534 // Resumed. Clear the resume request of the owning isolate. |
| 537 Isolate* owning_isolate = isolate(); | 535 Isolate* owning_isolate = isolate(); |
| 538 if (owning_isolate != NULL) { | 536 if (owning_isolate != NULL) { |
| 539 owning_isolate->GetAndClearResumeRequest(); | 537 owning_isolate->GetAndClearResumeRequest(); |
| 540 } | 538 } |
| 539 is_paused_on_start_ = false; |
| 541 } | 540 } |
| 542 } | 541 } |
| 543 | 542 |
| 544 void MessageHandler::PausedOnExit(bool paused) { | 543 void MessageHandler::PausedOnExit(bool paused) { |
| 545 MonitorLocker ml(&monitor_); | 544 MonitorLocker ml(&monitor_); |
| 546 PausedOnExitLocked(&ml, paused); | 545 PausedOnExitLocked(&ml, paused); |
| 547 } | 546 } |
| 548 | 547 |
| 549 void MessageHandler::PausedOnExitLocked(MonitorLocker* ml, bool paused) { | 548 void MessageHandler::PausedOnExitLocked(MonitorLocker* ml, bool paused) { |
| 550 if (paused) { | 549 if (paused) { |
| 551 ASSERT(!is_paused_on_exit_); | 550 ASSERT(!is_paused_on_exit_); |
| 552 is_paused_on_exit_ = true; | 551 ASSERT(paused_timestamp_ == -1); |
| 553 paused_timestamp_ = OS::GetCurrentTimeMillis(); | 552 paused_timestamp_ = OS::GetCurrentTimeMillis(); |
| 554 } else { | |
| 555 ASSERT(is_paused_on_exit_); | |
| 556 is_paused_on_exit_ = false; | |
| 557 paused_timestamp_ = -1; | |
| 558 } | |
| 559 if (is_paused_on_exit_) { | |
| 560 // Temporarily release the monitor when calling out to | 553 // Temporarily release the monitor when calling out to |
| 561 // NotifyPauseOnExit. This avoids a dead lock that can | 554 // NotifyPauseOnExit. This avoids a dead lock that can |
| 562 // occur when this message handler tries to post a message | 555 // occur when this message handler tries to post a message |
| 563 // while a message is being posted to it. | 556 // while a message is being posted to it. |
| 564 ml->Exit(); | 557 ml->Exit(); |
| 565 NotifyPauseOnExit(); | 558 NotifyPauseOnExit(); |
| 566 ml->Enter(); | 559 ml->Enter(); |
| 560 is_paused_on_exit_ = true; |
| 567 } else { | 561 } else { |
| 562 ASSERT(is_paused_on_exit_); |
| 563 ASSERT(paused_timestamp_ != -1); |
| 564 paused_timestamp_ = -1; |
| 568 // Resumed. Clear the resume request of the owning isolate. | 565 // Resumed. Clear the resume request of the owning isolate. |
| 569 Isolate* owning_isolate = isolate(); | 566 Isolate* owning_isolate = isolate(); |
| 570 if (owning_isolate != NULL) { | 567 if (owning_isolate != NULL) { |
| 571 owning_isolate->GetAndClearResumeRequest(); | 568 owning_isolate->GetAndClearResumeRequest(); |
| 572 } | 569 } |
| 570 is_paused_on_exit_ = false; |
| 573 } | 571 } |
| 574 } | 572 } |
| 575 #endif // !defined(PRODUCT) | 573 #endif // !defined(PRODUCT) |
| 576 | 574 |
| 577 MessageHandler::AcquiredQueues::AcquiredQueues(MessageHandler* handler) | 575 MessageHandler::AcquiredQueues::AcquiredQueues(MessageHandler* handler) |
| 578 : handler_(handler), ml_(&handler->monitor_) { | 576 : handler_(handler), ml_(&handler->monitor_) { |
| 579 ASSERT(handler != NULL); | 577 ASSERT(handler != NULL); |
| 580 handler_->oob_message_handling_allowed_ = false; | 578 handler_->oob_message_handling_allowed_ = false; |
| 581 } | 579 } |
| 582 | 580 |
| 583 MessageHandler::AcquiredQueues::~AcquiredQueues() { | 581 MessageHandler::AcquiredQueues::~AcquiredQueues() { |
| 584 ASSERT(handler_ != NULL); | 582 ASSERT(handler_ != NULL); |
| 585 handler_->oob_message_handling_allowed_ = true; | 583 handler_->oob_message_handling_allowed_ = true; |
| 586 } | 584 } |
| 587 | 585 |
| 588 } // namespace dart | 586 } // namespace dart |
| OLD | NEW |