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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/task_scheduler/scheduler_worker_pool_impl.cc
diff --git a/base/task_scheduler/scheduler_worker_pool_impl.cc b/base/task_scheduler/scheduler_worker_pool_impl.cc
index d0c5dd2a97dedf0522820a2494e61389c0a19536..19833c812d9819c625d980725d5992b5c3e7e07c 100644
--- a/base/task_scheduler/scheduler_worker_pool_impl.cc
+++ b/base/task_scheduler/scheduler_worker_pool_impl.cc
@@ -696,21 +696,24 @@ bool SchedulerWorkerPoolImpl::Initialize(
AutoSchedulerLock auto_lock(idle_workers_stack_lock_);
DCHECK(workers_.empty());
+ workers_.resize(max_threads);
- for (size_t i = 0; i < max_threads; ++i) {
- // The last SchedulerWorker added to the idle stack should be ALIVE.
+ // Create workers and push them to the idle stack in reverse order of index.
+ // This ensures that they are woken up in order of index and that the ALIVE
+ // worker is on top of the stack.
+ for (int index = max_threads - 1; index >= 0; --index) {
const SchedulerWorker::InitialState initial_state =
- (i == max_threads - 1) ? SchedulerWorker::InitialState::ALIVE
- : SchedulerWorker::InitialState::DETACHED;
+ (index == 0) ? SchedulerWorker::InitialState::ALIVE
+ : SchedulerWorker::InitialState::DETACHED;
std::unique_ptr<SchedulerWorker> worker = SchedulerWorker::Create(
- priority_hint, MakeUnique<SchedulerWorkerDelegateImpl>(
- this, re_enqueue_sequence_callback,
- &shared_priority_queue_, static_cast<int>(i)),
+ priority_hint,
+ MakeUnique<SchedulerWorkerDelegateImpl>(
+ this, re_enqueue_sequence_callback, &shared_priority_queue_, index),
task_tracker_, initial_state);
if (!worker)
break;
idle_workers_stack_.Push(worker.get());
- workers_.push_back(std::move(worker));
+ workers_[index] = std::move(worker);
}
#if DCHECK_IS_ON()
« 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