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

Unified Diff: base/task_scheduler/task_scheduler.cc

Issue 2791423003: Initialize TaskScheduler with InitParams in CreateAndSetSimpleTaskScheduler(). (Closed)
Patch Set: CR-robliao-10 Created 3 years, 8 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/task_scheduler.cc
diff --git a/base/task_scheduler/task_scheduler.cc b/base/task_scheduler/task_scheduler.cc
index bff2de65a422e5be152e8d4b1b29f9233fd127da..0e621f122263dfc2089363c36c03672d8cd83eaa 100644
--- a/base/task_scheduler/task_scheduler.cc
+++ b/base/task_scheduler/task_scheduler.cc
@@ -40,16 +40,29 @@ TaskScheduler::InitParams::~InitParams() = default;
#if !defined(OS_NACL)
// static
void TaskScheduler::CreateAndSetSimpleTaskScheduler(const std::string& name) {
- constexpr int kMinNumThreads = 1;
- std::vector<SchedulerWorkerPoolParams> worker_pool_params_vector;
- worker_pool_params_vector.emplace_back(
- name, ThreadPriority::NORMAL,
- SchedulerWorkerPoolParams::StandbyThreadPolicy::LAZY,
- std::max(kMinNumThreads, SysInfo::NumberOfProcessors()),
- TimeDelta::FromSeconds(30));
+ using StandbyThreadPolicy = SchedulerWorkerPoolParams::StandbyThreadPolicy;
+
+ // Values were chosen so that:
+ // * There are few background threads.
+ // * Background threads never outnumber foreground threads.
+ // * The system is utilized maximally by foreground threads.
+ const int num_cores = SysInfo::NumberOfProcessors();
+ constexpr int kBackgroundMaxThreads = 1;
+ constexpr int kBackgroundBlockingMaxThreads = 2;
+ const int kForegroundMaxThreads = std::max(1, num_cores);
+ const int kForegroundBlockingMaxThreads = std::max(2, num_cores);
+
+ constexpr TimeDelta kSuggestedReclaimTime = TimeDelta::FromSeconds(30);
+
CreateAndSetDefaultTaskScheduler(
- worker_pool_params_vector,
- Bind([](const TaskTraits&) -> size_t { return 0; }));
+ name, {{StandbyThreadPolicy::LAZY, kBackgroundMaxThreads,
+ kSuggestedReclaimTime},
+ {StandbyThreadPolicy::LAZY, kBackgroundBlockingMaxThreads,
+ kSuggestedReclaimTime},
+ {StandbyThreadPolicy::LAZY, kForegroundMaxThreads,
+ kSuggestedReclaimTime},
+ {StandbyThreadPolicy::LAZY, kForegroundBlockingMaxThreads,
+ kSuggestedReclaimTime}});
}
#endif // !defined(OS_NACL)
« 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