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> |
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 | 691 |
692 bool SchedulerWorkerPoolImpl::Initialize( | 692 bool SchedulerWorkerPoolImpl::Initialize( |
693 ThreadPriority priority_hint, | 693 ThreadPriority priority_hint, |
694 size_t max_threads, | 694 size_t max_threads, |
695 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback) { | 695 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback) { |
696 AutoSchedulerLock auto_lock(idle_workers_stack_lock_); | 696 AutoSchedulerLock auto_lock(idle_workers_stack_lock_); |
697 | 697 |
698 DCHECK(workers_.empty()); | 698 DCHECK(workers_.empty()); |
699 | 699 |
700 for (size_t i = 0; i < max_threads; ++i) { | 700 for (size_t i = 0; i < max_threads; ++i) { |
| 701 // The last SchedulerWorker added to the idle stack should be ALIVE. |
| 702 const SchedulerWorker::InitialState initial_state = |
| 703 (i == max_threads - 1) ? SchedulerWorker::InitialState::ALIVE |
| 704 : SchedulerWorker::InitialState::DETACHED; |
701 std::unique_ptr<SchedulerWorker> worker = SchedulerWorker::Create( | 705 std::unique_ptr<SchedulerWorker> worker = SchedulerWorker::Create( |
702 priority_hint, MakeUnique<SchedulerWorkerDelegateImpl>( | 706 priority_hint, MakeUnique<SchedulerWorkerDelegateImpl>( |
703 this, re_enqueue_sequence_callback, | 707 this, re_enqueue_sequence_callback, |
704 &shared_priority_queue_, static_cast<int>(i)), | 708 &shared_priority_queue_, static_cast<int>(i)), |
705 task_tracker_, i == 0 ? SchedulerWorker::InitialState::ALIVE | 709 task_tracker_, initial_state); |
706 : SchedulerWorker::InitialState::DETACHED); | |
707 if (!worker) | 710 if (!worker) |
708 break; | 711 break; |
709 idle_workers_stack_.Push(worker.get()); | 712 idle_workers_stack_.Push(worker.get()); |
710 workers_.push_back(std::move(worker)); | 713 workers_.push_back(std::move(worker)); |
711 } | 714 } |
712 | 715 |
713 #if DCHECK_IS_ON() | 716 #if DCHECK_IS_ON() |
714 workers_created_.Signal(); | 717 workers_created_.Signal(); |
715 #endif | 718 #endif |
716 | 719 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 AutoSchedulerLock auto_lock(idle_workers_stack_lock_); | 756 AutoSchedulerLock auto_lock(idle_workers_stack_lock_); |
754 idle_workers_stack_.Remove(worker); | 757 idle_workers_stack_.Remove(worker); |
755 } | 758 } |
756 | 759 |
757 bool SchedulerWorkerPoolImpl::CanWorkerDetachForTesting() { | 760 bool SchedulerWorkerPoolImpl::CanWorkerDetachForTesting() { |
758 return !worker_detachment_disallowed_.IsSet(); | 761 return !worker_detachment_disallowed_.IsSet(); |
759 } | 762 } |
760 | 763 |
761 } // namespace internal | 764 } // namespace internal |
762 } // namespace base | 765 } // namespace base |
OLD | NEW |