Commit 3495d068 authored by Alexander Timin's avatar Alexander Timin Committed by Commit Bot

[scheduler] Rename WorkQueue work_queue_ field to tasks_

WorkQueue class has work_queue_ field, which is confusing. Rename it to
tasks_.

R=alexclarke@chromium.org,skyostil@chromium.org

Change-Id: Ibdf4c69cf29a9ffbd48205fac1cd9b20c92f7a13
Reviewed-on: https://chromium-review.googlesource.com/897525
Commit-Queue: Alexander Timin <altimin@chromium.org>
Reviewed-by: default avatarAlex Clarke <alexclarke@chromium.org>
Reviewed-by: default avatarSami Kyöstilä <skyostil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#540811}
parent 53880dfe
...@@ -17,7 +17,7 @@ WorkQueue::WorkQueue(TaskQueueImpl* task_queue, ...@@ -17,7 +17,7 @@ WorkQueue::WorkQueue(TaskQueueImpl* task_queue,
void WorkQueue::AsValueInto(base::TimeTicks now, void WorkQueue::AsValueInto(base::TimeTicks now,
base::trace_event::TracedValue* state) const { base::trace_event::TracedValue* state) const {
for (const TaskQueueImpl::Task& task : work_queue_) { for (const TaskQueueImpl::Task& task : tasks_) {
TaskQueueImpl::TaskAsValueInto(task, now, state); TaskQueueImpl::TaskAsValueInto(task, now, state);
} }
} }
...@@ -28,15 +28,15 @@ WorkQueue::~WorkQueue() { ...@@ -28,15 +28,15 @@ WorkQueue::~WorkQueue() {
} }
const TaskQueueImpl::Task* WorkQueue::GetFrontTask() const { const TaskQueueImpl::Task* WorkQueue::GetFrontTask() const {
if (work_queue_.empty()) if (tasks_.empty())
return nullptr; return nullptr;
return &work_queue_.front(); return &tasks_.front();
} }
const TaskQueueImpl::Task* WorkQueue::GetBackTask() const { const TaskQueueImpl::Task* WorkQueue::GetBackTask() const {
if (work_queue_.empty()) if (tasks_.empty())
return nullptr; return nullptr;
return &work_queue_.back(); return &tasks_.back();
} }
bool WorkQueue::BlockedByFence() const { bool WorkQueue::BlockedByFence() const {
...@@ -46,33 +46,31 @@ bool WorkQueue::BlockedByFence() const { ...@@ -46,33 +46,31 @@ bool WorkQueue::BlockedByFence() const {
// If the queue is empty then any future tasks will have a higher enqueue // If the queue is empty then any future tasks will have a higher enqueue
// order and will be blocked. The queue is also blocked if the head is past // order and will be blocked. The queue is also blocked if the head is past
// the fence. // the fence.
return work_queue_.empty() || work_queue_.front().enqueue_order() >= fence_; return tasks_.empty() || tasks_.front().enqueue_order() >= fence_;
} }
bool WorkQueue::GetFrontTaskEnqueueOrder(EnqueueOrder* enqueue_order) const { bool WorkQueue::GetFrontTaskEnqueueOrder(EnqueueOrder* enqueue_order) const {
if (work_queue_.empty() || BlockedByFence()) if (tasks_.empty() || BlockedByFence())
return false; return false;
// Quick sanity check. // Quick sanity check.
DCHECK_LE(work_queue_.front().enqueue_order(), DCHECK_LE(tasks_.front().enqueue_order(), tasks_.back().enqueue_order())
work_queue_.back().enqueue_order())
<< task_queue_->GetName() << " : " << work_queue_sets_->GetName() << " : " << task_queue_->GetName() << " : " << work_queue_sets_->GetName() << " : "
<< name_; << name_;
*enqueue_order = work_queue_.front().enqueue_order(); *enqueue_order = tasks_.front().enqueue_order();
return true; return true;
} }
void WorkQueue::Push(TaskQueueImpl::Task task) { void WorkQueue::Push(TaskQueueImpl::Task task) {
bool was_empty = work_queue_.empty(); bool was_empty = tasks_.empty();
#ifndef NDEBUG #ifndef NDEBUG
DCHECK(task.enqueue_order_set()); DCHECK(task.enqueue_order_set());
#endif #endif
// Make sure the |enqueue_order()| is monotonically increasing. // Make sure the |enqueue_order()| is monotonically increasing.
DCHECK(was_empty || DCHECK(was_empty || tasks_.rbegin()->enqueue_order() < task.enqueue_order());
work_queue_.rbegin()->enqueue_order() < task.enqueue_order());
// Amoritized O(1). // Amoritized O(1).
work_queue_.push_back(std::move(task)); tasks_.push_back(std::move(task));
if (!was_empty) if (!was_empty)
return; return;
...@@ -85,7 +83,7 @@ void WorkQueue::Push(TaskQueueImpl::Task task) { ...@@ -85,7 +83,7 @@ void WorkQueue::Push(TaskQueueImpl::Task task) {
void WorkQueue::PushNonNestableTaskToFront(TaskQueueImpl::Task task) { void WorkQueue::PushNonNestableTaskToFront(TaskQueueImpl::Task task) {
DCHECK(task.nestable == base::Nestable::kNonNestable); DCHECK(task.nestable == base::Nestable::kNonNestable);
bool was_empty = work_queue_.empty(); bool was_empty = tasks_.empty();
bool was_blocked = BlockedByFence(); bool was_blocked = BlockedByFence();
#ifndef NDEBUG #ifndef NDEBUG
DCHECK(task.enqueue_order_set()); DCHECK(task.enqueue_order_set());
...@@ -93,13 +91,13 @@ void WorkQueue::PushNonNestableTaskToFront(TaskQueueImpl::Task task) { ...@@ -93,13 +91,13 @@ void WorkQueue::PushNonNestableTaskToFront(TaskQueueImpl::Task task) {
if (!was_empty) { if (!was_empty) {
// Make sure the |enqueue_order()| is monotonically increasing. // Make sure the |enqueue_order()| is monotonically increasing.
DCHECK_LE(task.enqueue_order(), work_queue_.front().enqueue_order()) DCHECK_LE(task.enqueue_order(), tasks_.front().enqueue_order())
<< task_queue_->GetName() << " : " << work_queue_sets_->GetName() << task_queue_->GetName() << " : " << work_queue_sets_->GetName()
<< " : " << name_; << " : " << name_;
} }
// Amoritized O(1). // Amoritized O(1).
work_queue_.push_front(std::move(task)); tasks_.push_front(std::move(task));
if (!work_queue_sets_) if (!work_queue_sets_)
return; return;
...@@ -117,10 +115,10 @@ void WorkQueue::PushNonNestableTaskToFront(TaskQueueImpl::Task task) { ...@@ -117,10 +115,10 @@ void WorkQueue::PushNonNestableTaskToFront(TaskQueueImpl::Task task) {
} }
void WorkQueue::ReloadEmptyImmediateQueue() { void WorkQueue::ReloadEmptyImmediateQueue() {
DCHECK(work_queue_.empty()); DCHECK(tasks_.empty());
work_queue_ = task_queue_->TakeImmediateIncomingQueue(); tasks_ = task_queue_->TakeImmediateIncomingQueue();
if (work_queue_.empty()) if (tasks_.empty())
return; return;
// If we hit the fence, pretend to WorkQueueSets that we're empty. // If we hit the fence, pretend to WorkQueueSets that we're empty.
...@@ -130,13 +128,13 @@ void WorkQueue::ReloadEmptyImmediateQueue() { ...@@ -130,13 +128,13 @@ void WorkQueue::ReloadEmptyImmediateQueue() {
TaskQueueImpl::Task WorkQueue::TakeTaskFromWorkQueue() { TaskQueueImpl::Task WorkQueue::TakeTaskFromWorkQueue() {
DCHECK(work_queue_sets_); DCHECK(work_queue_sets_);
DCHECK(!work_queue_.empty()); DCHECK(!tasks_.empty());
TaskQueueImpl::Task pending_task = work_queue_.TakeFirst(); TaskQueueImpl::Task pending_task = tasks_.TakeFirst();
// NB immediate tasks have a different pipeline to delayed ones. // NB immediate tasks have a different pipeline to delayed ones.
if (queue_type_ == QueueType::kImmediate && work_queue_.empty()) { if (queue_type_ == QueueType::kImmediate && tasks_.empty()) {
// Short-circuit the queue reload so that OnPopQueue does the right thing. // Short-circuit the queue reload so that OnPopQueue does the right thing.
work_queue_ = task_queue_->TakeImmediateIncomingQueue(); tasks_ = task_queue_->TakeImmediateIncomingQueue();
} }
// OnPopQueue calls GetFrontTaskEnqueueOrder which checks BlockedByFence() so // OnPopQueue calls GetFrontTaskEnqueueOrder which checks BlockedByFence() so
// we don't need to here. // we don't need to here.
...@@ -148,16 +146,16 @@ TaskQueueImpl::Task WorkQueue::TakeTaskFromWorkQueue() { ...@@ -148,16 +146,16 @@ TaskQueueImpl::Task WorkQueue::TakeTaskFromWorkQueue() {
bool WorkQueue::RemoveAllCanceledTasksFromFront() { bool WorkQueue::RemoveAllCanceledTasksFromFront() {
DCHECK(work_queue_sets_); DCHECK(work_queue_sets_);
bool task_removed = false; bool task_removed = false;
while (!work_queue_.empty() && (!work_queue_.front().task || while (!tasks_.empty() &&
work_queue_.front().task.IsCancelled())) { (!tasks_.front().task || tasks_.front().task.IsCancelled())) {
work_queue_.pop_front(); tasks_.pop_front();
task_removed = true; task_removed = true;
} }
if (task_removed) { if (task_removed) {
// NB immediate tasks have a different pipeline to delayed ones. // NB immediate tasks have a different pipeline to delayed ones.
if (queue_type_ == QueueType::kImmediate && work_queue_.empty()) { if (queue_type_ == QueueType::kImmediate && tasks_.empty()) {
// Short-circuit the queue reload so that OnPopQueue does the right thing. // Short-circuit the queue reload so that OnPopQueue does the right thing.
work_queue_ = task_queue_->TakeImmediateIncomingQueue(); tasks_ = task_queue_->TakeImmediateIncomingQueue();
} }
work_queue_sets_->OnPopQueue(this); work_queue_sets_->OnPopQueue(this);
task_queue_->TraceQueueSize(); task_queue_->TraceQueueSize();
...@@ -191,7 +189,7 @@ bool WorkQueue::InsertFence(EnqueueOrder fence) { ...@@ -191,7 +189,7 @@ bool WorkQueue::InsertFence(EnqueueOrder fence) {
bool was_blocked_by_fence = InsertFenceImpl(fence); bool was_blocked_by_fence = InsertFenceImpl(fence);
// Moving the fence forward may unblock some tasks. // Moving the fence forward may unblock some tasks.
if (work_queue_sets_ && !work_queue_.empty() && was_blocked_by_fence && if (work_queue_sets_ && !tasks_.empty() && was_blocked_by_fence &&
!BlockedByFence()) { !BlockedByFence()) {
work_queue_sets_->OnTaskPushedToEmptyQueue(this); work_queue_sets_->OnTaskPushedToEmptyQueue(this);
return true; return true;
...@@ -205,7 +203,7 @@ bool WorkQueue::InsertFence(EnqueueOrder fence) { ...@@ -205,7 +203,7 @@ bool WorkQueue::InsertFence(EnqueueOrder fence) {
bool WorkQueue::RemoveFence() { bool WorkQueue::RemoveFence() {
bool was_blocked_by_fence = BlockedByFence(); bool was_blocked_by_fence = BlockedByFence();
fence_ = 0; fence_ = 0;
if (work_queue_sets_ && !work_queue_.empty() && was_blocked_by_fence) { if (work_queue_sets_ && !tasks_.empty() && was_blocked_by_fence) {
work_queue_sets_->OnTaskPushedToEmptyQueue(this); work_queue_sets_->OnTaskPushedToEmptyQueue(this);
return true; return true;
} }
...@@ -213,8 +211,8 @@ bool WorkQueue::RemoveFence() { ...@@ -213,8 +211,8 @@ bool WorkQueue::RemoveFence() {
} }
bool WorkQueue::ShouldRunBefore(const WorkQueue* other_queue) const { bool WorkQueue::ShouldRunBefore(const WorkQueue* other_queue) const {
DCHECK(!work_queue_.empty()); DCHECK(!tasks_.empty());
DCHECK(!other_queue->work_queue_.empty()); DCHECK(!other_queue->tasks_.empty());
EnqueueOrder enqueue_order = 0; EnqueueOrder enqueue_order = 0;
EnqueueOrder other_enqueue_order = 0; EnqueueOrder other_enqueue_order = 0;
bool have_task = GetFrontTaskEnqueueOrder(&enqueue_order); bool have_task = GetFrontTaskEnqueueOrder(&enqueue_order);
...@@ -226,9 +224,9 @@ bool WorkQueue::ShouldRunBefore(const WorkQueue* other_queue) const { ...@@ -226,9 +224,9 @@ bool WorkQueue::ShouldRunBefore(const WorkQueue* other_queue) const {
} }
void WorkQueue::PopTaskForTesting() { void WorkQueue::PopTaskForTesting() {
if (work_queue_.empty()) if (tasks_.empty())
return; return;
work_queue_.pop_front(); tasks_.pop_front();
} }
} // namespace internal } // namespace internal
......
...@@ -49,10 +49,10 @@ class PLATFORM_EXPORT WorkQueue { ...@@ -49,10 +49,10 @@ class PLATFORM_EXPORT WorkQueue {
void AsValueInto(base::TimeTicks now, void AsValueInto(base::TimeTicks now,
base::trace_event::TracedValue* state) const; base::trace_event::TracedValue* state) const;
// Returns true if the |work_queue_| is empty. This method ignores any fences. // Returns true if the |tasks_| is empty. This method ignores any fences.
bool Empty() const { return work_queue_.empty(); } bool Empty() const { return tasks_.empty(); }
// If the |work_queue_| isn't empty and a fence hasn't been reached, // If the |tasks_| isn't empty and a fence hasn't been reached,
// |enqueue_order| gets set to the enqueue order of the front task and the // |enqueue_order| gets set to the enqueue order of the front task and the
// function returns true. Otherwise the function returns false. // function returns true. Otherwise the function returns false.
bool GetFrontTaskEnqueueOrder(EnqueueOrder* enqueue_order) const; bool GetFrontTaskEnqueueOrder(EnqueueOrder* enqueue_order) const;
...@@ -65,23 +65,23 @@ class PLATFORM_EXPORT WorkQueue { ...@@ -65,23 +65,23 @@ class PLATFORM_EXPORT WorkQueue {
// method ignores any fences. // method ignores any fences.
const TaskQueueImpl::Task* GetBackTask() const; const TaskQueueImpl::Task* GetBackTask() const;
// Pushes the task onto the |work_queue_| and if a fence hasn't been reached // Pushes the task onto the |tasks_| and if a fence hasn't been reached
// it informs the WorkQueueSets if the head changed. // it informs the WorkQueueSets if the head changed.
void Push(TaskQueueImpl::Task task); void Push(TaskQueueImpl::Task task);
// Pushes the task onto the front of the |work_queue_| and if it's before any // Pushes the task onto the front of the |tasks_| and if it's before any
// fence it informs the WorkQueueSets the head changed. Use with caution this // fence it informs the WorkQueueSets the head changed. Use with caution this
// API can easily lead to task starvation if misused. // API can easily lead to task starvation if misused.
void PushNonNestableTaskToFront(TaskQueueImpl::Task task); void PushNonNestableTaskToFront(TaskQueueImpl::Task task);
// Reloads the empty |work_queue_| with // Reloads the empty |tasks_| with
// |task_queue_->TakeImmediateIncomingQueue| and if a fence hasn't been // |task_queue_->TakeImmediateIncomingQueue| and if a fence hasn't been
// reached it informs the WorkQueueSets if the head changed. // reached it informs the WorkQueueSets if the head changed.
void ReloadEmptyImmediateQueue(); void ReloadEmptyImmediateQueue();
size_t Size() const { return work_queue_.size(); } size_t Size() const { return tasks_.size(); }
// Pulls a task off the |work_queue_| and informs the WorkQueueSets. If the // Pulls a task off the |tasks_| and informs the WorkQueueSets. If the
// task removed had an enqueue order >= the current fence then WorkQueue // task removed had an enqueue order >= the current fence then WorkQueue
// pretends to be empty as far as the WorkQueueSets is concerned. // pretends to be empty as far as the WorkQueueSets is concerned.
TaskQueueImpl::Task TakeTaskFromWorkQueue(); TaskQueueImpl::Task TakeTaskFromWorkQueue();
...@@ -137,7 +137,7 @@ class PLATFORM_EXPORT WorkQueue { ...@@ -137,7 +137,7 @@ class PLATFORM_EXPORT WorkQueue {
private: private:
bool InsertFenceImpl(EnqueueOrder fence); bool InsertFenceImpl(EnqueueOrder fence);
TaskQueueImpl::TaskDeque work_queue_; TaskQueueImpl::TaskDeque tasks_;
WorkQueueSets* work_queue_sets_ = nullptr; // NOT OWNED. WorkQueueSets* work_queue_sets_ = nullptr; // NOT OWNED.
TaskQueueImpl* const task_queue_; // NOT OWNED. TaskQueueImpl* const task_queue_; // NOT OWNED.
size_t work_queue_set_index_ = 0; size_t work_queue_set_index_ = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment