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

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

Issue 2810873008: Separate the create and start phases in DelayedTaskManager. (Closed)
Patch Set: self-review Created 3 years, 8 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 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" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 // Instantiate TaskTracker. Needs to happen after starting the service thread 179 // Instantiate TaskTracker. Needs to happen after starting the service thread
180 // to get its message_loop(). 180 // to get its message_loop().
181 task_tracker_ = 181 task_tracker_ =
182 #if defined(OS_POSIX) && !defined(OS_NACL_SFI) 182 #if defined(OS_POSIX) && !defined(OS_NACL_SFI)
183 base::MakeUnique<TaskTrackerPosix>( 183 base::MakeUnique<TaskTrackerPosix>(
184 static_cast<MessageLoopForIO*>(service_thread_.message_loop())); 184 static_cast<MessageLoopForIO*>(service_thread_.message_loop()));
185 #else 185 #else
186 base::MakeUnique<TaskTracker>(); 186 base::MakeUnique<TaskTracker>();
187 #endif 187 #endif
188 188
189 // Instantiate DelayedTaskManager. Needs to happen after starting the service 189 // Start DelayedTaskManager. Needs to happen after starting the service thread
190 // thread to get its task_runner(). 190 // to get its task_runner().
191 delayed_task_manager_ = 191 delayed_task_manager_.Start(service_thread_.task_runner());
192 base::MakeUnique<DelayedTaskManager>(service_thread_.task_runner());
193 192
194 single_thread_task_runner_manager_ = 193 single_thread_task_runner_manager_ =
195 MakeUnique<SchedulerSingleThreadTaskRunnerManager>( 194 MakeUnique<SchedulerSingleThreadTaskRunnerManager>(
196 task_tracker_.get(), delayed_task_manager_.get()); 195 task_tracker_.get(), &delayed_task_manager_);
197 single_thread_task_runner_manager_->Start(); 196 single_thread_task_runner_manager_->Start();
198 197
199 // Callback invoked by workers to re-enqueue a sequence in the appropriate 198 // Callback invoked by workers to re-enqueue a sequence in the appropriate
200 // PriorityQueue. 199 // PriorityQueue.
201 const SchedulerWorkerPoolImpl::ReEnqueueSequenceCallback 200 const SchedulerWorkerPoolImpl::ReEnqueueSequenceCallback
202 re_enqueue_sequence_callback = 201 re_enqueue_sequence_callback =
203 Bind(&TaskSchedulerImpl::ReEnqueueSequenceCallback, Unretained(this)); 202 Bind(&TaskSchedulerImpl::ReEnqueueSequenceCallback, Unretained(this));
204 203
205 // Order must match the EnvironmentType enum. 204 // Order must match the EnvironmentType enum.
206 const SchedulerWorkerPoolParams* worker_pool_params[] = { 205 const SchedulerWorkerPoolParams* worker_pool_params[] = {
(...skipping 14 matching lines...) Expand all
221 // Start worker pools. 220 // Start worker pools.
222 for (int environment_type = 0; environment_type < ENVIRONMENT_COUNT; 221 for (int environment_type = 0; environment_type < ENVIRONMENT_COUNT;
223 ++environment_type) { 222 ++environment_type) {
224 // Passing pointers to objects owned by |this| to the constructor of 223 // Passing pointers to objects owned by |this| to the constructor of
225 // SchedulerWorkerPoolImpl is safe because a TaskSchedulerImpl can't be 224 // SchedulerWorkerPoolImpl is safe because a TaskSchedulerImpl can't be
226 // deleted before all its worker pools have been joined. 225 // deleted before all its worker pools have been joined.
227 worker_pools_[environment_type] = MakeUnique<SchedulerWorkerPoolImpl>( 226 worker_pools_[environment_type] = MakeUnique<SchedulerWorkerPoolImpl>(
228 name_ + kEnvironmentParams[environment_type].name_suffix, 227 name_ + kEnvironmentParams[environment_type].name_suffix,
229 kEnvironmentParams[environment_type].priority_hint, 228 kEnvironmentParams[environment_type].priority_hint,
230 re_enqueue_sequence_callback, task_tracker_.get(), 229 re_enqueue_sequence_callback, task_tracker_.get(),
231 delayed_task_manager_.get()); 230 &delayed_task_manager_);
232 worker_pools_[environment_type]->Start( 231 worker_pools_[environment_type]->Start(
233 *worker_pool_params[environment_type]); 232 *worker_pool_params[environment_type]);
234 } 233 }
235 } 234 }
236 235
237 SchedulerWorkerPoolImpl* TaskSchedulerImpl::GetWorkerPoolForTraits( 236 SchedulerWorkerPoolImpl* TaskSchedulerImpl::GetWorkerPoolForTraits(
238 const TaskTraits& traits) const { 237 const TaskTraits& traits) const {
239 return worker_pools_[GetEnvironmentIndexForTraits(traits)].get(); 238 return worker_pools_[GetEnvironmentIndexForTraits(traits)].get();
240 } 239 }
241 240
242 void TaskSchedulerImpl::ReEnqueueSequenceCallback( 241 void TaskSchedulerImpl::ReEnqueueSequenceCallback(
243 scoped_refptr<Sequence> sequence) { 242 scoped_refptr<Sequence> sequence) {
244 DCHECK(sequence); 243 DCHECK(sequence);
245 244
246 const SequenceSortKey sort_key = sequence->GetSortKey(); 245 const SequenceSortKey sort_key = sequence->GetSortKey();
247 246
248 // The next task in |sequence| should run in a worker pool suited for its 247 // The next task in |sequence| should run in a worker pool suited for its
249 // traits, except for the priority which is adjusted to the highest priority 248 // traits, except for the priority which is adjusted to the highest priority
250 // in |sequence|. 249 // in |sequence|.
251 const TaskTraits traits = 250 const TaskTraits traits =
252 sequence->PeekTaskTraits().WithPriority(sort_key.priority()); 251 sequence->PeekTaskTraits().WithPriority(sort_key.priority());
253 252
254 GetWorkerPoolForTraits(traits)->ReEnqueueSequence(std::move(sequence), 253 GetWorkerPoolForTraits(traits)->ReEnqueueSequence(std::move(sequence),
255 sort_key); 254 sort_key);
256 } 255 }
257 256
258 } // namespace internal 257 } // namespace internal
259 } // namespace base 258 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698