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

Unified Diff: base/task_scheduler/scheduler_worker_pool_impl.cc

Issue 2501763002: Add Thread Standby Policy SchedulerWorkerPoolImpl (Closed)
Patch Set: Rebase to edc7bea Created 4 years, 1 month 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
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 f15cc937c7122d62b05335de9644c38ee907be50..f2d69344f4cfb6da35f4932b6ad3aa4ba0d7d739 100644
--- a/base/task_scheduler/scheduler_worker_pool_impl.cc
+++ b/base/task_scheduler/scheduler_worker_pool_impl.cc
@@ -313,8 +313,9 @@ std::unique_ptr<SchedulerWorkerPoolImpl> SchedulerWorkerPoolImpl::Create(
params.io_restriction(),
params.suggested_reclaim_time(),
task_tracker, delayed_task_manager));
- if (worker_pool->Initialize(params.priority_hint(), params.max_threads(),
- re_enqueue_sequence_callback)) {
+ if (worker_pool->Initialize(
+ params.priority_hint(), params.standby_thread_policy(),
+ params.max_threads(), re_enqueue_sequence_callback)) {
return worker_pool;
}
return nullptr;
@@ -452,6 +453,15 @@ void SchedulerWorkerPoolImpl::DisallowWorkerDetachmentForTesting() {
worker_detachment_disallowed_.Set();
}
+size_t SchedulerWorkerPoolImpl::NumberOfAliveWorkersForTesting() {
+ size_t num_alive_workers = 0;
+ for (const auto& worker : workers_) {
+ if (worker->ThreadAliveForTesting())
+ ++num_alive_workers;
+ }
+ return num_alive_workers;
+}
+
SchedulerWorkerPoolImpl::SchedulerSingleThreadTaskRunner::
SchedulerSingleThreadTaskRunner(const TaskTraits& traits,
SchedulerWorkerPool* worker_pool,
@@ -716,6 +726,7 @@ SchedulerWorkerPoolImpl::SchedulerWorkerPoolImpl(
bool SchedulerWorkerPoolImpl::Initialize(
ThreadPriority priority_hint,
+ SchedulerWorkerPoolParams::StandbyThreadPolicy standby_thread_policy,
size_t max_threads,
const ReEnqueueSequenceCallback& re_enqueue_sequence_callback) {
AutoSchedulerLock auto_lock(idle_workers_stack_lock_);
@@ -727,9 +738,13 @@ bool SchedulerWorkerPoolImpl::Initialize(
// 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 bool is_standby_lazy =
+ standby_thread_policy ==
+ SchedulerWorkerPoolParams::StandbyThreadPolicy::LAZY;
const SchedulerWorker::InitialState initial_state =
- (index == 0) ? SchedulerWorker::InitialState::ALIVE
- : SchedulerWorker::InitialState::DETACHED;
+ (index == 0 && !is_standby_lazy)
+ ? SchedulerWorker::InitialState::ALIVE
+ : SchedulerWorker::InitialState::DETACHED;
std::unique_ptr<SchedulerWorker> worker = SchedulerWorker::Create(
priority_hint,
MakeUnique<SchedulerWorkerDelegateImpl>(
@@ -752,6 +767,8 @@ void SchedulerWorkerPoolImpl::WakeUpWorker(SchedulerWorker* worker) {
DCHECK(worker);
RemoveFromIdleWorkersStack(worker);
worker->WakeUp();
+ // TOOD(robliao): Honor StandbyThreadPolicy::ONE here and consider adding
+ // hysteresis to the CanDetach check. See https://crbug.com/666041.
}
void SchedulerWorkerPoolImpl::WakeUpOneWorker() {
« 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