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

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

Issue 2412983003: TaskScheduler: Put an ALIVE SchedulerWorker on top of the idle stack. (Closed)
Patch Set: CR robliao #3 Created 4 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698