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 | |
Edgar Arriaga | 453bcb1 | 2023-09-12 23:09:01 | [diff] [blame] | 15 | // Fixed amount of threads that will be used as a cap for thread pools. |
| 16 | BASE_EXPORT BASE_DECLARE_FEATURE(kThreadPoolCap2); |
Edgar Arriaga | d096f40 | 2023-05-02 15:39:24 | [diff] [blame] | 17 | |
Takashi Toyoshima | cff0ce6 | 2025-01-17 14:32:12 | [diff] [blame] | 18 | BASE_EXPORT BASE_DECLARE_FEATURE_PARAM(int, kThreadPoolCapRestrictedCount); |
Edgar Arriaga | d096f40 | 2023-05-02 15:39:24 | [diff] [blame] | 19 | |
Zhibo Wang | f8950ab6 | 2022-12-09 05:33:42 | [diff] [blame] | 20 | // Under this feature, a utility_thread_group will be created for |
| 21 | // running USER_VISIBLE tasks. |
| 22 | BASE_EXPORT BASE_DECLARE_FEATURE(kUseUtilityThreadGroup); |
| 23 | |
Etienne Pierre-doray | a879273 | 2022-02-05 02:27:25 | [diff] [blame] | 24 | // Under this feature, a non-zero leeway is added to delayed tasks. Along with |
| 25 | // DelayPolicy, this affects the time at which a delayed task runs. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 26 | BASE_EXPORT BASE_DECLARE_FEATURE(kAddTaskLeewayFeature); |
Etienne Pierre-doray | d5cdda49 | 2023-07-05 18:20:14 | [diff] [blame] | 27 | #if BUILDFLAG(IS_WIN) |
| 28 | constexpr TimeDelta kDefaultLeeway = Milliseconds(16); |
| 29 | #else |
Jiahe Zhang | 07cf3313 | 2022-08-09 09:42:49 | [diff] [blame] | 30 | constexpr TimeDelta kDefaultLeeway = Milliseconds(8); |
Etienne Pierre-doray | d5cdda49 | 2023-07-05 18:20:14 | [diff] [blame] | 31 | #endif // #if !BUILDFLAG(IS_WIN) |
Takashi Toyoshima | cff0ce6 | 2025-01-17 14:32:12 | [diff] [blame] | 32 | BASE_EXPORT BASE_DECLARE_FEATURE_PARAM(TimeDelta, kTaskLeewayParam); |
Etienne Pierre-doray | a879273 | 2022-02-05 02:27:25 | [diff] [blame] | 33 | |
Etienne Pierre-doray | 77474c90 | 2023-09-27 20:23:09 | [diff] [blame] | 34 | // We consider that delayed tasks above |kMaxPreciseDelay| never need |
| 35 | // DelayPolicy::kPrecise. The default value is slightly above 30Hz timer. |
| 36 | constexpr TimeDelta kDefaultMaxPreciseDelay = Milliseconds(36); |
Takashi Toyoshima | cff0ce6 | 2025-01-17 14:32:12 | [diff] [blame] | 37 | BASE_EXPORT BASE_DECLARE_FEATURE_PARAM(TimeDelta, kMaxPreciseDelay); |
Etienne Pierre-doray | 77474c90 | 2023-09-27 20:23:09 | [diff] [blame] | 38 | |
Jiahe Zhang | 07cf3313 | 2022-08-09 09:42:49 | [diff] [blame] | 39 | // 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] | 40 | // DelayPolicy. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 41 | BASE_EXPORT BASE_DECLARE_FEATURE(kAlignWakeUps); |
Etienne Pierre-doray | 048472eb | 2022-02-07 16:24:48 | [diff] [blame] | 42 | |
Etienne Pierre-doray | 1f2b04e | 2023-09-05 20:23:56 | [diff] [blame] | 43 | // Under this feature, slack is added on mac message pumps that support it when |
| 44 | // allowed per DelayPolicy. |
| 45 | BASE_EXPORT BASE_DECLARE_FEATURE(kTimerSlackMac); |
| 46 | |
Sean Maher | bff1adc | 2024-04-10 20:33:43 | [diff] [blame] | 47 | // Under this feature, the Windows UI pump uses a WaitableEvent to wake itself |
| 48 | // up when not in a native nested loop. It also uses different control flow, |
| 49 | // calling Win32 MessagePump functions less often. |
| 50 | BASE_EXPORT BASE_DECLARE_FEATURE(kUIPumpImprovementsWin); |
| 51 | |
Sean Maher | acb46d7 | 2024-05-16 17:22:15 | [diff] [blame] | 52 | // Under this feature, the Android pump will call ALooper_PollOnce() rather than |
| 53 | // unconditionally yielding to native to determine whether there exists native |
| 54 | // work to be done before sleep. |
| 55 | BASE_EXPORT BASE_DECLARE_FEATURE(kPumpFastToSleepAndroid); |
| 56 | |
Alex Attar | 9fcc01e | 2022-05-20 14:01:27 | [diff] [blame] | 57 | // Feature to run tasks by batches before pumping out messages. |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 58 | BASE_EXPORT BASE_DECLARE_FEATURE(kRunTasksByBatches); |
Alex Attar | 9fcc01e | 2022-05-20 14:01:27 | [diff] [blame] | 59 | |
Leszek Swirski | 2987cc8 | 2018-11-05 15:19:28 | [diff] [blame] | 60 | } // namespace base |
| 61 | |
| 62 | #endif // BASE_TASK_TASK_FEATURES_H_ |