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

Side by Side Diff: components/scheduler/base/work_queue.cc

Issue 1685093002: Fix bug with TaskQueueSelector and blocked queues (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix UAF Created 4 years, 10 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
« no previous file with comments | « components/scheduler/base/work_queue.h ('k') | components/scheduler/base/work_queue_sets.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "components/scheduler/base/work_queue.h" 5 #include "components/scheduler/base/work_queue.h"
6 6
7 #include "components/scheduler/base/work_queue_sets.h" 7 #include "components/scheduler/base/work_queue_sets.h"
8 8
9 namespace scheduler { 9 namespace scheduler {
10 namespace internal { 10 namespace internal {
11 11
12 WorkQueue::WorkQueue(TaskQueueImpl* task_queue, const char* name) 12 WorkQueue::WorkQueue(TaskQueueImpl* task_queue, const char* name)
13 : work_queue_sets_(nullptr), 13 : work_queue_sets_(nullptr),
14 task_queue_(task_queue), 14 task_queue_(task_queue),
15 work_queue_set_index_(0), 15 work_queue_set_index_(0),
16 name_(name) {} 16 name_(name) {}
17 17
18 void WorkQueue::AsValueInto(base::trace_event::TracedValue* state) const { 18 void WorkQueue::AsValueInto(base::trace_event::TracedValue* state) const {
19 std::queue<TaskQueueImpl::Task> queue_copy(work_queue_); 19 std::queue<TaskQueueImpl::Task> queue_copy(work_queue_);
20 while (!queue_copy.empty()) { 20 while (!queue_copy.empty()) {
21 TaskQueueImpl::TaskAsValueInto(queue_copy.front(), state); 21 TaskQueueImpl::TaskAsValueInto(queue_copy.front(), state);
22 queue_copy.pop(); 22 queue_copy.pop();
23 } 23 }
24 } 24 }
25 25
26 WorkQueue::~WorkQueue() {} 26 WorkQueue::~WorkQueue() {
27 27 DCHECK(!work_queue_sets_) << task_queue_ ->GetName() << " : "
28 void WorkQueue::Clear() { 28 << work_queue_sets_->name() << " : " << name_;
29 work_queue_ = std::queue<TaskQueueImpl::Task>();
30 } 29 }
31 30
32 const TaskQueueImpl::Task* WorkQueue::GetFrontTask() const { 31 const TaskQueueImpl::Task* WorkQueue::GetFrontTask() const {
33 if (work_queue_.empty()) 32 if (work_queue_.empty())
34 return nullptr; 33 return nullptr;
35 return &work_queue_.front(); 34 return &work_queue_.front();
36 } 35 }
37 36
38 bool WorkQueue::GetFrontTaskEnqueueOrder(EnqueueOrder* enqueue_order) const { 37 bool WorkQueue::GetFrontTaskEnqueueOrder(EnqueueOrder* enqueue_order) const {
39 if (work_queue_.empty()) 38 if (work_queue_.empty())
40 return false; 39 return false;
41 *enqueue_order = work_queue_.front().enqueue_order(); 40 *enqueue_order = work_queue_.front().enqueue_order();
42 return true; 41 return true;
43 } 42 }
44 43
45 void WorkQueue::Push(TaskQueueImpl::Task&& task) { 44 void WorkQueue::Push(TaskQueueImpl::Task&& task) {
46 DCHECK(work_queue_sets_);
47 bool was_empty = work_queue_.empty(); 45 bool was_empty = work_queue_.empty();
48 work_queue_.push(task); 46 work_queue_.push(task);
49 if (was_empty) 47 if (was_empty && work_queue_sets_)
50 work_queue_sets_->OnPushQueue(this); 48 work_queue_sets_->OnPushQueue(this);
51 } 49 }
52 50
53 void WorkQueue::PushAndSetEnqueueOrder(TaskQueueImpl::Task&& task, 51 void WorkQueue::PushAndSetEnqueueOrder(TaskQueueImpl::Task&& task,
54 EnqueueOrder enqueue_order) { 52 EnqueueOrder enqueue_order) {
55 DCHECK(work_queue_sets_);
56 bool was_empty = work_queue_.empty(); 53 bool was_empty = work_queue_.empty();
57 work_queue_.push(task); 54 work_queue_.push(task);
58 work_queue_.back().set_enqueue_order(enqueue_order); 55 work_queue_.back().set_enqueue_order(enqueue_order);
59 56
60 if (was_empty) 57 if (was_empty && work_queue_sets_)
61 work_queue_sets_->OnPushQueue(this); 58 work_queue_sets_->OnPushQueue(this);
62 } 59 }
63 60
64 void WorkQueue::PopTaskForTest() { 61 void WorkQueue::PopTaskForTest() {
65 work_queue_.pop(); 62 work_queue_.pop();
66 } 63 }
67 64
68 void WorkQueue::SwapLocked(std::queue<TaskQueueImpl::Task>& incoming_queue) { 65 void WorkQueue::SwapLocked(std::queue<TaskQueueImpl::Task>& incoming_queue) {
69 DCHECK(work_queue_sets_);
70 std::swap(work_queue_, incoming_queue); 66 std::swap(work_queue_, incoming_queue);
71 67
72 if (!work_queue_.empty()) 68 if (!work_queue_.empty() && work_queue_sets_)
73 work_queue_sets_->OnPushQueue(this); 69 work_queue_sets_->OnPushQueue(this);
74 task_queue_->TraceQueueSize(true); 70 task_queue_->TraceQueueSize(true);
75 } 71 }
76 72
77 TaskQueueImpl::Task WorkQueue::TakeTaskFromWorkQueue() { 73 TaskQueueImpl::Task WorkQueue::TakeTaskFromWorkQueue() {
78 DCHECK(work_queue_sets_); 74 DCHECK(work_queue_sets_);
79 DCHECK(!work_queue_.empty()); 75 DCHECK(!work_queue_.empty());
80 TaskQueueImpl::Task pending_task = std::move(work_queue_.front()); 76 TaskQueueImpl::Task pending_task = std::move(work_queue_.front());
81 work_queue_.pop(); 77 work_queue_.pop();
82 work_queue_sets_->OnPopQueue(this); 78 work_queue_sets_->OnPopQueue(this);
83 task_queue_->TraceQueueSize(false); 79 task_queue_->TraceQueueSize(false);
84 return pending_task; 80 return pending_task;
85 } 81 }
86 82
87 void WorkQueue::AssignToWorkQueueSets(WorkQueueSets* work_queue_sets, 83 void WorkQueue::AssignToWorkQueueSets(WorkQueueSets* work_queue_sets) {
88 size_t work_queue_set_index) {
89 work_queue_sets_ = work_queue_sets; 84 work_queue_sets_ = work_queue_sets;
85 }
86
87 void WorkQueue::AssignSetIndex(size_t work_queue_set_index) {
90 work_queue_set_index_ = work_queue_set_index; 88 work_queue_set_index_ = work_queue_set_index;
91 } 89 }
92 90
93 bool WorkQueue::ShouldRunBefore(const WorkQueue* other_queue) const { 91 bool WorkQueue::ShouldRunBefore(const WorkQueue* other_queue) const {
94 DCHECK(!work_queue_.empty()); 92 DCHECK(!work_queue_.empty());
95 DCHECK(!other_queue->work_queue_.empty()); 93 DCHECK(!other_queue->work_queue_.empty());
96 EnqueueOrder enqueue_order; 94 EnqueueOrder enqueue_order;
97 EnqueueOrder other_enqueue_order; 95 EnqueueOrder other_enqueue_order;
98 bool have_task = GetFrontTaskEnqueueOrder(&enqueue_order); 96 bool have_task = GetFrontTaskEnqueueOrder(&enqueue_order);
99 bool have_other_task = 97 bool have_other_task =
100 other_queue->GetFrontTaskEnqueueOrder(&other_enqueue_order); 98 other_queue->GetFrontTaskEnqueueOrder(&other_enqueue_order);
101 DCHECK(have_task); 99 DCHECK(have_task);
102 DCHECK(have_other_task); 100 DCHECK(have_other_task);
103 return enqueue_order < other_enqueue_order; 101 return enqueue_order < other_enqueue_order;
104 } 102 }
105 103
106 } // namespace internal 104 } // namespace internal
107 } // namespace scheduler 105 } // namespace scheduler
OLDNEW
« no previous file with comments | « components/scheduler/base/work_queue.h ('k') | components/scheduler/base/work_queue_sets.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698