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

Side by Side Diff: components/scheduler/child/task_queue_manager.cc

Issue 1259583006: Reland: Explicitly track the scheduler task enqueueing order in a new field (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comment Created 5 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/child/task_queue_manager.h" 5 #include "components/scheduler/child/task_queue_manager.h"
6 6
7 #include <queue> 7 #include <queue>
8 #include <set> 8 #include <set>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 97 }
98 98
99 void TaskQueueManager::UnregisterAsUpdatableTaskQueue( 99 void TaskQueueManager::UnregisterAsUpdatableTaskQueue(
100 internal::TaskQueueImpl* queue) { 100 internal::TaskQueueImpl* queue) {
101 DCHECK(main_thread_checker_.CalledOnValidThread()); 101 DCHECK(main_thread_checker_.CalledOnValidThread());
102 updatable_queue_set_.erase(queue); 102 updatable_queue_set_.erase(queue);
103 } 103 }
104 104
105 void TaskQueueManager::UpdateWorkQueues( 105 void TaskQueueManager::UpdateWorkQueues(
106 bool should_trigger_wakeup, 106 bool should_trigger_wakeup,
107 const base::PendingTask* previous_task) { 107 const internal::SchedulerTask* previous_task) {
108 DCHECK(main_thread_checker_.CalledOnValidThread()); 108 DCHECK(main_thread_checker_.CalledOnValidThread());
109 internal::LazyNow lazy_now(this); 109 internal::LazyNow lazy_now(this);
110 110
111 // Insert any newly updatable queues into the updatable_queue_set_. 111 // Insert any newly updatable queues into the updatable_queue_set_.
112 { 112 {
113 base::AutoLock lock(newly_updatable_lock_); 113 base::AutoLock lock(newly_updatable_lock_);
114 while (!newly_updatable_.empty()) { 114 while (!newly_updatable_.empty()) {
115 updatable_queue_set_.insert(newly_updatable_.back()); 115 updatable_queue_set_.insert(newly_updatable_.back());
116 newly_updatable_.pop_back(); 116 newly_updatable_.pop_back();
117 } 117 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 if (posted_from_main_thread) { 152 if (posted_from_main_thread) {
153 pending_dowork_count_--; 153 pending_dowork_count_--;
154 DCHECK_GE(pending_dowork_count_, 0); 154 DCHECK_GE(pending_dowork_count_, 0);
155 } 155 }
156 DCHECK(main_thread_checker_.CalledOnValidThread()); 156 DCHECK(main_thread_checker_.CalledOnValidThread());
157 157
158 // Pass false and nullptr to UpdateWorkQueues here to prevent waking up a 158 // Pass false and nullptr to UpdateWorkQueues here to prevent waking up a
159 // pump-after-wakeup queue. 159 // pump-after-wakeup queue.
160 UpdateWorkQueues(false, nullptr); 160 UpdateWorkQueues(false, nullptr);
161 161
162 base::PendingTask previous_task((tracked_objects::Location()), 162 internal::SchedulerTask previous_task;
163 (base::Closure()));
164 for (int i = 0; i < work_batch_size_; i++) { 163 for (int i = 0; i < work_batch_size_; i++) {
165 internal::TaskQueueImpl* queue; 164 internal::TaskQueueImpl* queue;
166 if (!SelectQueueToService(&queue)) 165 if (!SelectQueueToService(&queue))
167 return; 166 return;
168 // Note that this function won't post another call to DoWork if one is 167 // Note that this function won't post another call to DoWork if one is
169 // already pending, so it is safe to call it in a loop. 168 // already pending, so it is safe to call it in a loop.
170 MaybePostDoWorkOnMainRunner(); 169 MaybePostDoWorkOnMainRunner();
171 170
172 if (ProcessTaskFromWorkQueue(queue, &previous_task)) 171 if (ProcessTaskFromWorkQueue(queue, &previous_task))
173 return; // The TaskQueueManager got deleted, we must bail out. 172 return; // The TaskQueueManager got deleted, we must bail out.
(...skipping 11 matching lines...) Expand all
185 184
186 bool TaskQueueManager::SelectQueueToService( 185 bool TaskQueueManager::SelectQueueToService(
187 internal::TaskQueueImpl** out_queue) { 186 internal::TaskQueueImpl** out_queue) {
188 bool should_run = selector_.SelectQueueToService(out_queue); 187 bool should_run = selector_.SelectQueueToService(out_queue);
189 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( 188 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(
190 disabled_by_default_tracing_category_, "TaskQueueManager", this, 189 disabled_by_default_tracing_category_, "TaskQueueManager", this,
191 AsValueWithSelectorResult(should_run, *out_queue)); 190 AsValueWithSelectorResult(should_run, *out_queue));
192 return should_run; 191 return should_run;
193 } 192 }
194 193
195 void TaskQueueManager::DidQueueTask(const base::PendingTask& pending_task) { 194 void TaskQueueManager::DidQueueTask(internal::SchedulerTask& pending_task) {
195 pending_task.sequence_num = GetNextSequenceNumber();
196 task_annotator_.DidQueueTask("TaskQueueManager::PostTask", pending_task); 196 task_annotator_.DidQueueTask("TaskQueueManager::PostTask", pending_task);
197 } 197 }
198 198
199 bool TaskQueueManager::ProcessTaskFromWorkQueue( 199 bool TaskQueueManager::ProcessTaskFromWorkQueue(
200 internal::TaskQueueImpl* queue, 200 internal::TaskQueueImpl* queue,
201 base::PendingTask* out_previous_task) { 201 internal::SchedulerTask* out_previous_task) {
202 DCHECK(main_thread_checker_.CalledOnValidThread()); 202 DCHECK(main_thread_checker_.CalledOnValidThread());
203 scoped_refptr<DeletionSentinel> protect(deletion_sentinel_); 203 scoped_refptr<DeletionSentinel> protect(deletion_sentinel_);
204 base::PendingTask pending_task = queue->TakeTaskFromWorkQueue(); 204 // TODO(alexclarke): consider std::move() when allowed.
205 internal::SchedulerTask pending_task = queue->TakeTaskFromWorkQueue();
205 206
206 if (queue->GetQuiescenceMonitored()) 207 if (queue->GetQuiescenceMonitored())
207 task_was_run_on_quiescence_monitored_queue_ = true; 208 task_was_run_on_quiescence_monitored_queue_ = true;
208 209
209 if (!pending_task.nestable && main_task_runner_->IsNested()) { 210 if (!pending_task.nestable && main_task_runner_->IsNested()) {
210 // Defer non-nestable work to the main task runner. NOTE these tasks can be 211 // Defer non-nestable work to the main task runner. NOTE these tasks can be
211 // arbitrarily delayed so the additional delay should not be a problem. 212 // arbitrarily delayed so the additional delay should not be a problem.
212 main_task_runner_->PostNonNestableTask(pending_task.posted_from, 213 main_task_runner_->PostNonNestableTask(pending_task.posted_from,
213 pending_task.task); 214 pending_task.task);
214 } else { 215 } else {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 } 280 }
280 281
281 base::TimeTicks TaskQueueManager::Now() const { 282 base::TimeTicks TaskQueueManager::Now() const {
282 return time_source_->NowTicks(); 283 return time_source_->NowTicks();
283 } 284 }
284 285
285 int TaskQueueManager::GetNextSequenceNumber() { 286 int TaskQueueManager::GetNextSequenceNumber() {
286 return task_sequence_num_.GetNext(); 287 return task_sequence_num_.GetNext();
287 } 288 }
288 289
290 int TaskQueueManager::GetNextAgeNumber() {
291 return task_age_num_.GetNext();
292 }
293
289 scoped_refptr<base::trace_event::ConvertableToTraceFormat> 294 scoped_refptr<base::trace_event::ConvertableToTraceFormat>
290 TaskQueueManager::AsValueWithSelectorResult( 295 TaskQueueManager::AsValueWithSelectorResult(
291 bool should_run, 296 bool should_run,
292 internal::TaskQueueImpl* selected_queue) const { 297 internal::TaskQueueImpl* selected_queue) const {
293 DCHECK(main_thread_checker_.CalledOnValidThread()); 298 DCHECK(main_thread_checker_.CalledOnValidThread());
294 scoped_refptr<base::trace_event::TracedValue> state = 299 scoped_refptr<base::trace_event::TracedValue> state =
295 new base::trace_event::TracedValue(); 300 new base::trace_event::TracedValue();
296 state->BeginArray("queues"); 301 state->BeginArray("queues");
297 for (auto& queue : queues_) 302 for (auto& queue : queues_)
298 queue->AsValueInto(state.get()); 303 queue->AsValueInto(state.get());
(...skipping 10 matching lines...) Expand all
309 state->EndArray(); 314 state->EndArray();
310 return state; 315 return state;
311 } 316 }
312 317
313 void TaskQueueManager::OnTaskQueueEnabled() { 318 void TaskQueueManager::OnTaskQueueEnabled() {
314 DCHECK(main_thread_checker_.CalledOnValidThread()); 319 DCHECK(main_thread_checker_.CalledOnValidThread());
315 MaybePostDoWorkOnMainRunner(); 320 MaybePostDoWorkOnMainRunner();
316 } 321 }
317 322
318 } // namespace scheduler 323 } // namespace scheduler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698