| Index: base/task_scheduler/task_scheduler_impl.cc
|
| diff --git a/base/task_scheduler/task_scheduler_impl.cc b/base/task_scheduler/task_scheduler_impl.cc
|
| index e5c8abf716306f8602b0cde8786e10dc292f1739..df6a8f98f35b01243d597579d2f7a32cb15a81ae 100644
|
| --- a/base/task_scheduler/task_scheduler_impl.cc
|
| +++ b/base/task_scheduler/task_scheduler_impl.cc
|
| @@ -24,6 +24,53 @@
|
| namespace base {
|
| namespace internal {
|
|
|
| +namespace {
|
| +
|
| +enum EnvironmentType {
|
| + BACKGROUND = 0,
|
| + BACKGROUND_BLOCKING,
|
| + FOREGROUND,
|
| + FOREGROUND_BLOCKING,
|
| + ENVIRONMENT_COUNT // Always last.
|
| +};
|
| +
|
| +// Order must match the EnvironmentType enum.
|
| +constexpr struct {
|
| + // The threads and histograms of this environment will be labeled with
|
| + // the task scheduler name concatenated to this.
|
| + const char* name_suffix;
|
| +
|
| + // Preferred priority for threads in this environment; the actual thread
|
| + // priority depends on shutdown state and platform capabilities.
|
| + ThreadPriority priority_hint;
|
| +
|
| + // Offset of the SchedulerWorkerPoolParams corresponding to this environement
|
| + // in TaskScheduler::InitParams. Enables creation of SchedulerWorkerPools from
|
| + // TaskScheduler::InitParams and |kEnvironmentParams| in a for loop.
|
| + size_t offset;
|
| +} kEnvironmentParams[] = {
|
| + {"Background", base::ThreadPriority::BACKGROUND,
|
| + offsetof(TaskScheduler::InitParams, background_worker_pool_params)},
|
| + {"BackgroundBlocking", base::ThreadPriority::BACKGROUND,
|
| + offsetof(TaskScheduler::InitParams,
|
| + background_blocking_worker_pool_params)},
|
| + {"Foreground", base::ThreadPriority::NORMAL,
|
| + offsetof(TaskScheduler::InitParams, foreground_worker_pool_params)},
|
| + {"ForegroundBlocking", base::ThreadPriority::NORMAL,
|
| + offsetof(TaskScheduler::InitParams,
|
| + foreground_blocking_worker_pool_params)},
|
| +};
|
| +
|
| +size_t GetEnvironmentIndexForTraits(const TaskTraits& traits) {
|
| + const bool is_background =
|
| + traits.priority() == base::TaskPriority::BACKGROUND;
|
| + if (traits.may_block() || traits.with_base_sync_primitives())
|
| + return is_background ? BACKGROUND_BLOCKING : FOREGROUND_BLOCKING;
|
| + return is_background ? BACKGROUND : FOREGROUND;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| // static
|
| std::unique_ptr<TaskSchedulerImpl> TaskSchedulerImpl::Create(
|
| const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector,
|
| @@ -35,6 +82,31 @@ std::unique_ptr<TaskSchedulerImpl> TaskSchedulerImpl::Create(
|
| return scheduler;
|
| }
|
|
|
| +// static
|
| +std::unique_ptr<TaskSchedulerImpl> TaskSchedulerImpl::Create(
|
| + const std::string& name,
|
| + const TaskScheduler::InitParams& init_params) {
|
| + // Create a vector of SchedulerWorkerPoolParams using names and priority hints
|
| + // derived from |kEnvironmentParams| and other params from |init_params|.
|
| + std::vector<SchedulerWorkerPoolParams> worker_pool_params_vector;
|
| + for (const auto& environment_params : kEnvironmentParams) {
|
| + const SchedulerWorkerPoolParams& worker_pool_params_in =
|
| + *reinterpret_cast<const SchedulerWorkerPoolParams*>(
|
| + reinterpret_cast<uintptr_t>(&init_params) +
|
| + environment_params.offset);
|
| + worker_pool_params_vector.emplace_back(
|
| + name + environment_params.name_suffix, environment_params.priority_hint,
|
| + worker_pool_params_in.standby_thread_policy(),
|
| + worker_pool_params_in.max_threads(),
|
| + worker_pool_params_in.suggested_reclaim_time(),
|
| + worker_pool_params_in.backward_compatibility());
|
| + }
|
| + DCHECK_EQ(static_cast<size_t>(ENVIRONMENT_COUNT),
|
| + worker_pool_params_vector.size());
|
| +
|
| + return Create(worker_pool_params_vector, Bind(&GetEnvironmentIndexForTraits));
|
| +}
|
| +
|
| TaskSchedulerImpl::~TaskSchedulerImpl() {
|
| #if DCHECK_IS_ON()
|
| DCHECK(join_for_testing_returned_.IsSet());
|
|
|