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

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

Issue 2146223002: Refactor WorkerPoolCreationArgs to a Read-Only WorkerPoolParams (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/task_scheduler/scheduler_service_thread.h" 12 #include "base/task_scheduler/scheduler_service_thread.h"
13 #include "base/task_scheduler/sequence_sort_key.h" 13 #include "base/task_scheduler/sequence_sort_key.h"
14 #include "base/task_scheduler/task.h" 14 #include "base/task_scheduler/task.h"
15 #include "base/task_scheduler/worker_pool_params.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 17
17 namespace base { 18 namespace base {
18 namespace internal { 19 namespace internal {
19 20
20 // static 21 // static
21 std::unique_ptr<TaskSchedulerImpl> TaskSchedulerImpl::Create( 22 std::unique_ptr<TaskSchedulerImpl> TaskSchedulerImpl::Create(
22 const std::vector<WorkerPoolCreationArgs>& worker_pools, 23 const std::vector<WorkerPoolParams>& worker_pools,
23 const WorkerPoolIndexForTraitsCallback& 24 const WorkerPoolIndexForTraitsCallback&
24 worker_pool_index_for_traits_callback) { 25 worker_pool_index_for_traits_callback) {
25 std::unique_ptr<TaskSchedulerImpl> scheduler( 26 std::unique_ptr<TaskSchedulerImpl> scheduler(
26 new TaskSchedulerImpl(worker_pool_index_for_traits_callback)); 27 new TaskSchedulerImpl(worker_pool_index_for_traits_callback));
27 scheduler->Initialize(worker_pools); 28 scheduler->Initialize(worker_pools);
28 return scheduler; 29 return scheduler;
29 } 30 }
30 31
31 TaskSchedulerImpl::~TaskSchedulerImpl() { 32 TaskSchedulerImpl::~TaskSchedulerImpl() {
32 #if DCHECK_IS_ON() 33 #if DCHECK_IS_ON()
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 #if DCHECK_IS_ON() 78 #if DCHECK_IS_ON()
78 , 79 ,
79 join_for_testing_returned_(WaitableEvent::ResetPolicy::MANUAL, 80 join_for_testing_returned_(WaitableEvent::ResetPolicy::MANUAL,
80 WaitableEvent::InitialState::NOT_SIGNALED) 81 WaitableEvent::InitialState::NOT_SIGNALED)
81 #endif 82 #endif
82 { 83 {
83 DCHECK(!worker_pool_index_for_traits_callback_.is_null()); 84 DCHECK(!worker_pool_index_for_traits_callback_.is_null());
84 } 85 }
85 86
86 void TaskSchedulerImpl::Initialize( 87 void TaskSchedulerImpl::Initialize(
87 const std::vector<WorkerPoolCreationArgs>& worker_pools) { 88 const std::vector<WorkerPoolParams>& worker_pools) {
88 DCHECK(!worker_pools.empty()); 89 DCHECK(!worker_pools.empty());
89 90
90 const SchedulerWorkerPoolImpl::ReEnqueueSequenceCallback 91 const SchedulerWorkerPoolImpl::ReEnqueueSequenceCallback
91 re_enqueue_sequence_callback = 92 re_enqueue_sequence_callback =
92 Bind(&TaskSchedulerImpl::ReEnqueueSequenceCallback, Unretained(this)); 93 Bind(&TaskSchedulerImpl::ReEnqueueSequenceCallback, Unretained(this));
93 94
94 for (const auto& worker_pool : worker_pools) { 95 for (const auto& worker_pool : worker_pools) {
95 // Passing pointers to objects owned by |this| to 96 // Passing pointers to objects owned by |this| to
96 // SchedulerWorkerPoolImpl::Create() is safe because a TaskSchedulerImpl 97 // SchedulerWorkerPoolImpl::Create() is safe because a TaskSchedulerImpl
97 // can't be deleted before all its worker pools have been joined. 98 // can't be deleted before all its worker pools have been joined.
98 worker_pools_.push_back(SchedulerWorkerPoolImpl::Create( 99 worker_pools_.push_back(SchedulerWorkerPoolImpl::Create(
99 worker_pool.name, worker_pool.thread_priority, worker_pool.max_threads, 100 worker_pool, re_enqueue_sequence_callback, &task_tracker_,
100 worker_pool.io_restriction, re_enqueue_sequence_callback, 101 &delayed_task_manager_));
101 &task_tracker_, &delayed_task_manager_));
102 CHECK(worker_pools_.back()); 102 CHECK(worker_pools_.back());
103 } 103 }
104 104
105 service_thread_ = SchedulerServiceThread::Create(&task_tracker_, 105 service_thread_ = SchedulerServiceThread::Create(&task_tracker_,
106 &delayed_task_manager_); 106 &delayed_task_manager_);
107 CHECK(service_thread_); 107 CHECK(service_thread_);
108 } 108 }
109 109
110 SchedulerWorkerPool* TaskSchedulerImpl::GetWorkerPoolForTraits( 110 SchedulerWorkerPool* TaskSchedulerImpl::GetWorkerPoolForTraits(
111 const TaskTraits& traits) { 111 const TaskTraits& traits) {
(...skipping 17 matching lines...) Expand all
129 GetWorkerPoolForTraits(traits)->ReEnqueueSequence(std::move(sequence), 129 GetWorkerPoolForTraits(traits)->ReEnqueueSequence(std::move(sequence),
130 sort_key); 130 sort_key);
131 } 131 }
132 132
133 void TaskSchedulerImpl::OnDelayedRunTimeUpdated() { 133 void TaskSchedulerImpl::OnDelayedRunTimeUpdated() {
134 service_thread_->WakeUp(); 134 service_thread_->WakeUp();
135 } 135 }
136 136
137 } // namespace internal 137 } // namespace internal
138 } // namespace base 138 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698