[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>
diff --git a/runtime/vm/message_handler.cc b/runtime/vm/message_handler.cc
index da32e9a..06fd9e2 100644
--- a/runtime/vm/message_handler.cc
+++ b/runtime/vm/message_handler.cc
@@ -64,9 +64,9 @@
is_paused_on_exit_(false),
paused_timestamp_(-1),
#endif
+ task_running_(false),
delete_me_(false),
pool_(NULL),
- task_(NULL),
idle_start_time_(0),
start_callback_(NULL),
end_callback_(NULL),
@@ -81,7 +81,6 @@
queue_ = NULL;
oob_queue_ = NULL;
pool_ = NULL;
- task_ = NULL;
}
const char* MessageHandler::name() const {
@@ -102,7 +101,6 @@
StartCallback start_callback,
EndCallback end_callback,
CallbackData data) {
- bool task_running;
MonitorLocker ml(&monitor_);
if (FLAG_trace_isolates) {
OS::PrintErr(
@@ -116,15 +114,14 @@
start_callback_ = start_callback;
end_callback_ = end_callback;
callback_data_ = data;
- task_ = new MessageHandlerTask(this);
- task_running = pool_->Run(task_);
- ASSERT(task_running);
+ task_running_ = pool_->Run(new MessageHandlerTask(this));
+ ASSERT(task_running_);
}
void MessageHandler::PostMessage(std::unique_ptr<Message> message,
bool before_events) {
Message::Priority saved_priority;
- bool task_running = true;
+
{
MonitorLocker ml(&monitor_);
if (FLAG_trace_isolates) {
@@ -158,13 +155,12 @@
ml.Notify();
}
- if ((pool_ != NULL) && (task_ == NULL)) {
+ if ((pool_ != NULL) && !task_running_) {
ASSERT(!delete_me_);
- task_ = new MessageHandlerTask(this);
- task_running = pool_->Run(task_);
+ task_running_ = pool_->Run(new MessageHandlerTask(this));
+ ASSERT(task_running_);
}
}
- ASSERT(task_running);
// Invoke any custom message notification.
MessageNotify(saved_priority);
@@ -279,7 +275,7 @@
MessageHandler::MessageStatus MessageHandler::PauseAndHandleAllMessages(
int64_t timeout_millis) {
MonitorLocker ml(&monitor_);
- ASSERT(task_ != NULL);
+ ASSERT(task_running_);
ASSERT(!delete_me_);
#if defined(DEBUG)
CheckAccess();
@@ -287,7 +283,7 @@
paused_for_messages_ = true;
while (queue_->IsEmpty() && oob_queue_->IsEmpty()) {
Monitor::WaitResult wr = ml.Wait(timeout_millis);
- ASSERT(task_ != NULL);
+ ASSERT(task_running_);
ASSERT(!delete_me_);
if (wr == Monitor::kTimedOut) {
break;
@@ -375,7 +371,7 @@
if (ShouldPauseOnStart(status)) {
// Still paused.
ASSERT(oob_queue_->IsEmpty());
- task_ = NULL; // No task in queue.
+ task_running_ = false; // No task in queue.
return;
} else {
PausedOnStartLocked(&ml, false);
@@ -386,7 +382,7 @@
if (ShouldPauseOnExit(status)) {
// Still paused.
ASSERT(oob_queue_->IsEmpty());
- task_ = NULL; // No task in queue.
+ task_running_ = false; // No task in queue.
return;
} else {
PausedOnExitLocked(&ml, false);
@@ -440,7 +436,7 @@
if (ShouldPauseOnExit(status)) {
// Still paused.
ASSERT(oob_queue_->IsEmpty());
- task_ = NULL; // No task in queue.
+ task_running_ = false; // No task in queue.
return;
} else {
PausedOnExitLocked(&ml, false);
@@ -470,10 +466,10 @@
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.
ASSERT(oob_queue_->IsEmpty());
- task_ = NULL;
+ task_running_ = false;
}
// The handler may have been deleted by another thread here if it is a native
@@ -562,7 +558,7 @@
ASSERT(OwnedByPortMap());
{
MonitorLocker ml(&monitor_);
- if (task_ != NULL) {
+ if (task_running_) {
// This message handler currently has a task running on the thread pool.
delete_me_ = true;
return;
diff --git a/runtime/vm/message_handler.h b/runtime/vm/message_handler.h
index babc541..46a7c19 100644
--- a/runtime/vm/message_handler.h
+++ b/runtime/vm/message_handler.h
@@ -257,9 +257,9 @@
bool is_paused_on_exit_;
int64_t paused_timestamp_;
#endif
+ bool task_running_;
bool delete_me_;
ThreadPool* pool_;
- ThreadPool::Task* task_;
int64_t idle_start_time_;
StartCallback start_callback_;
EndCallback end_callback_;