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

Side by Side Diff: base/task_scheduler/task_scheduler_impl.cc

Issue 2862143004: Remove SchedulerWorkerPoolImpl::ReEnqueueSequenceCallback. (Closed)
Patch Set: CR-robliao-remove-includes Created 3 years, 7 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 | « base/task_scheduler/task_scheduler_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/task_scheduler/task_scheduler_impl.h" 5 #include "base/task_scheduler/task_scheduler_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
12 #include "base/task_scheduler/delayed_task_manager.h" 10 #include "base/task_scheduler/delayed_task_manager.h"
13 #include "base/task_scheduler/scheduler_worker_pool_params.h" 11 #include "base/task_scheduler/scheduler_worker_pool_params.h"
12 #include "base/task_scheduler/sequence.h"
14 #include "base/task_scheduler/sequence_sort_key.h" 13 #include "base/task_scheduler/sequence_sort_key.h"
15 #include "base/task_scheduler/task.h" 14 #include "base/task_scheduler/task.h"
16 #include "base/task_scheduler/task_tracker.h" 15 #include "base/task_scheduler/task_tracker.h"
17 16
18 namespace base { 17 namespace base {
19 namespace internal { 18 namespace internal {
20 19
21 namespace { 20 namespace {
22 21
23 enum EnvironmentType { 22 enum EnvironmentType {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 : name_(name), 57 : name_(name),
59 service_thread_("TaskSchedulerServiceThread"), 58 service_thread_("TaskSchedulerServiceThread"),
60 single_thread_task_runner_manager_(&task_tracker_, 59 single_thread_task_runner_manager_(&task_tracker_,
61 &delayed_task_manager_) { 60 &delayed_task_manager_) {
62 static_assert(arraysize(worker_pools_) == ENVIRONMENT_COUNT, 61 static_assert(arraysize(worker_pools_) == ENVIRONMENT_COUNT,
63 "The size of |worker_pools_| must match ENVIRONMENT_COUNT."); 62 "The size of |worker_pools_| must match ENVIRONMENT_COUNT.");
64 static_assert( 63 static_assert(
65 arraysize(kEnvironmentParams) == ENVIRONMENT_COUNT, 64 arraysize(kEnvironmentParams) == ENVIRONMENT_COUNT,
66 "The size of |kEnvironmentParams| must match ENVIRONMENT_COUNT."); 65 "The size of |kEnvironmentParams| must match ENVIRONMENT_COUNT.");
67 66
68 // Callback invoked by workers to re-enqueue a sequence in the appropriate
69 // PriorityQueue.
70 const auto reenqueue_sequence_callback = BindRepeating(
71 &TaskSchedulerImpl::ReEnqueueSequenceCallback, Unretained(this));
72
73 for (int environment_type = 0; environment_type < ENVIRONMENT_COUNT; 67 for (int environment_type = 0; environment_type < ENVIRONMENT_COUNT;
74 ++environment_type) { 68 ++environment_type) {
75 worker_pools_[environment_type] = MakeUnique<SchedulerWorkerPoolImpl>( 69 worker_pools_[environment_type] = MakeUnique<SchedulerWorkerPoolImpl>(
76 name_ + kEnvironmentParams[environment_type].name_suffix, 70 name_ + kEnvironmentParams[environment_type].name_suffix,
77 kEnvironmentParams[environment_type].priority_hint, 71 kEnvironmentParams[environment_type].priority_hint, &task_tracker_,
78 reenqueue_sequence_callback, &task_tracker_, &delayed_task_manager_); 72 &delayed_task_manager_);
79 } 73 }
80 } 74 }
81 75
82 TaskSchedulerImpl::~TaskSchedulerImpl() { 76 TaskSchedulerImpl::~TaskSchedulerImpl() {
83 #if DCHECK_IS_ON() 77 #if DCHECK_IS_ON()
84 DCHECK(join_for_testing_returned_.IsSet()); 78 DCHECK(join_for_testing_returned_.IsSet());
85 #endif 79 #endif
86 } 80 }
87 81
88 void TaskSchedulerImpl::Start(const TaskScheduler::InitParams& init_params) { 82 void TaskSchedulerImpl::Start(const TaskScheduler::InitParams& init_params) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 #if DCHECK_IS_ON() 196 #if DCHECK_IS_ON()
203 join_for_testing_returned_.Set(); 197 join_for_testing_returned_.Set();
204 #endif 198 #endif
205 } 199 }
206 200
207 SchedulerWorkerPoolImpl* TaskSchedulerImpl::GetWorkerPoolForTraits( 201 SchedulerWorkerPoolImpl* TaskSchedulerImpl::GetWorkerPoolForTraits(
208 const TaskTraits& traits) const { 202 const TaskTraits& traits) const {
209 return worker_pools_[GetEnvironmentIndexForTraits(traits)].get(); 203 return worker_pools_[GetEnvironmentIndexForTraits(traits)].get();
210 } 204 }
211 205
212 void TaskSchedulerImpl::ReEnqueueSequenceCallback(
213 scoped_refptr<Sequence> sequence) {
214 DCHECK(sequence);
215
216 const SequenceSortKey sort_key = sequence->GetSortKey();
217
218 // The next task in |sequence| should run in a worker pool suited for its
219 // traits, except for the priority which is adjusted to the highest priority
220 // in |sequence|.
221 const TaskTraits traits =
222 sequence->PeekTaskTraits().WithPriority(sort_key.priority());
223
224 GetWorkerPoolForTraits(traits)->ReEnqueueSequence(std::move(sequence),
225 sort_key);
226 }
227
228 } // namespace internal 206 } // namespace internal
229 } // namespace base 207 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/task_scheduler_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698