Leszek Swirski | 2987cc8 | 2018-11-05 15:19:28 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 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. |
| 25 | extern const BASE_EXPORT 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. |
| 28 | extern const BASE_EXPORT Feature kUseBackgroundNativeThreadPool; |
Aditya Keerthi | a41eda5 | 2019-04-01 15:03:25 | [diff] [blame] | 29 | #endif |
| 30 | |
Francois Doray | a20b6df2 | 2019-06-27 15:04:19 | [diff] [blame] | 31 | // Whether threads in the ThreadPool should be reclaimed after being idle for 5 |
| 32 | // minutes, instead of 30 seconds. |
| 33 | extern const BASE_EXPORT Feature kUseFiveMinutesThreadReclaimTime; |
| 34 | |
Patrick Monette | 6497eae | 2022-08-09 17:59:58 | [diff] [blame] | 35 | // This feature controls whether wake ups are possible for canceled tasks. |
| 36 | extern const BASE_EXPORT Feature kNoWakeUpsForCanceledTasks; |
| 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. |
| 39 | extern const BASE_EXPORT base::Feature kRemoveCanceledTasksInTaskQueue; |
| 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. |
| 46 | extern const BASE_EXPORT base::Feature kAlwaysAbandonScheduledTask; |
| 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. |
| 50 | extern const BASE_EXPORT 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. |
| 56 | extern const BASE_EXPORT base::Feature kAlignWakeUps; |
| 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. |
| 60 | extern const BASE_EXPORT base::Feature kExplicitHighResolutionTimerWin; |
| 61 | |
Alex Attar | 9fcc01e | 2022-05-20 14:01:27 | [diff] [blame] | 62 | // Feature to run tasks by batches before pumping out messages. |
| 63 | extern const BASE_EXPORT base::Feature kRunTasksByBatches; |
| 64 | |
Jiahe Zhang | 07cf3313 | 2022-08-09 09:42:49 | [diff] [blame] | 65 | BASE_EXPORT void InitializeTaskLeeway(); |
| 66 | BASE_EXPORT TimeDelta GetTaskLeeway(); |
| 67 | |
Leszek Swirski | 2987cc8 | 2018-11-05 15:19:28 | [diff] [blame] | 68 | } // namespace base |
| 69 | |
| 70 | #endif // BASE_TASK_TASK_FEATURES_H_ |