Chromium Code Reviews| Index: components/scheduler/child/task_queue_impl.cc |
| diff --git a/components/scheduler/child/task_queue_impl.cc b/components/scheduler/child/task_queue_impl.cc |
| index c422abd4634a17904fbb990b9d29eb502cc6611a..8d6e67115491c97399c2d33a5d3a9b38e1caccf0 100644 |
| --- a/components/scheduler/child/task_queue_impl.cc |
| +++ b/components/scheduler/child/task_queue_impl.cc |
| @@ -9,6 +9,14 @@ |
| namespace scheduler { |
| namespace internal { |
| +SchedulerTask::SchedulerTask() |
| + : PendingTask(tracked_objects::Location(), base::Closure()) {} |
|
Sami
2015/08/05 11:27:34
Should we initialize age here and below?
alex clarke (OOO till 29th)
2015/08/05 14:32:43
Done.
|
| + |
| +SchedulerTask::SchedulerTask(const tracked_objects::Location& posted_from, |
| + const base::Closure& task, |
| + bool nestable) |
| + : PendingTask(posted_from, task, base::TimeTicks(), nestable) {} |
| + |
| TaskQueueImpl::TaskQueueImpl( |
| TaskQueueManager* task_queue_manager, |
| const Spec& spec, |
| @@ -17,7 +25,6 @@ TaskQueueImpl::TaskQueueImpl( |
| : thread_id_(base::PlatformThread::CurrentId()), |
| task_queue_manager_(task_queue_manager), |
| pump_policy_(spec.pump_policy), |
| - delayed_task_sequence_number_(0), |
| name_(spec.name), |
| disabled_by_default_tracing_category_( |
| disabled_by_default_tracing_category), |
| @@ -33,9 +40,9 @@ TaskQueueImpl::~TaskQueueImpl() {} |
| void TaskQueueImpl::WillDeleteTaskQueueManager() { |
| base::AutoLock lock(lock_); |
| task_queue_manager_ = nullptr; |
| - delayed_task_queue_ = base::DelayedTaskQueue(); |
| - incoming_queue_ = base::TaskQueue(); |
| - work_queue_ = base::TaskQueue(); |
| + delayed_task_queue_ = std::priority_queue<SchedulerTask>(); |
| + incoming_queue_ = std::queue<SchedulerTask>(); |
| + work_queue_ = std::queue<SchedulerTask>(); |
| } |
| bool TaskQueueImpl::RunsTasksOnCurrentThread() const { |
| @@ -93,13 +100,13 @@ bool TaskQueueImpl::PostDelayedTaskLocked( |
| lock_.AssertAcquired(); |
| DCHECK(task_queue_manager_); |
| - base::PendingTask pending_task(from_here, task, base::TimeTicks(), |
| - task_type != TaskType::NON_NESTABLE); |
| + SchedulerTask pending_task(from_here, task, |
| + task_type != TaskType::NON_NESTABLE); |
| task_queue_manager_->DidQueueTask(pending_task); |
| if (!desired_run_time.is_null()) { |
| pending_task.delayed_run_time = std::max(lazy_now->Now(), desired_run_time); |
| - pending_task.sequence_num = delayed_task_sequence_number_++; |
| + // TODO(alexclarke): consider emplace() when C++11 library features allowed. |
| delayed_task_queue_.push(pending_task); |
| TraceQueueSize(true); |
| // If we changed the topmost task, then it is time to reschedule. |
| @@ -129,6 +136,7 @@ void TaskQueueImpl::MoveReadyDelayedTasksToIncomingQueueLocked( |
| delayed_task_queue_.top().delayed_run_time <= lazy_now->Now()) { |
| in_flight_kick_delayed_tasks_.erase( |
| delayed_task_queue_.top().delayed_run_time); |
| + // TODO(alexclarke): consider std::move() when allowed. |
| EnqueueTaskLocked(delayed_task_queue_.top()); |
| delayed_task_queue_.pop(); |
| } |
| @@ -181,7 +189,7 @@ TaskQueue::QueueState TaskQueueImpl::GetQueueState() const { |
| } |
| } |
| -bool TaskQueueImpl::TaskIsOlderThanQueuedTasks(const base::PendingTask* task) { |
| +bool TaskQueueImpl::TaskIsOlderThanQueuedTasks(const SchedulerTask* task) { |
| lock_.AssertAcquired(); |
| // A null task is passed when UpdateQueue is called before any task is run. |
| // In this case we don't want to pump an after_wakeup queue, so return true |
| @@ -193,11 +201,11 @@ bool TaskQueueImpl::TaskIsOlderThanQueuedTasks(const base::PendingTask* task) { |
| if (incoming_queue_.empty()) |
| return false; |
| - base::PendingTask oldest_queued_task = incoming_queue_.front(); |
| + const SchedulerTask& oldest_queued_task = incoming_queue_.front(); |
| DCHECK(oldest_queued_task.delayed_run_time.is_null()); |
| DCHECK(task->delayed_run_time.is_null()); |
| - // Note: the comparison is correct due to the fact that the PendingTask |
| + // Note: the comparison is correct due to the fact that the SchedulerTask |
| // operator inverts its comparison operation in order to work well in a heap |
| // based priority queue. |
| return oldest_queued_task < *task; |
| @@ -205,7 +213,7 @@ bool TaskQueueImpl::TaskIsOlderThanQueuedTasks(const base::PendingTask* task) { |
| bool TaskQueueImpl::ShouldAutoPumpQueueLocked( |
| bool should_trigger_wakeup, |
| - const base::PendingTask* previous_task) { |
| + const SchedulerTask* previous_task) { |
| lock_.AssertAcquired(); |
| if (pump_policy_ == PumpPolicy::MANUAL) |
| return false; |
| @@ -228,13 +236,13 @@ bool TaskQueueImpl::NextPendingDelayedTaskRunTime( |
| void TaskQueueImpl::UpdateWorkQueue(LazyNow* lazy_now, |
| bool should_trigger_wakeup, |
| - const base::PendingTask* previous_task) { |
| + const SchedulerTask* previous_task) { |
| DCHECK(work_queue_.empty()); |
| base::AutoLock lock(lock_); |
| if (!ShouldAutoPumpQueueLocked(should_trigger_wakeup, previous_task)) |
| return; |
| MoveReadyDelayedTasksToIncomingQueueLocked(lazy_now); |
| - work_queue_.Swap(&incoming_queue_); |
| + std::swap(work_queue_, incoming_queue_); |
| // |incoming_queue_| is now empty so TaskQueueManager::UpdateQueues no |
| // longer needs to consider this queue for reloading. |
| task_queue_manager_->UnregisterAsUpdatableTaskQueue(this); |
| @@ -245,8 +253,9 @@ void TaskQueueImpl::UpdateWorkQueue(LazyNow* lazy_now, |
| } |
| } |
| -base::PendingTask TaskQueueImpl::TakeTaskFromWorkQueue() { |
| - base::PendingTask pending_task = work_queue_.front(); |
| +SchedulerTask TaskQueueImpl::TakeTaskFromWorkQueue() { |
| + // TODO(alexclarke): consider std::move() when allowed. |
| + SchedulerTask pending_task = work_queue_.front(); |
| work_queue_.pop(); |
| DCHECK(task_queue_manager_); |
| task_queue_manager_->selector_.GetTaskQueueSets()->OnPopQueue(this); |
| @@ -271,7 +280,7 @@ void TaskQueueImpl::TraceQueueSize(bool is_locked) const { |
| lock_.Release(); |
| } |
| -void TaskQueueImpl::EnqueueTaskLocked(const base::PendingTask& pending_task) { |
| +void TaskQueueImpl::EnqueueTaskLocked(const SchedulerTask& pending_task) { |
| lock_.AssertAcquired(); |
| if (!task_queue_manager_) |
| return; |
| @@ -279,9 +288,9 @@ void TaskQueueImpl::EnqueueTaskLocked(const base::PendingTask& pending_task) { |
| task_queue_manager_->RegisterAsUpdatableTaskQueue(this); |
| if (pump_policy_ == PumpPolicy::AUTO && incoming_queue_.empty()) |
| task_queue_manager_->MaybePostDoWorkOnMainRunner(); |
| + // TODO(alexclarke): consider std::move() when allowed. |
| incoming_queue_.push(pending_task); |
| - incoming_queue_.back().sequence_num = |
| - task_queue_manager_->GetNextSequenceNumber(); |
| + incoming_queue_.back().age = task_queue_manager_->GetNextAgeNumber(); |
|
Sami
2015/08/05 11:27:34
This means we're doing two atomic increments per P
|
| if (!pending_task.delayed_run_time.is_null()) { |
| // Clear the delayed run time because we've already applied the delay |
| @@ -309,6 +318,7 @@ void TaskQueueImpl::PumpQueueLocked() { |
| bool was_empty = work_queue_.empty(); |
| while (!incoming_queue_.empty()) { |
| + // TODO(alexclarke): consider std::move() when allowed. |
| work_queue_.push(incoming_queue_.front()); |
| incoming_queue_.pop(); |
| } |
| @@ -334,12 +344,11 @@ const char* TaskQueueImpl::GetName() const { |
| bool TaskQueueImpl::GetWorkQueueFrontTaskAge(int* age) const { |
| if (work_queue_.empty()) |
| return false; |
| - *age = work_queue_.front().sequence_num; |
| + *age = work_queue_.front().age; |
| return true; |
| } |
| -void TaskQueueImpl::PushTaskOntoWorkQueueForTest( |
| - const base::PendingTask& task) { |
| +void TaskQueueImpl::PushTaskOntoWorkQueueForTest(const SchedulerTask& task) { |
| work_queue_.push(task); |
| } |
| @@ -433,9 +442,9 @@ void TaskQueueImpl::AsValueInto(base::trace_event::TracedValue* state) const { |
| } |
| // static |
| -void TaskQueueImpl::QueueAsValueInto(const base::TaskQueue& queue, |
| +void TaskQueueImpl::QueueAsValueInto(const std::queue<SchedulerTask>& queue, |
| base::trace_event::TracedValue* state) { |
| - base::TaskQueue queue_copy(queue); |
| + std::queue<SchedulerTask> queue_copy(queue); |
| while (!queue_copy.empty()) { |
| TaskAsValueInto(queue_copy.front(), state); |
| queue_copy.pop(); |
| @@ -443,9 +452,10 @@ void TaskQueueImpl::QueueAsValueInto(const base::TaskQueue& queue, |
| } |
| // static |
| -void TaskQueueImpl::QueueAsValueInto(const base::DelayedTaskQueue& queue, |
| - base::trace_event::TracedValue* state) { |
| - base::DelayedTaskQueue queue_copy(queue); |
| +void TaskQueueImpl::QueueAsValueInto( |
| + const std::priority_queue<SchedulerTask>& queue, |
| + base::trace_event::TracedValue* state) { |
| + std::priority_queue<SchedulerTask> queue_copy(queue); |
| while (!queue_copy.empty()) { |
| TaskAsValueInto(queue_copy.top(), state); |
| queue_copy.pop(); |
| @@ -453,10 +463,11 @@ void TaskQueueImpl::QueueAsValueInto(const base::DelayedTaskQueue& queue, |
| } |
| // static |
| -void TaskQueueImpl::TaskAsValueInto(const base::PendingTask& task, |
| +void TaskQueueImpl::TaskAsValueInto(const SchedulerTask& task, |
| base::trace_event::TracedValue* state) { |
| state->BeginDictionary(); |
| state->SetString("posted_from", task.posted_from.ToString()); |
| + state->SetInteger("age", task.age); |
| state->SetInteger("sequence_num", task.sequence_num); |
| state->SetBoolean("nestable", task.nestable); |
| state->SetBoolean("is_high_res", task.is_high_res); |