Chromium Code Reviews| 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..fd17dc3548d9f4e0527489541f5dc9de5b20fb05 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 control and shutdown task queues. |
| + for (size_t i = 0; i < total_task_queue_count_; i++) { |
| + if (i == CONTROL_TASK_QUEUE || i == SHUTDOWN_TASK_QUEUE) |
|
rmcilroy
2015/04/28 09:51:09
I'm wondering whether we even need the control tas
Sami
2015/04/28 11:52:46
I thought Alex originally made kept the control qu
|
| + 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: |