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

Side by Side Diff: third_party/WebKit/Source/platform/scheduler/base/work_queue.cc

Issue 2579773002: Use WTF::Deque instead of std::queue in the blink scheduler (Closed)
Patch Set: Apply the fix Sami suggested Created 3 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/scheduler/base/work_queue.h" 5 #include "platform/scheduler/base/work_queue.h"
6 6
7 #include "platform/scheduler/base/work_queue_sets.h" 7 #include "platform/scheduler/base/work_queue_sets.h"
8 8
9 namespace blink { 9 namespace blink {
10 namespace scheduler { 10 namespace scheduler {
11 namespace internal { 11 namespace internal {
12 12
13 WorkQueue::WorkQueue(TaskQueueImpl* task_queue, const char* name) 13 WorkQueue::WorkQueue(TaskQueueImpl* task_queue, const char* name)
14 : work_queue_sets_(nullptr), 14 : work_queue_sets_(nullptr),
15 task_queue_(task_queue), 15 task_queue_(task_queue),
16 work_queue_set_index_(0), 16 work_queue_set_index_(0),
17 name_(name), 17 name_(name),
18 fence_(0) {} 18 fence_(0) {}
19 19
20 void WorkQueue::AsValueInto(base::trace_event::TracedValue* state) const { 20 void WorkQueue::AsValueInto(base::trace_event::TracedValue* state) const {
21 // Remove const to search |work_queue_| in the destructive manner. Restore the 21 for (const TaskQueueImpl::Task& task : work_queue_) {
22 // content from |visited| later. 22 TaskQueueImpl::TaskAsValueInto(task, state);
23 std::queue<TaskQueueImpl::Task>* mutable_queue =
24 const_cast<std::queue<TaskQueueImpl::Task>*>(&work_queue_);
25 std::queue<TaskQueueImpl::Task> visited;
26 while (!mutable_queue->empty()) {
27 TaskQueueImpl::TaskAsValueInto(mutable_queue->front(), state);
28 visited.push(std::move(mutable_queue->front()));
29 mutable_queue->pop();
30 } 23 }
31 *mutable_queue = std::move(visited);
32 } 24 }
33 25
34 WorkQueue::~WorkQueue() { 26 WorkQueue::~WorkQueue() {
35 DCHECK(!work_queue_sets_) << task_queue_->GetName() << " : " 27 DCHECK(!work_queue_sets_) << task_queue_->GetName() << " : "
36 << work_queue_sets_->name() << " : " << name_; 28 << work_queue_sets_->name() << " : " << name_;
37 } 29 }
38 30
39 const TaskQueueImpl::Task* WorkQueue::GetFrontTask() const { 31 const TaskQueueImpl::Task* WorkQueue::GetFrontTask() const {
40 if (work_queue_.empty()) 32 if (work_queue_.empty())
41 return nullptr; 33 return nullptr;
(...skipping 28 matching lines...) Expand all
70 return true; 62 return true;
71 } 63 }
72 64
73 void WorkQueue::Push(TaskQueueImpl::Task task) { 65 void WorkQueue::Push(TaskQueueImpl::Task task) {
74 bool was_empty = work_queue_.empty(); 66 bool was_empty = work_queue_.empty();
75 #ifndef NDEBUG 67 #ifndef NDEBUG
76 DCHECK(task.enqueue_order_set()); 68 DCHECK(task.enqueue_order_set());
77 #endif 69 #endif
78 70
79 // Amoritized O(1). 71 // Amoritized O(1).
80 work_queue_.push(std::move(task)); 72 work_queue_.push_back(std::move(task));
81 73
82 if (!was_empty) 74 if (!was_empty)
83 return; 75 return;
84 76
85 // If we hit the fence, pretend to WorkQueueSets that we're empty. 77 // If we hit the fence, pretend to WorkQueueSets that we're empty.
86 if (work_queue_sets_ && !BlockedByFence()) 78 if (work_queue_sets_ && !BlockedByFence())
87 work_queue_sets_->OnPushQueue(this); 79 work_queue_sets_->OnPushQueue(this);
88 } 80 }
89 81
90 void WorkQueue::PopTaskForTest() { 82 void WorkQueue::PopTaskForTest() {
91 if (work_queue_.empty()) 83 if (work_queue_.empty())
92 return; 84 return;
93 work_queue_.pop(); 85 work_queue_.pop_front();
94 } 86 }
95 87
96 void WorkQueue::SwapLocked(std::queue<TaskQueueImpl::Task>& incoming_queue) { 88 void WorkQueue::SwapLocked(WTF::Deque<TaskQueueImpl::Task>& incoming_queue) {
97 DCHECK(work_queue_.empty()); 89 DCHECK(work_queue_.empty());
98 std::swap(work_queue_, incoming_queue); 90 work_queue_.swap(incoming_queue);
99 if (work_queue_.empty()) 91 if (work_queue_.empty())
100 return; 92 return;
101 // If we hit the fence, pretend to WorkQueueSets that we're empty. 93 // If we hit the fence, pretend to WorkQueueSets that we're empty.
102 if (work_queue_sets_ && !BlockedByFence()) 94 if (work_queue_sets_ && !BlockedByFence())
103 work_queue_sets_->OnPushQueue(this); 95 work_queue_sets_->OnPushQueue(this);
104 } 96 }
105 97
106 TaskQueueImpl::Task WorkQueue::TakeTaskFromWorkQueue() { 98 TaskQueueImpl::Task WorkQueue::TakeTaskFromWorkQueue() {
107 DCHECK(work_queue_sets_); 99 DCHECK(work_queue_sets_);
108 DCHECK(!work_queue_.empty()); 100 DCHECK(!work_queue_.empty());
109 101
110 // Skip over canceled tasks, except for the last one since we always return 102 // Skip over canceled tasks, except for the last one since we always return
111 // something. 103 // something.
112 while (work_queue_.size() > 1u && work_queue_.front().task.IsCancelled()) { 104 while (work_queue_.size() > 1u && work_queue_.front().task.IsCancelled()) {
113 work_queue_.pop(); 105 work_queue_.pop_front();
114 } 106 }
115 107
116 TaskQueueImpl::Task pending_task = 108 TaskQueueImpl::Task pending_task = work_queue_.takeFirst();
117 std::move(const_cast<TaskQueueImpl::Task&>(work_queue_.front()));
118 work_queue_.pop();
119 work_queue_sets_->OnPopQueue(this); 109 work_queue_sets_->OnPopQueue(this);
120 task_queue_->TraceQueueSize(false); 110 task_queue_->TraceQueueSize(false);
121 return pending_task; 111 return pending_task;
122 } 112 }
123 113
124 void WorkQueue::AssignToWorkQueueSets(WorkQueueSets* work_queue_sets) { 114 void WorkQueue::AssignToWorkQueueSets(WorkQueueSets* work_queue_sets) {
125 work_queue_sets_ = work_queue_sets; 115 work_queue_sets_ = work_queue_sets;
126 } 116 }
127 117
128 void WorkQueue::AssignSetIndex(size_t work_queue_set_index) { 118 void WorkQueue::AssignSetIndex(size_t work_queue_set_index) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 bool have_other_task = 155 bool have_other_task =
166 other_queue->GetFrontTaskEnqueueOrder(&other_enqueue_order); 156 other_queue->GetFrontTaskEnqueueOrder(&other_enqueue_order);
167 DCHECK(have_task); 157 DCHECK(have_task);
168 DCHECK(have_other_task); 158 DCHECK(have_other_task);
169 return enqueue_order < other_enqueue_order; 159 return enqueue_order < other_enqueue_order;
170 } 160 }
171 161
172 } // namespace internal 162 } // namespace internal
173 } // namespace scheduler 163 } // namespace scheduler
174 } // namespace blink 164 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698