Chromium Code Reviews| 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/scheduler_worker_pool_impl.h" | 5 #include "base/task_scheduler/scheduler_worker_pool_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/sequenced_task_runner.h" | 16 #include "base/sequenced_task_runner.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/task_scheduler/delayed_task_manager.h" | 19 #include "base/task_scheduler/delayed_task_manager.h" |
| 20 #include "base/task_scheduler/task_tracker.h" | 20 #include "base/task_scheduler/task_tracker.h" |
| 21 #include "base/task_scheduler/worker_pool_params.h" | |
| 21 #include "base/threading/platform_thread.h" | 22 #include "base/threading/platform_thread.h" |
| 22 #include "base/threading/thread_local.h" | 23 #include "base/threading/thread_local.h" |
| 23 #include "base/threading/thread_restrictions.h" | 24 #include "base/threading/thread_restrictions.h" |
| 24 | 25 |
| 25 namespace base { | 26 namespace base { |
| 26 namespace internal { | 27 namespace internal { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 // SchedulerWorker that owns the current thread, if any. | 31 // SchedulerWorker that owns the current thread, if any. |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 }; | 221 }; |
| 221 | 222 |
| 222 SchedulerWorkerPoolImpl::~SchedulerWorkerPoolImpl() { | 223 SchedulerWorkerPoolImpl::~SchedulerWorkerPoolImpl() { |
| 223 // SchedulerWorkerPool should never be deleted in production unless its | 224 // SchedulerWorkerPool should never be deleted in production unless its |
| 224 // initialization failed. | 225 // initialization failed. |
| 225 DCHECK(join_for_testing_returned_.IsSignaled() || workers_.empty()); | 226 DCHECK(join_for_testing_returned_.IsSignaled() || workers_.empty()); |
| 226 } | 227 } |
| 227 | 228 |
| 228 // static | 229 // static |
| 229 std::unique_ptr<SchedulerWorkerPoolImpl> SchedulerWorkerPoolImpl::Create( | 230 std::unique_ptr<SchedulerWorkerPoolImpl> SchedulerWorkerPoolImpl::Create( |
| 230 StringPiece name, | 231 const WorkerPoolParams& worker_pool_params, |
|
gab
2016/07/18 15:24:13
s/worker_pool_params/params/ (just as descriptive
robliao
2016/07/18 19:51:11
sgtm. Done.
| |
| 231 ThreadPriority thread_priority, | |
| 232 size_t max_threads, | |
| 233 IORestriction io_restriction, | |
| 234 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback, | 232 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback, |
| 235 TaskTracker* task_tracker, | 233 TaskTracker* task_tracker, |
| 236 DelayedTaskManager* delayed_task_manager) { | 234 DelayedTaskManager* delayed_task_manager) { |
| 237 std::unique_ptr<SchedulerWorkerPoolImpl> worker_pool( | 235 std::unique_ptr<SchedulerWorkerPoolImpl> worker_pool( |
| 238 new SchedulerWorkerPoolImpl(name, io_restriction, task_tracker, | 236 new SchedulerWorkerPoolImpl(worker_pool_params.name(), |
| 239 delayed_task_manager)); | 237 worker_pool_params.io_restriction(), |
| 240 if (worker_pool->Initialize(thread_priority, max_threads, | 238 task_tracker, delayed_task_manager)); |
| 239 if (worker_pool->Initialize(worker_pool_params.thread_priority(), | |
| 240 worker_pool_params.max_threads(), | |
| 241 re_enqueue_sequence_callback)) { | 241 re_enqueue_sequence_callback)) { |
| 242 return worker_pool; | 242 return worker_pool; |
| 243 } | 243 } |
| 244 return nullptr; | 244 return nullptr; |
| 245 } | 245 } |
| 246 | 246 |
| 247 void SchedulerWorkerPoolImpl::WaitForAllWorkersIdleForTesting() { | 247 void SchedulerWorkerPoolImpl::WaitForAllWorkersIdleForTesting() { |
| 248 AutoSchedulerLock auto_lock(idle_workers_stack_lock_); | 248 AutoSchedulerLock auto_lock(idle_workers_stack_lock_); |
| 249 while (idle_workers_stack_.Size() < workers_.size()) | 249 while (idle_workers_stack_.Size() < workers_.size()) |
| 250 idle_workers_stack_cv_for_testing_->Wait(); | 250 idle_workers_stack_cv_for_testing_->Wait(); |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 } | 556 } |
| 557 | 557 |
| 558 void SchedulerWorkerPoolImpl::RemoveFromIdleWorkersStack( | 558 void SchedulerWorkerPoolImpl::RemoveFromIdleWorkersStack( |
| 559 SchedulerWorker* worker) { | 559 SchedulerWorker* worker) { |
| 560 AutoSchedulerLock auto_lock(idle_workers_stack_lock_); | 560 AutoSchedulerLock auto_lock(idle_workers_stack_lock_); |
| 561 idle_workers_stack_.Remove(worker); | 561 idle_workers_stack_.Remove(worker); |
| 562 } | 562 } |
| 563 | 563 |
| 564 } // namespace internal | 564 } // namespace internal |
| 565 } // namespace base | 565 } // namespace base |
| OLD | NEW |