mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 23:19:47 +00:00
[vm] Replace MessageHandler::task_ with task_running_
MessageHandler doesn't actually need a reference to the ThreadPool::Task, it just wants to know if one is running or not. Replacing it with a simple boolean will simplify switching ThreadPool::Task to use std::unique_ptr. Updates #37244. Change-Id: Ie69ec38523f009ba559678fd544efa4cc8ead7dd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106008 Reviewed-by: Régis Crelier <regis@google.com> Commit-Queue: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
8be1d13af7
commit
8fc98147e6
|
@ -64,9 +64,9 @@ MessageHandler::MessageHandler()
|
||||||
is_paused_on_exit_(false),
|
is_paused_on_exit_(false),
|
||||||
paused_timestamp_(-1),
|
paused_timestamp_(-1),
|
||||||
#endif
|
#endif
|
||||||
|
task_running_(false),
|
||||||
delete_me_(false),
|
delete_me_(false),
|
||||||
pool_(NULL),
|
pool_(NULL),
|
||||||
task_(NULL),
|
|
||||||
idle_start_time_(0),
|
idle_start_time_(0),
|
||||||
start_callback_(NULL),
|
start_callback_(NULL),
|
||||||
end_callback_(NULL),
|
end_callback_(NULL),
|
||||||
|
@ -81,7 +81,6 @@ MessageHandler::~MessageHandler() {
|
||||||
queue_ = NULL;
|
queue_ = NULL;
|
||||||
oob_queue_ = NULL;
|
oob_queue_ = NULL;
|
||||||
pool_ = NULL;
|
pool_ = NULL;
|
||||||
task_ = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* MessageHandler::name() const {
|
const char* MessageHandler::name() const {
|
||||||
|
@ -102,7 +101,6 @@ void MessageHandler::Run(ThreadPool* pool,
|
||||||
StartCallback start_callback,
|
StartCallback start_callback,
|
||||||
EndCallback end_callback,
|
EndCallback end_callback,
|
||||||
CallbackData data) {
|
CallbackData data) {
|
||||||
bool task_running;
|
|
||||||
MonitorLocker ml(&monitor_);
|
MonitorLocker ml(&monitor_);
|
||||||
if (FLAG_trace_isolates) {
|
if (FLAG_trace_isolates) {
|
||||||
OS::PrintErr(
|
OS::PrintErr(
|
||||||
|
@ -116,15 +114,14 @@ void MessageHandler::Run(ThreadPool* pool,
|
||||||
start_callback_ = start_callback;
|
start_callback_ = start_callback;
|
||||||
end_callback_ = end_callback;
|
end_callback_ = end_callback;
|
||||||
callback_data_ = data;
|
callback_data_ = data;
|
||||||
task_ = new MessageHandlerTask(this);
|
task_running_ = pool_->Run(new MessageHandlerTask(this));
|
||||||
task_running = pool_->Run(task_);
|
ASSERT(task_running_);
|
||||||
ASSERT(task_running);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageHandler::PostMessage(std::unique_ptr<Message> message,
|
void MessageHandler::PostMessage(std::unique_ptr<Message> message,
|
||||||
bool before_events) {
|
bool before_events) {
|
||||||
Message::Priority saved_priority;
|
Message::Priority saved_priority;
|
||||||
bool task_running = true;
|
|
||||||
{
|
{
|
||||||
MonitorLocker ml(&monitor_);
|
MonitorLocker ml(&monitor_);
|
||||||
if (FLAG_trace_isolates) {
|
if (FLAG_trace_isolates) {
|
||||||
|
@ -158,13 +155,12 @@ void MessageHandler::PostMessage(std::unique_ptr<Message> message,
|
||||||
ml.Notify();
|
ml.Notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pool_ != NULL) && (task_ == NULL)) {
|
if ((pool_ != NULL) && !task_running_) {
|
||||||
ASSERT(!delete_me_);
|
ASSERT(!delete_me_);
|
||||||
task_ = new MessageHandlerTask(this);
|
task_running_ = pool_->Run(new MessageHandlerTask(this));
|
||||||
task_running = pool_->Run(task_);
|
ASSERT(task_running_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ASSERT(task_running);
|
|
||||||
|
|
||||||
// Invoke any custom message notification.
|
// Invoke any custom message notification.
|
||||||
MessageNotify(saved_priority);
|
MessageNotify(saved_priority);
|
||||||
|
@ -279,7 +275,7 @@ MessageHandler::MessageStatus MessageHandler::HandleNextMessage() {
|
||||||
MessageHandler::MessageStatus MessageHandler::PauseAndHandleAllMessages(
|
MessageHandler::MessageStatus MessageHandler::PauseAndHandleAllMessages(
|
||||||
int64_t timeout_millis) {
|
int64_t timeout_millis) {
|
||||||
MonitorLocker ml(&monitor_);
|
MonitorLocker ml(&monitor_);
|
||||||
ASSERT(task_ != NULL);
|
ASSERT(task_running_);
|
||||||
ASSERT(!delete_me_);
|
ASSERT(!delete_me_);
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
CheckAccess();
|
CheckAccess();
|
||||||
|
@ -287,7 +283,7 @@ MessageHandler::MessageStatus MessageHandler::PauseAndHandleAllMessages(
|
||||||
paused_for_messages_ = true;
|
paused_for_messages_ = true;
|
||||||
while (queue_->IsEmpty() && oob_queue_->IsEmpty()) {
|
while (queue_->IsEmpty() && oob_queue_->IsEmpty()) {
|
||||||
Monitor::WaitResult wr = ml.Wait(timeout_millis);
|
Monitor::WaitResult wr = ml.Wait(timeout_millis);
|
||||||
ASSERT(task_ != NULL);
|
ASSERT(task_running_);
|
||||||
ASSERT(!delete_me_);
|
ASSERT(!delete_me_);
|
||||||
if (wr == Monitor::kTimedOut) {
|
if (wr == Monitor::kTimedOut) {
|
||||||
break;
|
break;
|
||||||
|
@ -375,7 +371,7 @@ void MessageHandler::TaskCallback() {
|
||||||
if (ShouldPauseOnStart(status)) {
|
if (ShouldPauseOnStart(status)) {
|
||||||
// Still paused.
|
// Still paused.
|
||||||
ASSERT(oob_queue_->IsEmpty());
|
ASSERT(oob_queue_->IsEmpty());
|
||||||
task_ = NULL; // No task in queue.
|
task_running_ = false; // No task in queue.
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
PausedOnStartLocked(&ml, false);
|
PausedOnStartLocked(&ml, false);
|
||||||
|
@ -386,7 +382,7 @@ void MessageHandler::TaskCallback() {
|
||||||
if (ShouldPauseOnExit(status)) {
|
if (ShouldPauseOnExit(status)) {
|
||||||
// Still paused.
|
// Still paused.
|
||||||
ASSERT(oob_queue_->IsEmpty());
|
ASSERT(oob_queue_->IsEmpty());
|
||||||
task_ = NULL; // No task in queue.
|
task_running_ = false; // No task in queue.
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
PausedOnExitLocked(&ml, false);
|
PausedOnExitLocked(&ml, false);
|
||||||
|
@ -440,7 +436,7 @@ void MessageHandler::TaskCallback() {
|
||||||
if (ShouldPauseOnExit(status)) {
|
if (ShouldPauseOnExit(status)) {
|
||||||
// Still paused.
|
// Still paused.
|
||||||
ASSERT(oob_queue_->IsEmpty());
|
ASSERT(oob_queue_->IsEmpty());
|
||||||
task_ = NULL; // No task in queue.
|
task_running_ = false; // No task in queue.
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
PausedOnExitLocked(&ml, false);
|
PausedOnExitLocked(&ml, false);
|
||||||
|
@ -470,10 +466,10 @@ void MessageHandler::TaskCallback() {
|
||||||
delete_me = delete_me_;
|
delete_me = delete_me_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear the task_ last. This allows other tasks to potentially start
|
// Clear task_running_ last. This allows other tasks to potentially start
|
||||||
// for this message handler.
|
// for this message handler.
|
||||||
ASSERT(oob_queue_->IsEmpty());
|
ASSERT(oob_queue_->IsEmpty());
|
||||||
task_ = NULL;
|
task_running_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The handler may have been deleted by another thread here if it is a native
|
// The handler may have been deleted by another thread here if it is a native
|
||||||
|
@ -562,7 +558,7 @@ void MessageHandler::RequestDeletion() {
|
||||||
ASSERT(OwnedByPortMap());
|
ASSERT(OwnedByPortMap());
|
||||||
{
|
{
|
||||||
MonitorLocker ml(&monitor_);
|
MonitorLocker ml(&monitor_);
|
||||||
if (task_ != NULL) {
|
if (task_running_) {
|
||||||
// This message handler currently has a task running on the thread pool.
|
// This message handler currently has a task running on the thread pool.
|
||||||
delete_me_ = true;
|
delete_me_ = true;
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -257,9 +257,9 @@ class MessageHandler {
|
||||||
bool is_paused_on_exit_;
|
bool is_paused_on_exit_;
|
||||||
int64_t paused_timestamp_;
|
int64_t paused_timestamp_;
|
||||||
#endif
|
#endif
|
||||||
|
bool task_running_;
|
||||||
bool delete_me_;
|
bool delete_me_;
|
||||||
ThreadPool* pool_;
|
ThreadPool* pool_;
|
||||||
ThreadPool::Task* task_;
|
|
||||||
int64_t idle_start_time_;
|
int64_t idle_start_time_;
|
||||||
StartCallback start_callback_;
|
StartCallback start_callback_;
|
||||||
EndCallback end_callback_;
|
EndCallback end_callback_;
|
||||||
|
|
Loading…
Reference in a new issue