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

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

Issue 2208493002: TaskScheduler: No BACKGROUND threads when unsupported. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + CR robliao #6 (nit) Created 4 years, 4 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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 std::unique_ptr<SchedulerWorkerPoolImpl> SchedulerWorkerPoolImpl::Create( 246 std::unique_ptr<SchedulerWorkerPoolImpl> SchedulerWorkerPoolImpl::Create(
247 const SchedulerWorkerPoolParams& params, 247 const SchedulerWorkerPoolParams& params,
248 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback, 248 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback,
249 TaskTracker* task_tracker, 249 TaskTracker* task_tracker,
250 DelayedTaskManager* delayed_task_manager) { 250 DelayedTaskManager* delayed_task_manager) {
251 std::unique_ptr<SchedulerWorkerPoolImpl> worker_pool( 251 std::unique_ptr<SchedulerWorkerPoolImpl> worker_pool(
252 new SchedulerWorkerPoolImpl(params.name(), 252 new SchedulerWorkerPoolImpl(params.name(),
253 params.io_restriction(), 253 params.io_restriction(),
254 params.suggested_reclaim_time(), 254 params.suggested_reclaim_time(),
255 task_tracker, delayed_task_manager)); 255 task_tracker, delayed_task_manager));
256 if (worker_pool->Initialize(params.thread_priority(), 256 if (worker_pool->Initialize(params.priority_hint(), params.max_threads(),
257 params.max_threads(),
258 re_enqueue_sequence_callback)) { 257 re_enqueue_sequence_callback)) {
259 return worker_pool; 258 return worker_pool;
260 } 259 }
261 return nullptr; 260 return nullptr;
262 } 261 }
263 262
264 void SchedulerWorkerPoolImpl::WaitForAllWorkersIdleForTesting() { 263 void SchedulerWorkerPoolImpl::WaitForAllWorkersIdleForTesting() {
265 AutoSchedulerLock auto_lock(idle_workers_stack_lock_); 264 AutoSchedulerLock auto_lock(idle_workers_stack_lock_);
266 while (idle_workers_stack_.Size() < workers_.size()) 265 while (idle_workers_stack_.Size() < workers_.size())
267 idle_workers_stack_cv_for_testing_->Wait(); 266 idle_workers_stack_cv_for_testing_->Wait();
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 workers_created_(WaitableEvent::ResetPolicy::MANUAL, 561 workers_created_(WaitableEvent::ResetPolicy::MANUAL,
563 WaitableEvent::InitialState::NOT_SIGNALED), 562 WaitableEvent::InitialState::NOT_SIGNALED),
564 #endif 563 #endif
565 task_tracker_(task_tracker), 564 task_tracker_(task_tracker),
566 delayed_task_manager_(delayed_task_manager) { 565 delayed_task_manager_(delayed_task_manager) {
567 DCHECK(task_tracker_); 566 DCHECK(task_tracker_);
568 DCHECK(delayed_task_manager_); 567 DCHECK(delayed_task_manager_);
569 } 568 }
570 569
571 bool SchedulerWorkerPoolImpl::Initialize( 570 bool SchedulerWorkerPoolImpl::Initialize(
572 ThreadPriority thread_priority, 571 ThreadPriority priority_hint,
573 size_t max_threads, 572 size_t max_threads,
574 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback) { 573 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback) {
575 AutoSchedulerLock auto_lock(idle_workers_stack_lock_); 574 AutoSchedulerLock auto_lock(idle_workers_stack_lock_);
576 575
577 DCHECK(workers_.empty()); 576 DCHECK(workers_.empty());
578 577
579 for (size_t i = 0; i < max_threads; ++i) { 578 for (size_t i = 0; i < max_threads; ++i) {
580 std::unique_ptr<SchedulerWorker> worker = 579 std::unique_ptr<SchedulerWorker> worker = SchedulerWorker::Create(
581 SchedulerWorker::Create( 580 priority_hint, WrapUnique(new SchedulerWorkerDelegateImpl(
582 thread_priority, WrapUnique(new SchedulerWorkerDelegateImpl( 581 this, re_enqueue_sequence_callback,
583 this, re_enqueue_sequence_callback, 582 &shared_priority_queue_, static_cast<int>(i))),
584 &shared_priority_queue_, static_cast<int>(i))), 583 task_tracker_, i == 0 ? SchedulerWorker::InitialState::ALIVE
585 task_tracker_, 584 : SchedulerWorker::InitialState::DETACHED);
586 i == 0
587 ? SchedulerWorker::InitialState::ALIVE
588 : SchedulerWorker::InitialState::DETACHED);
589 if (!worker) 585 if (!worker)
590 break; 586 break;
591 idle_workers_stack_.Push(worker.get()); 587 idle_workers_stack_.Push(worker.get());
592 workers_.push_back(std::move(worker)); 588 workers_.push_back(std::move(worker));
593 } 589 }
594 590
595 #if DCHECK_IS_ON() 591 #if DCHECK_IS_ON()
596 workers_created_.Signal(); 592 workers_created_.Signal();
597 #endif 593 #endif
598 594
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 AutoSchedulerLock auto_lock(idle_workers_stack_lock_); 631 AutoSchedulerLock auto_lock(idle_workers_stack_lock_);
636 idle_workers_stack_.Remove(worker); 632 idle_workers_stack_.Remove(worker);
637 } 633 }
638 634
639 bool SchedulerWorkerPoolImpl::CanWorkerDetachForTesting() { 635 bool SchedulerWorkerPoolImpl::CanWorkerDetachForTesting() {
640 return !worker_detachment_disallowed_.IsSet(); 636 return !worker_detachment_disallowed_.IsSet();
641 } 637 }
642 638
643 } // namespace internal 639 } // namespace internal
644 } // namespace base 640 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/scheduler_worker_pool_impl.h ('k') | base/task_scheduler/scheduler_worker_pool_params.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698