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

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

Issue 2749303002: [reference - do not submit] Always create four pools in TaskSchedulerImpl. (Closed)
Patch Set: rebase Created 3 years, 9 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
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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 }; 192 };
193 193
194 SchedulerWorkerPoolImpl::~SchedulerWorkerPoolImpl() { 194 SchedulerWorkerPoolImpl::~SchedulerWorkerPoolImpl() {
195 // SchedulerWorkerPool should never be deleted in production unless its 195 // SchedulerWorkerPool should never be deleted in production unless its
196 // initialization failed. 196 // initialization failed.
197 DCHECK(join_for_testing_returned_.IsSignaled() || workers_.empty()); 197 DCHECK(join_for_testing_returned_.IsSignaled() || workers_.empty());
198 } 198 }
199 199
200 // static 200 // static
201 std::unique_ptr<SchedulerWorkerPoolImpl> SchedulerWorkerPoolImpl::Create( 201 std::unique_ptr<SchedulerWorkerPoolImpl> SchedulerWorkerPoolImpl::Create(
202 const std::string& name,
203 ThreadPriority priority_hint,
202 const SchedulerWorkerPoolParams& params, 204 const SchedulerWorkerPoolParams& params,
203 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback, 205 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback,
204 TaskTracker* task_tracker, 206 TaskTracker* task_tracker,
205 DelayedTaskManager* delayed_task_manager) { 207 DelayedTaskManager* delayed_task_manager) {
206 auto worker_pool = WrapUnique( 208 auto worker_pool = WrapUnique(new SchedulerWorkerPoolImpl(
207 new SchedulerWorkerPoolImpl(params, task_tracker, delayed_task_manager)); 209 name, params, task_tracker, delayed_task_manager));
208 if (worker_pool->Initialize(params, re_enqueue_sequence_callback)) 210 if (worker_pool->Initialize(priority_hint, params,
211 re_enqueue_sequence_callback)) {
209 return worker_pool; 212 return worker_pool;
213 }
210 return nullptr; 214 return nullptr;
211 } 215 }
212 216
213 scoped_refptr<TaskRunner> SchedulerWorkerPoolImpl::CreateTaskRunnerWithTraits( 217 scoped_refptr<TaskRunner> SchedulerWorkerPoolImpl::CreateTaskRunnerWithTraits(
214 const TaskTraits& traits) { 218 const TaskTraits& traits) {
215 return make_scoped_refptr(new SchedulerParallelTaskRunner(traits, this)); 219 return make_scoped_refptr(new SchedulerParallelTaskRunner(traits, this));
216 } 220 }
217 221
218 scoped_refptr<SequencedTaskRunner> 222 scoped_refptr<SequencedTaskRunner>
219 SchedulerWorkerPoolImpl::CreateSequencedTaskRunnerWithTraits( 223 SchedulerWorkerPoolImpl::CreateSequencedTaskRunnerWithTraits(
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 461
458 void SchedulerWorkerPoolImpl::SchedulerWorkerDelegateImpl::OnDetach() { 462 void SchedulerWorkerPoolImpl::SchedulerWorkerDelegateImpl::OnDetach() {
459 DCHECK(!did_detach_since_last_get_work_); 463 DCHECK(!did_detach_since_last_get_work_);
460 outer_->num_tasks_before_detach_histogram_->Add(num_tasks_since_last_detach_); 464 outer_->num_tasks_before_detach_histogram_->Add(num_tasks_since_last_detach_);
461 num_tasks_since_last_detach_ = 0; 465 num_tasks_since_last_detach_ = 0;
462 did_detach_since_last_get_work_ = true; 466 did_detach_since_last_get_work_ = true;
463 last_detach_time_ = TimeTicks::Now(); 467 last_detach_time_ = TimeTicks::Now();
464 } 468 }
465 469
466 SchedulerWorkerPoolImpl::SchedulerWorkerPoolImpl( 470 SchedulerWorkerPoolImpl::SchedulerWorkerPoolImpl(
471 const std::string& name,
467 const SchedulerWorkerPoolParams& params, 472 const SchedulerWorkerPoolParams& params,
468 TaskTracker* task_tracker, 473 TaskTracker* task_tracker,
469 DelayedTaskManager* delayed_task_manager) 474 DelayedTaskManager* delayed_task_manager)
470 : name_(params.name()), 475 : name_(name),
471 suggested_reclaim_time_(params.suggested_reclaim_time()), 476 suggested_reclaim_time_(params.suggested_reclaim_time()),
472 idle_workers_stack_lock_(shared_priority_queue_.container_lock()), 477 idle_workers_stack_lock_(shared_priority_queue_.container_lock()),
473 idle_workers_stack_cv_for_testing_( 478 idle_workers_stack_cv_for_testing_(
474 idle_workers_stack_lock_.CreateConditionVariable()), 479 idle_workers_stack_lock_.CreateConditionVariable()),
475 join_for_testing_returned_(WaitableEvent::ResetPolicy::MANUAL, 480 join_for_testing_returned_(WaitableEvent::ResetPolicy::MANUAL,
476 WaitableEvent::InitialState::NOT_SIGNALED), 481 WaitableEvent::InitialState::NOT_SIGNALED),
477 #if DCHECK_IS_ON() 482 #if DCHECK_IS_ON()
478 workers_created_(WaitableEvent::ResetPolicy::MANUAL, 483 workers_created_(WaitableEvent::ResetPolicy::MANUAL,
479 WaitableEvent::InitialState::NOT_SIGNALED), 484 WaitableEvent::InitialState::NOT_SIGNALED),
480 #endif 485 #endif
(...skipping 23 matching lines...) Expand all
504 100, 509 100,
505 50, 510 50,
506 HistogramBase::kUmaTargetedHistogramFlag)), 511 HistogramBase::kUmaTargetedHistogramFlag)),
507 task_tracker_(task_tracker), 512 task_tracker_(task_tracker),
508 delayed_task_manager_(delayed_task_manager) { 513 delayed_task_manager_(delayed_task_manager) {
509 DCHECK(task_tracker_); 514 DCHECK(task_tracker_);
510 DCHECK(delayed_task_manager_); 515 DCHECK(delayed_task_manager_);
511 } 516 }
512 517
513 bool SchedulerWorkerPoolImpl::Initialize( 518 bool SchedulerWorkerPoolImpl::Initialize(
519 ThreadPriority priority_hint,
514 const SchedulerWorkerPoolParams& params, 520 const SchedulerWorkerPoolParams& params,
515 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback) { 521 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback) {
516 AutoSchedulerLock auto_lock(idle_workers_stack_lock_); 522 AutoSchedulerLock auto_lock(idle_workers_stack_lock_);
517 523
518 DCHECK(workers_.empty()); 524 DCHECK(workers_.empty());
519 workers_.resize(params.max_threads()); 525 workers_.resize(params.max_threads());
520 526
521 // Create workers and push them to the idle stack in reverse order of index. 527 // Create workers and push them to the idle stack in reverse order of index.
522 // This ensures that they are woken up in order of index and that the ALIVE 528 // This ensures that they are woken up in order of index and that the ALIVE
523 // worker is on top of the stack. 529 // worker is on top of the stack.
524 for (int index = params.max_threads() - 1; index >= 0; --index) { 530 for (int index = params.max_threads() - 1; index >= 0; --index) {
525 const bool is_standby_lazy = 531 const bool is_standby_lazy =
526 params.standby_thread_policy() == 532 params.standby_thread_policy() ==
527 SchedulerWorkerPoolParams::StandbyThreadPolicy::LAZY; 533 SchedulerWorkerPoolParams::StandbyThreadPolicy::LAZY;
528 const SchedulerWorker::InitialState initial_state = 534 const SchedulerWorker::InitialState initial_state =
529 (index == 0 && !is_standby_lazy) 535 (index == 0 && !is_standby_lazy)
530 ? SchedulerWorker::InitialState::ALIVE 536 ? SchedulerWorker::InitialState::ALIVE
531 : SchedulerWorker::InitialState::DETACHED; 537 : SchedulerWorker::InitialState::DETACHED;
532 scoped_refptr<SchedulerWorker> worker = SchedulerWorker::Create( 538 scoped_refptr<SchedulerWorker> worker = SchedulerWorker::Create(
533 params.priority_hint(), 539 priority_hint,
534 MakeUnique<SchedulerWorkerDelegateImpl>( 540 MakeUnique<SchedulerWorkerDelegateImpl>(
535 this, re_enqueue_sequence_callback, index), 541 this, re_enqueue_sequence_callback, index),
536 task_tracker_, initial_state, params.backward_compatibility()); 542 task_tracker_, initial_state, params.backward_compatibility());
537 if (!worker) 543 if (!worker)
538 break; 544 break;
539 idle_workers_stack_.Push(worker.get()); 545 idle_workers_stack_.Push(worker.get());
540 workers_[index] = std::move(worker); 546 workers_[index] = std::move(worker);
541 } 547 }
542 548
543 #if DCHECK_IS_ON() 549 #if DCHECK_IS_ON()
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 AutoSchedulerLock auto_lock(idle_workers_stack_lock_); 591 AutoSchedulerLock auto_lock(idle_workers_stack_lock_);
586 idle_workers_stack_.Remove(worker); 592 idle_workers_stack_.Remove(worker);
587 } 593 }
588 594
589 bool SchedulerWorkerPoolImpl::CanWorkerDetachForTesting() { 595 bool SchedulerWorkerPoolImpl::CanWorkerDetachForTesting() {
590 return !worker_detachment_disallowed_.IsSet(); 596 return !worker_detachment_disallowed_.IsSet();
591 } 597 }
592 598
593 } // namespace internal 599 } // namespace internal
594 } // namespace base 600 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/scheduler_worker_pool_impl.h ('k') | base/task_scheduler/scheduler_worker_pool_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698