Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors |
Leszek Swirski | 2987cc8 | 2018-11-05 15:19:28 | [diff] [blame] | 2 | // 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-Dubois | 9dbbbda3 | 2022-08-26 01:25:31 | [diff] [blame] | 9 | #include "base/feature_list.h" |
Etienne Pierre-Doray | d6b575b2 | 2018-11-21 19:32:29 | [diff] [blame] | 10 | #include "base/metrics/field_trial_params.h" |
Aditya Keerthi | a41eda5 | 2019-04-01 15:03:25 | [diff] [blame] | 11 | #include "build/build_config.h" |
Leszek Swirski | 2987cc8 | 2018-11-05 15:19:28 | [diff] [blame] | 12 | |
| 13 | namespace base { |
| 14 | |
Xiaohan Wang | bba17e2 | 2022-01-15 17:58:14 | [diff] [blame] | 15 | #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE) |
Francois Doray | 7f77731 | 2019-05-16 12:26:31 | [diff] [blame] | 16 | #define HAS_NATIVE_THREAD_POOL() 1 |
| 17 | #else |
| 18 | #define HAS_NATIVE_THREAD_POOL() 0 |
| 19 | #endif |
| 20 | |
| 21 | #if HAS_NATIVE_THREAD_POOL() |
Francois Doray | ee4a553 | 2021-03-30 00:17:17 | [diff] [blame] | 22 | // Under this feature, ThreadPoolImpl will use a foreground ThreadGroup backed |
| 23 | // by a native thread pool implementation. The Windows Thread Pool API and |
Aditya Keerthi | a41eda5 | 2019-04-01 15:03:25 | [diff] [blame] | 24 | // libdispatch are used on Windows and macOS/iOS respectively. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame^] | 25 | BASE_EXPORT BASE_DECLARE_FEATURE(kUseNativeThreadPool); |
Francois Doray | ee4a553 | 2021-03-30 00:17:17 | [diff] [blame] | 26 | // Under this feature, ThreadPoolImpl will use a background ThreadGroup backed |
| 27 | // by a native thread pool implementation. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame^] | 28 | BASE_EXPORT BASE_DECLARE_FEATURE(kUseBackgroundNativeThreadPool); |
Aditya Keerthi | a41eda5 | 2019-04-01 15:03:25 | [diff] [blame] | 29 | #endif |
| 30 | |
Etienne Pierre-doray | b289523 | 2022-08-30 18:15:03 | [diff] [blame] | 31 | // Under this feature, worker threads are not reclaimed after a timeout. Rather, |
| 32 | // only excess workers are cleaned up immediately after finishing a task. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame^] | 33 | BASE_EXPORT BASE_DECLARE_FEATURE(kNoWorkerThreadReclaim); |
Francois Doray | a20b6df2 | 2019-06-27 15:04:19 | [diff] [blame] | 34 | |
Patrick Monette | 6497eae | 2022-08-09 17:59:58 | [diff] [blame] | 35 | // This feature controls whether wake ups are possible for canceled tasks. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame^] | 36 | BASE_EXPORT BASE_DECLARE_FEATURE(kNoWakeUpsForCanceledTasks); |
Patrick Monette | 6497eae | 2022-08-09 17:59:58 | [diff] [blame] | 37 | |
Patrick Monette | eaaa238 | 2021-12-08 17:06:59 | [diff] [blame] | 38 | // Controls whether or not canceled delayed tasks are removed from task queues. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame^] | 39 | BASE_EXPORT BASE_DECLARE_FEATURE(kRemoveCanceledTasksInTaskQueue); |
Patrick Monette | eaaa238 | 2021-12-08 17:06:59 | [diff] [blame] | 40 | |
Patrick Monette | 4efba9c | 2022-08-18 16:41:32 | [diff] [blame] | 41 | // This feature controls whether or not the scheduled task is always abandoned |
| 42 | // when a timer is stopped or reset. The re-use of the scheduled task is an |
| 43 | // optimization that ensures a timer can not leave multiple canceled tasks in |
| 44 | // the task queue. Meant to be used in conjunction with |
| 45 | // kRemoveCanceledTasksInTaskQueue. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame^] | 46 | BASE_EXPORT BASE_DECLARE_FEATURE(kAlwaysAbandonScheduledTask); |
Patrick Monette | 4efba9c | 2022-08-18 16:41:32 | [diff] [blame] | 47 | |
Etienne Pierre-doray | a879273 | 2022-02-05 02:27:25 | [diff] [blame] | 48 | // Under this feature, a non-zero leeway is added to delayed tasks. Along with |
| 49 | // DelayPolicy, this affects the time at which a delayed task runs. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame^] | 50 | BASE_EXPORT BASE_DECLARE_FEATURE(kAddTaskLeewayFeature); |
Jiahe Zhang | 07cf3313 | 2022-08-09 09:42:49 | [diff] [blame] | 51 | constexpr TimeDelta kDefaultLeeway = Milliseconds(8); |
Etienne Pierre-doray | a879273 | 2022-02-05 02:27:25 | [diff] [blame] | 52 | extern const BASE_EXPORT base::FeatureParam<TimeDelta> kTaskLeewayParam; |
| 53 | |
Jiahe Zhang | 07cf3313 | 2022-08-09 09:42:49 | [diff] [blame] | 54 | // Under this feature, wake ups are aligned at a 8ms boundary when allowed per |
Etienne Pierre-doray | 048472eb | 2022-02-07 16:24:48 | [diff] [blame] | 55 | // DelayPolicy. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame^] | 56 | BASE_EXPORT BASE_DECLARE_FEATURE(kAlignWakeUps); |
Etienne Pierre-doray | 048472eb | 2022-02-07 16:24:48 | [diff] [blame] | 57 | |
Etienne Pierre-doray | ae2c15a | 2022-04-29 18:50:59 | [diff] [blame] | 58 | // Under this feature, tasks that need high resolution timer are determined |
| 59 | // based on explicit DelayPolicy rather than based on a threshold. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame^] | 60 | BASE_EXPORT BASE_DECLARE_FEATURE(kExplicitHighResolutionTimerWin); |
Etienne Pierre-doray | ae2c15a | 2022-04-29 18:50:59 | [diff] [blame] | 61 | |
Alex Attar | 9fcc01e | 2022-05-20 14:01:27 | [diff] [blame] | 62 | // Feature to run tasks by batches before pumping out messages. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame^] | 63 | BASE_EXPORT BASE_DECLARE_FEATURE(kRunTasksByBatches); |
Alex Attar | 9fcc01e | 2022-05-20 14:01:27 | [diff] [blame] | 64 | |
Stephen Nusko | 408b9a9 | 2022-09-15 10:03:57 | [diff] [blame] | 65 | // Feature to run tasks by batches before pumping out messages. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame^] | 66 | BASE_EXPORT BASE_DECLARE_FEATURE(kBrowserPeriodicYieldingToNative); |
Stephen Nusko | 408b9a9 | 2022-09-15 10:03:57 | [diff] [blame] | 67 | extern const BASE_EXPORT base::FeatureParam<TimeDelta> |
| 68 | kBrowserPeriodicYieldingToNativeNormalInputAfterMsParam; |
| 69 | extern const BASE_EXPORT base::FeatureParam<TimeDelta> |
| 70 | kBrowserPeriodicYieldingToNativeFlingInputAfterMsParam; |
| 71 | extern const BASE_EXPORT base::FeatureParam<TimeDelta> |
| 72 | kBrowserPeriodicYieldingToNativeNoInputAfterMsParam; |
| 73 | extern const BASE_EXPORT base::FeatureParam<TimeDelta> |
| 74 | kBrowserPeriodicYieldingToNativeDelay; |
| 75 | |
Jiahe Zhang | 07cf3313 | 2022-08-09 09:42:49 | [diff] [blame] | 76 | BASE_EXPORT void InitializeTaskLeeway(); |
| 77 | BASE_EXPORT TimeDelta GetTaskLeeway(); |
| 78 | |
Leszek Swirski | 2987cc8 | 2018-11-05 15:19:28 | [diff] [blame] | 79 | } // namespace base |
| 80 | |
| 81 | #endif // BASE_TASK_TASK_FEATURES_H_ |