Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Unified Diff: components/scheduler/child/scheduler_helper.cc

Issue 1106213002: Adds a SHUTDOWN_TASK_QUEUE and a PreShutdown api to the scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/scheduler/child/scheduler_helper.cc
diff --git a/components/scheduler/child/scheduler_helper.cc b/components/scheduler/child/scheduler_helper.cc
index cb2d191ee2860f15286c881df60117ac61a86821..f0f80e9c8504f034d2c20266f931ec07dc0e4665 100644
--- a/components/scheduler/child/scheduler_helper.cc
+++ b/components/scheduler/child/scheduler_helper.cc
@@ -4,6 +4,7 @@
#include "components/scheduler/child/scheduler_helper.h"
+#include "base/synchronization/waitable_event.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/trace_event_argument.h"
#include "components/scheduler/child/nestable_single_thread_task_runner.h"
@@ -33,6 +34,10 @@ SchedulerHelper::SchedulerHelper(
QueueId::CONTROL_TASK_AFTER_WAKEUP_QUEUE)),
default_task_runner_(
task_queue_manager_->TaskRunnerForQueue(QueueId::DEFAULT_TASK_QUEUE)),
+ shutdown_task_runner_(task_queue_manager_->TaskRunnerForQueue(
+ QueueId::SHUTDOWN_TASK_QUEUE)),
+ total_task_queue_count_(total_task_queue_count),
+ in_preshutdown_(false),
quiescence_monitored_task_queue_mask_(
((1ull << total_task_queue_count) - 1ull) &
~(1ull << QueueId::IDLE_TASK_QUEUE) &
@@ -63,18 +68,16 @@ SchedulerHelper::SchedulerHelper(
weak_scheduler_ptr_),
tracing_category));
- task_queue_selector_->SetQueuePriority(
- QueueId::CONTROL_TASK_QUEUE,
- PrioritizingTaskQueueSelector::CONTROL_PRIORITY);
+ SetQueuePriority(QueueId::CONTROL_TASK_QUEUE,
+ PrioritizingTaskQueueSelector::CONTROL_PRIORITY);
- task_queue_selector_->SetQueuePriority(
- QueueId::CONTROL_TASK_AFTER_WAKEUP_QUEUE,
- PrioritizingTaskQueueSelector::CONTROL_PRIORITY);
+ SetQueuePriority(QueueId::CONTROL_TASK_AFTER_WAKEUP_QUEUE,
+ PrioritizingTaskQueueSelector::CONTROL_PRIORITY);
task_queue_manager_->SetPumpPolicy(
QueueId::CONTROL_TASK_AFTER_WAKEUP_QUEUE,
TaskQueueManager::PumpPolicy::AFTER_WAKEUP);
- task_queue_selector_->DisableQueue(QueueId::IDLE_TASK_QUEUE);
+ DisableQueue(QueueId::IDLE_TASK_QUEUE);
task_queue_manager_->SetPumpPolicy(QueueId::IDLE_TASK_QUEUE,
TaskQueueManager::PumpPolicy::MANUAL);
@@ -96,6 +99,20 @@ SchedulerHelper::SchedulerHelperDelegate::SchedulerHelperDelegate() {
SchedulerHelper::SchedulerHelperDelegate::~SchedulerHelperDelegate() {
}
+void SchedulerHelper::PreShutdown() {
+ CheckOnValidThread();
+ DCHECK(!in_preshutdown_);
+ TRACE_EVENT0(disabled_by_default_tracing_category_, "PreShutdown");
+ // Disable everything except the shutdown task queue.
+ for (size_t i = 0; i < total_task_queue_count_; i++) {
+ if (i == SHUTDOWN_TASK_QUEUE)
+ continue;
+ DisableQueue(i);
+ }
+ // Ensure that the queues don't get re-enabled.
+ in_preshutdown_ = true;
+}
+
void SchedulerHelper::Shutdown() {
CheckOnValidThread();
task_queue_manager_.reset();
@@ -113,6 +130,11 @@ scoped_refptr<SingleThreadIdleTaskRunner> SchedulerHelper::IdleTaskRunner() {
}
scoped_refptr<base::SingleThreadTaskRunner>
+SchedulerHelper::ShutdownTaskRunner() {
+ return shutdown_task_runner_;
+}
+
+scoped_refptr<base::SingleThreadTaskRunner>
SchedulerHelper::ControlTaskRunner() {
return control_task_runner_;
}
@@ -254,9 +276,8 @@ void SchedulerHelper::StartIdlePeriod(IdlePeriodState new_state,
CheckOnValidThread();
DCHECK(IsInIdlePeriod(new_state));
- task_queue_selector_->EnableQueue(
- QueueId::IDLE_TASK_QUEUE,
- PrioritizingTaskQueueSelector::BEST_EFFORT_PRIORITY);
+ EnableQueue(QueueId::IDLE_TASK_QUEUE,
+ PrioritizingTaskQueueSelector::BEST_EFFORT_PRIORITY);
task_queue_manager_->PumpQueue(QueueId::IDLE_TASK_QUEUE);
idle_period_state_ = new_state;
@@ -293,7 +314,7 @@ void SchedulerHelper::EndIdlePeriod() {
TRACE_EVENT_ASYNC_END0(tracing_category_, idle_period_tracing_name_, this);
}
- task_queue_selector_->DisableQueue(QueueId::IDLE_TASK_QUEUE);
+ DisableQueue(QueueId::IDLE_TASK_QUEUE);
idle_period_state_ = IdlePeriodState::NOT_IN_IDLE_PERIOD;
idle_period_deadline_ = base::TimeTicks();
}
@@ -355,6 +376,8 @@ void SchedulerHelper::SetQueuePriority(
size_t queue_index,
PrioritizingTaskQueueSelector::QueuePriority priority) {
CheckOnValidThread();
+ if (in_preshutdown_)
+ return;
return task_queue_selector_->SetQueuePriority(queue_index, priority);
}
@@ -362,11 +385,15 @@ void SchedulerHelper::EnableQueue(
size_t queue_index,
PrioritizingTaskQueueSelector::QueuePriority priority) {
CheckOnValidThread();
+ if (in_preshutdown_)
+ return;
task_queue_selector_->EnableQueue(queue_index, priority);
}
void SchedulerHelper::DisableQueue(size_t queue_index) {
CheckOnValidThread();
+ if (in_preshutdown_)
+ return;
task_queue_selector_->DisableQueue(queue_index);
}
@@ -382,6 +409,8 @@ const char* SchedulerHelper::TaskQueueIdToString(QueueId queue_id) {
return "default_tq";
case IDLE_TASK_QUEUE:
return "idle_tq";
+ case SHUTDOWN_TASK_QUEUE:
+ return "shutdown_tq";
case CONTROL_TASK_QUEUE:
return "control_tq";
case CONTROL_TASK_AFTER_WAKEUP_QUEUE:
« no previous file with comments | « components/scheduler/child/scheduler_helper.h ('k') | components/scheduler/child/scheduler_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698