OLD | NEW |
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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 // PriorityQueue. | 245 // PriorityQueue. |
246 const SchedulerWorkerPoolImpl::ReEnqueueSequenceCallback | 246 const SchedulerWorkerPoolImpl::ReEnqueueSequenceCallback |
247 re_enqueue_sequence_callback = | 247 re_enqueue_sequence_callback = |
248 Bind(&TaskSchedulerImpl::ReEnqueueSequenceCallback, Unretained(this)); | 248 Bind(&TaskSchedulerImpl::ReEnqueueSequenceCallback, Unretained(this)); |
249 | 249 |
250 // Start worker pools. | 250 // Start worker pools. |
251 for (const auto& worker_pool_params : worker_pool_params_vector) { | 251 for (const auto& worker_pool_params : worker_pool_params_vector) { |
252 // Passing pointers to objects owned by |this| to | 252 // Passing pointers to objects owned by |this| to |
253 // SchedulerWorkerPoolImpl::Create() is safe because a TaskSchedulerImpl | 253 // SchedulerWorkerPoolImpl::Create() is safe because a TaskSchedulerImpl |
254 // can't be deleted before all its worker pools have been joined. | 254 // can't be deleted before all its worker pools have been joined. |
255 worker_pools_.push_back(SchedulerWorkerPoolImpl::Create( | 255 worker_pools_.push_back(MakeUnique<SchedulerWorkerPoolImpl>( |
256 worker_pool_params, re_enqueue_sequence_callback, task_tracker_.get(), | 256 worker_pool_params.name(), worker_pool_params.priority_hint(), |
| 257 re_enqueue_sequence_callback, task_tracker_.get(), |
257 delayed_task_manager_.get())); | 258 delayed_task_manager_.get())); |
258 CHECK(worker_pools_.back()); | 259 worker_pools_.back()->Start(worker_pool_params); |
259 } | 260 } |
260 } | 261 } |
261 | 262 |
262 SchedulerWorkerPoolImpl* TaskSchedulerImpl::GetWorkerPoolForTraits( | 263 SchedulerWorkerPoolImpl* TaskSchedulerImpl::GetWorkerPoolForTraits( |
263 const TaskTraits& traits) const { | 264 const TaskTraits& traits) const { |
264 const size_t index = worker_pool_index_for_traits_callback_.Run(traits); | 265 const size_t index = worker_pool_index_for_traits_callback_.Run(traits); |
265 DCHECK_LT(index, worker_pools_.size()); | 266 DCHECK_LT(index, worker_pools_.size()); |
266 return worker_pools_[index].get(); | 267 return worker_pools_[index].get(); |
267 } | 268 } |
268 | 269 |
269 void TaskSchedulerImpl::ReEnqueueSequenceCallback( | 270 void TaskSchedulerImpl::ReEnqueueSequenceCallback( |
270 scoped_refptr<Sequence> sequence) { | 271 scoped_refptr<Sequence> sequence) { |
271 DCHECK(sequence); | 272 DCHECK(sequence); |
272 | 273 |
273 const SequenceSortKey sort_key = sequence->GetSortKey(); | 274 const SequenceSortKey sort_key = sequence->GetSortKey(); |
274 | 275 |
275 // The next task in |sequence| should run in a worker pool suited for its | 276 // The next task in |sequence| should run in a worker pool suited for its |
276 // traits, except for the priority which is adjusted to the highest priority | 277 // traits, except for the priority which is adjusted to the highest priority |
277 // in |sequence|. | 278 // in |sequence|. |
278 const TaskTraits traits = | 279 const TaskTraits traits = |
279 sequence->PeekTaskTraits().WithPriority(sort_key.priority()); | 280 sequence->PeekTaskTraits().WithPriority(sort_key.priority()); |
280 | 281 |
281 GetWorkerPoolForTraits(traits)->ReEnqueueSequence(std::move(sequence), | 282 GetWorkerPoolForTraits(traits)->ReEnqueueSequence(std::move(sequence), |
282 sort_key); | 283 sort_key); |
283 } | 284 } |
284 | 285 |
285 } // namespace internal | 286 } // namespace internal |
286 } // namespace base | 287 } // namespace base |
OLD | NEW |