| Index: base/task_scheduler/task_scheduler.cc
|
| diff --git a/base/task_scheduler/task_scheduler.cc b/base/task_scheduler/task_scheduler.cc
|
| index 592d6f4a15ecb97f79f890cbd66ee9001c82f596..7a323d63fc152222e30dc573e6e6af1efa2e0194 100644
|
| --- a/base/task_scheduler/task_scheduler.cc
|
| +++ b/base/task_scheduler/task_scheduler.cc
|
| @@ -4,11 +4,8 @@
|
|
|
| #include "base/task_scheduler/task_scheduler.h"
|
|
|
| -#include <algorithm>
|
| -
|
| -#include "base/bind.h"
|
| #include "base/logging.h"
|
| -#include "base/sys_info.h"
|
| +#include "base/task_scheduler/initialization_util.h"
|
| #include "base/task_scheduler/scheduler_worker_pool_params.h"
|
| #include "base/task_scheduler/task_scheduler_impl.h"
|
| #include "base/threading/platform_thread.h"
|
| @@ -23,29 +20,68 @@ TaskScheduler* g_task_scheduler = nullptr;
|
|
|
| } // namespace
|
|
|
| +TaskSchedulerInitParams::TaskSchedulerInitParams(
|
| + const SchedulerWorkerPoolParams& background_worker_pool_params_in,
|
| + const SchedulerWorkerPoolParams& background_blocking_worker_pool_params_in,
|
| + const SchedulerWorkerPoolParams& foreground_worker_pool_params_in,
|
| + const SchedulerWorkerPoolParams& foreground_blocking_worker_pool_params_in)
|
| + : background_worker_pool_params(background_worker_pool_params_in),
|
| + background_blocking_worker_pool_params(
|
| + background_blocking_worker_pool_params_in),
|
| + foreground_worker_pool_params(foreground_worker_pool_params_in),
|
| + foreground_blocking_worker_pool_params(
|
| + foreground_blocking_worker_pool_params_in) {}
|
| +
|
| +bool TaskSchedulerInitParams::IsValid() const {
|
| + return background_worker_pool_params.IsValid() &&
|
| + background_blocking_worker_pool_params.IsValid() &&
|
| + foreground_worker_pool_params.IsValid() &&
|
| + foreground_blocking_worker_pool_params.IsValid();
|
| +}
|
| +
|
| #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, base::SysInfo::NumberOfProcessors()),
|
| - TimeDelta::FromSeconds(30));
|
| + using StandbyThreadPolicy = SchedulerWorkerPoolParams::StandbyThreadPolicy;
|
| +
|
| + constexpr TimeDelta kSuggestedReclaimTime = TimeDelta::FromSeconds(30);
|
| + constexpr int kMaxNumBackgroundThreads = 1;
|
| + constexpr int kMaxNumBackgroundBlockingThreads = 2;
|
| + constexpr int kMaxNumForegroundThreadsLowerBound = 2;
|
| + constexpr int kMaxNumForegroundThreadsUpperBound = 32;
|
| + constexpr double kMaxNumForegroundThreadsCoresMultiplier = 1;
|
| + constexpr int kMaxNumForegroundThreadsOffset = 0;
|
| + constexpr int kMaxNumForegroundBlockingThreadsLowerBound = 2;
|
| + constexpr int kMaxNumForegroundBlockingThreadsUpperBound = 64;
|
| + constexpr double kMaxNumForegroundBlockingThreadsCoresMultiplier = 2;
|
| + constexpr int kMaxNumForegroundBlockingThreadsOffset = 0;
|
| +
|
| CreateAndSetDefaultTaskScheduler(
|
| - worker_pool_params_vector,
|
| - Bind([](const TaskTraits&) -> size_t { return 0; }));
|
| + name, {{StandbyThreadPolicy::LAZY, kMaxNumBackgroundThreads,
|
| + kSuggestedReclaimTime},
|
| + {StandbyThreadPolicy::LAZY, kMaxNumBackgroundBlockingThreads,
|
| + kSuggestedReclaimTime},
|
| + {StandbyThreadPolicy::LAZY,
|
| + RecommendedMaxNumberOfThreadsInPool(
|
| + kMaxNumForegroundThreadsLowerBound,
|
| + kMaxNumForegroundThreadsUpperBound,
|
| + kMaxNumForegroundThreadsCoresMultiplier,
|
| + kMaxNumForegroundThreadsOffset),
|
| + kSuggestedReclaimTime},
|
| + {StandbyThreadPolicy::LAZY,
|
| + RecommendedMaxNumberOfThreadsInPool(
|
| + kMaxNumForegroundBlockingThreadsLowerBound,
|
| + kMaxNumForegroundBlockingThreadsUpperBound,
|
| + kMaxNumForegroundBlockingThreadsCoresMultiplier,
|
| + kMaxNumForegroundBlockingThreadsOffset),
|
| + kSuggestedReclaimTime}});
|
| }
|
| #endif // !defined(OS_NACL)
|
|
|
| -// static
|
| void TaskScheduler::CreateAndSetDefaultTaskScheduler(
|
| - const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector,
|
| - const WorkerPoolIndexForTraitsCallback&
|
| - worker_pool_index_for_traits_callback) {
|
| - SetInstance(internal::TaskSchedulerImpl::Create(
|
| - worker_pool_params_vector, worker_pool_index_for_traits_callback));
|
| + const std::string& name,
|
| + const TaskSchedulerInitParams& init_params) {
|
| + SetInstance(internal::TaskSchedulerImpl::Create(name, init_params));
|
| }
|
|
|
| // static
|
|
|