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

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

Issue 2415123002: TaskScheduler: Fix initial order of SchedulerWorkers on idle stack. (Closed)
Patch Set: 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 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 DCHECK(delayed_task_manager_); 689 DCHECK(delayed_task_manager_);
690 } 690 }
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 workers_.resize(max_threads);
699 700
700 for (size_t i = 0; i < max_threads; ++i) { 701 // Create workers and push them to the idle stack in reverse order of index.
701 // The last SchedulerWorker added to the idle stack should be ALIVE. 702 // This ensures that they are woken up in order of index and that the ALIVE
703 // worker is on top of the stack.
704 for (int index = max_threads - 1; index >= 0; --index) {
702 const SchedulerWorker::InitialState initial_state = 705 const SchedulerWorker::InitialState initial_state =
703 (i == max_threads - 1) ? SchedulerWorker::InitialState::ALIVE 706 (index == 0) ? SchedulerWorker::InitialState::ALIVE
704 : SchedulerWorker::InitialState::DETACHED; 707 : SchedulerWorker::InitialState::DETACHED;
705 std::unique_ptr<SchedulerWorker> worker = SchedulerWorker::Create( 708 std::unique_ptr<SchedulerWorker> worker = SchedulerWorker::Create(
706 priority_hint, MakeUnique<SchedulerWorkerDelegateImpl>( 709 priority_hint,
707 this, re_enqueue_sequence_callback, 710 MakeUnique<SchedulerWorkerDelegateImpl>(
708 &shared_priority_queue_, static_cast<int>(i)), 711 this, re_enqueue_sequence_callback, &shared_priority_queue_, index),
709 task_tracker_, initial_state); 712 task_tracker_, initial_state);
710 if (!worker) 713 if (!worker)
711 break; 714 break;
712 idle_workers_stack_.Push(worker.get()); 715 idle_workers_stack_.Push(worker.get());
713 workers_.push_back(std::move(worker)); 716 workers_[index] = std::move(worker);
714 } 717 }
715 718
716 #if DCHECK_IS_ON() 719 #if DCHECK_IS_ON()
717 workers_created_.Signal(); 720 workers_created_.Signal();
718 #endif 721 #endif
719 722
720 return !workers_.empty(); 723 return !workers_.empty();
721 } 724 }
722 725
723 void SchedulerWorkerPoolImpl::WakeUpWorker(SchedulerWorker* worker) { 726 void SchedulerWorkerPoolImpl::WakeUpWorker(SchedulerWorker* worker) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 AutoSchedulerLock auto_lock(idle_workers_stack_lock_); 765 AutoSchedulerLock auto_lock(idle_workers_stack_lock_);
763 idle_workers_stack_.Remove(worker); 766 idle_workers_stack_.Remove(worker);
764 } 767 }
765 768
766 bool SchedulerWorkerPoolImpl::CanWorkerDetachForTesting() { 769 bool SchedulerWorkerPoolImpl::CanWorkerDetachForTesting() {
767 return !worker_detachment_disallowed_.IsSet(); 770 return !worker_detachment_disallowed_.IsSet();
768 } 771 }
769 772
770 } // namespace internal 773 } // namespace internal
771 } // namespace base 774 } // 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