blob: aa0ea112daadcd4b91b3dccf1dc3303c5f59aada [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2018 The Chromium Authors
Leszek Swirski2987cc82018-11-05 15:19:282// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BASE_TASK_TASK_FEATURES_H_
6#define BASE_TASK_TASK_FEATURES_H_
7
8#include "base/base_export.h"
Anthony Vallee-Dubois9dbbbda32022-08-26 01:25:319#include "base/feature_list.h"
Etienne Pierre-Dorayd6b575b22018-11-21 19:32:2910#include "base/metrics/field_trial_params.h"
Aditya Keerthia41eda52019-04-01 15:03:2511#include "build/build_config.h"
Leszek Swirski2987cc82018-11-05 15:19:2812
13namespace base {
14
Edgar Arriagad096f402023-05-02 15:39:2415// Amount of threads that will be system-wide restricted from being used
16// by thread pools.
17BASE_EXPORT BASE_DECLARE_FEATURE(kThreadPoolCap);
18
19extern const BASE_EXPORT base::FeatureParam<int> kThreadPoolCapRestrictedCount;
20
Zhibo Wangf8950ab62022-12-09 05:33:4221// Under this feature, a utility_thread_group will be created for
22// running USER_VISIBLE tasks.
23BASE_EXPORT BASE_DECLARE_FEATURE(kUseUtilityThreadGroup);
24
Etienne Pierre-dorayb2895232022-08-30 18:15:0325// Under this feature, worker threads are not reclaimed after a timeout. Rather,
26// only excess workers are cleaned up immediately after finishing a task.
Daniel Cheng0fff5c232022-09-21 17:43:3427BASE_EXPORT BASE_DECLARE_FEATURE(kNoWorkerThreadReclaim);
Francois Doraya20b6df22019-06-27 15:04:1928
Patrick Monette6497eae2022-08-09 17:59:5829// This feature controls whether wake ups are possible for canceled tasks.
Daniel Cheng0fff5c232022-09-21 17:43:3430BASE_EXPORT BASE_DECLARE_FEATURE(kNoWakeUpsForCanceledTasks);
Patrick Monette6497eae2022-08-09 17:59:5831
Patrick Monetteeaaa2382021-12-08 17:06:5932// Controls whether or not canceled delayed tasks are removed from task queues.
Daniel Cheng0fff5c232022-09-21 17:43:3433BASE_EXPORT BASE_DECLARE_FEATURE(kRemoveCanceledTasksInTaskQueue);
Patrick Monetteeaaa2382021-12-08 17:06:5934
Patrick Monette4efba9c2022-08-18 16:41:3235// This feature controls whether or not the scheduled task is always abandoned
36// when a timer is stopped or reset. The re-use of the scheduled task is an
37// optimization that ensures a timer can not leave multiple canceled tasks in
38// the task queue. Meant to be used in conjunction with
39// kRemoveCanceledTasksInTaskQueue.
Daniel Cheng0fff5c232022-09-21 17:43:3440BASE_EXPORT BASE_DECLARE_FEATURE(kAlwaysAbandonScheduledTask);
Patrick Monette4efba9c2022-08-18 16:41:3241
Gabriel Charettedfad5992022-10-28 17:57:1742// This feature controls whether ThreadPool WorkerThreads should hold off waking
43// up to purge partition alloc within the first minute of their lifetime. See
44// base::internal::GetSleepTimeBeforePurge.
45BASE_EXPORT BASE_DECLARE_FEATURE(kDelayFirstWorkerWake);
46
Etienne Pierre-doraya8792732022-02-05 02:27:2547// Under this feature, a non-zero leeway is added to delayed tasks. Along with
48// DelayPolicy, this affects the time at which a delayed task runs.
Daniel Cheng0fff5c232022-09-21 17:43:3449BASE_EXPORT BASE_DECLARE_FEATURE(kAddTaskLeewayFeature);
Jiahe Zhang07cf33132022-08-09 09:42:4950constexpr TimeDelta kDefaultLeeway = Milliseconds(8);
Etienne Pierre-doraya8792732022-02-05 02:27:2551extern const BASE_EXPORT base::FeatureParam<TimeDelta> kTaskLeewayParam;
52
Jiahe Zhang07cf33132022-08-09 09:42:4953// Under this feature, wake ups are aligned at a 8ms boundary when allowed per
Etienne Pierre-doray048472eb2022-02-07 16:24:4854// DelayPolicy.
Daniel Cheng0fff5c232022-09-21 17:43:3455BASE_EXPORT BASE_DECLARE_FEATURE(kAlignWakeUps);
Etienne Pierre-doray048472eb2022-02-07 16:24:4856
Etienne Pierre-dorayae2c15a2022-04-29 18:50:5957// Under this feature, tasks that need high resolution timer are determined
58// based on explicit DelayPolicy rather than based on a threshold.
Daniel Cheng0fff5c232022-09-21 17:43:3459BASE_EXPORT BASE_DECLARE_FEATURE(kExplicitHighResolutionTimerWin);
Etienne Pierre-dorayae2c15a2022-04-29 18:50:5960
Alex Attar9fcc01e2022-05-20 14:01:2761// Feature to run tasks by batches before pumping out messages.
Daniel Cheng0fff5c232022-09-21 17:43:3462BASE_EXPORT BASE_DECLARE_FEATURE(kRunTasksByBatches);
Alex Attar9fcc01e2022-05-20 14:01:2763
Jiahe Zhang07cf33132022-08-09 09:42:4964BASE_EXPORT void InitializeTaskLeeway();
Jiahe Zhangce46f4cb2022-11-22 03:12:0265BASE_EXPORT TimeDelta GetTaskLeewayForCurrentThread();
66BASE_EXPORT TimeDelta GetDefaultTaskLeeway();
Jiahe Zhang07cf33132022-08-09 09:42:4967
Etienne Pierre-doraye9957c9c2023-03-15 20:54:1668// Controls the max number of delayed tasks that can run before selecting an
69// immediate task in sequence manager.
70BASE_EXPORT BASE_DECLARE_FEATURE(kMaxDelayedStarvationTasks);
71extern const BASE_EXPORT base::FeatureParam<int>
72 kMaxDelayedStarvationTasksParam;
73
Leszek Swirski2987cc82018-11-05 15:19:2874} // namespace base
75
76#endif // BASE_TASK_TASK_FEATURES_H_