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" |
Etienne Pierre-Doray | d6b575b2 | 2018-11-21 19:32:29 | [diff] [blame] | 9 | #include "base/metrics/field_trial_params.h" |
Aditya Keerthi | a41eda5 | 2019-04-01 15:03:25 | [diff] [blame] | 10 | #include "build/build_config.h" |
Leszek Swirski | 2987cc8 | 2018-11-05 15:19:28 | [diff] [blame] | 11 | |
| 12 | namespace base { |
| 13 | |
| 14 | struct Feature; |
Francois Doray | 5b44e33f | 2018-11-09 22:08:13 | [diff] [blame] | 15 | |
Etienne Pierre-doray | 3ed4138 | 2019-02-06 04:40:47 | [diff] [blame] | 16 | // Under this feature, workers blocked with MayBlock are replaced immediately |
Etienne Pierre-doray | f7d8526 | 2019-11-20 23:37:06 | [diff] [blame] | 17 | // instead of waiting for a threshold in the foreground thread group. |
Etienne Pierre-doray | 3ed4138 | 2019-02-06 04:40:47 | [diff] [blame] | 18 | extern const BASE_EXPORT Feature kMayBlockWithoutDelay; |
| 19 | |
Etienne Pierre-doray | ea2b21e | 2020-10-26 22:38:59 | [diff] [blame] | 20 | // Under this feature, ThreadPool::ShouldYield() always returns false |
| 21 | extern const BASE_EXPORT Feature kDisableJobYield; |
| 22 | // Under this feature, JobTaskSource doesn't use worker count in its sort key |
| 23 | // such that worker threads are not distributed among running jobs equally. |
| 24 | extern const BASE_EXPORT Feature kDisableFairJobScheduling; |
| 25 | // Under this feature, priority update on Jobs is disabled. |
| 26 | extern const BASE_EXPORT Feature kDisableJobUpdatePriority; |
| 27 | // Under this feature, another WorkerThread is signaled only after the current |
| 28 | // thread was assigned work. |
| 29 | extern const BASE_EXPORT Feature kWakeUpAfterGetWork; |
| 30 | |
| 31 | // Strategy affecting how WorkerThreads are signaled to pick up pending work. |
| 32 | enum class WakeUpStrategy { |
| 33 | // A single thread scheduling new work signals all required WorkerThreads. |
| 34 | kCentralizedWakeUps, |
| 35 | // Each thread signals at most a single thread, either when scheduling new |
| 36 | // work or picking up pending work. |
| 37 | kSerializedWakeUps, |
| 38 | // Each thread signals at most 2 threads, either when scheduling new |
| 39 | // work or picking up pending work. |
| 40 | kExponentialWakeUps, |
Etienne Pierre-doray | b5fe0b5f | 2021-01-29 18:37:27 | [diff] [blame] | 41 | // Each thread signals as many threads as necessary, either when scheduling |
| 42 | // new work or picking up pending work. |
| 43 | kGreedyWakeUps, |
Etienne Pierre-doray | ea2b21e | 2020-10-26 22:38:59 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | // Under this feature, a given WakeUpStrategy param is used. |
| 47 | extern const BASE_EXPORT Feature kWakeUpStrategyFeature; |
| 48 | extern const BASE_EXPORT base::FeatureParam<WakeUpStrategy> |
| 49 | kWakeUpStrategyParam; |
| 50 | |
Xiaohan Wang | bba17e2 | 2022-01-15 17:58:14 | [diff] [blame] | 51 | #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE) |
Francois Doray | 7f77731 | 2019-05-16 12:26:31 | [diff] [blame] | 52 | #define HAS_NATIVE_THREAD_POOL() 1 |
| 53 | #else |
| 54 | #define HAS_NATIVE_THREAD_POOL() 0 |
| 55 | #endif |
| 56 | |
| 57 | #if HAS_NATIVE_THREAD_POOL() |
Francois Doray | ee4a553 | 2021-03-30 00:17:17 | [diff] [blame] | 58 | // Under this feature, ThreadPoolImpl will use a foreground ThreadGroup backed |
| 59 | // by a native thread pool implementation. The Windows Thread Pool API and |
Aditya Keerthi | a41eda5 | 2019-04-01 15:03:25 | [diff] [blame] | 60 | // libdispatch are used on Windows and macOS/iOS respectively. |
| 61 | extern const BASE_EXPORT Feature kUseNativeThreadPool; |
Francois Doray | ee4a553 | 2021-03-30 00:17:17 | [diff] [blame] | 62 | // Under this feature, ThreadPoolImpl will use a background ThreadGroup backed |
| 63 | // by a native thread pool implementation. |
| 64 | extern const BASE_EXPORT Feature kUseBackgroundNativeThreadPool; |
Aditya Keerthi | a41eda5 | 2019-04-01 15:03:25 | [diff] [blame] | 65 | #endif |
| 66 | |
Francois Doray | a20b6df2 | 2019-06-27 15:04:19 | [diff] [blame] | 67 | // Whether threads in the ThreadPool should be reclaimed after being idle for 5 |
| 68 | // minutes, instead of 30 seconds. |
| 69 | extern const BASE_EXPORT Feature kUseFiveMinutesThreadReclaimTime; |
| 70 | |
Patrick Monette | eaaa238 | 2021-12-08 17:06:59 | [diff] [blame] | 71 | // Controls whether or not canceled delayed tasks are removed from task queues. |
| 72 | extern const BASE_EXPORT base::Feature kRemoveCanceledTasksInTaskQueue; |
| 73 | |
Etienne Pierre-doray | a879273 | 2022-02-05 02:27:25 | [diff] [blame] | 74 | // Under this feature, a non-zero leeway is added to delayed tasks. Along with |
| 75 | // DelayPolicy, this affects the time at which a delayed task runs. |
| 76 | extern const BASE_EXPORT Feature kAddTaskLeewayFeature; |
| 77 | extern const BASE_EXPORT base::FeatureParam<TimeDelta> kTaskLeewayParam; |
| 78 | |
Etienne Pierre-doray | 048472eb | 2022-02-07 16:24:48 | [diff] [blame] | 79 | // Under this feature, wake ups are aligned at a 4ms boundary when allowed per |
| 80 | // DelayPolicy. |
| 81 | extern const BASE_EXPORT base::Feature kAlignWakeUps; |
| 82 | |
Etienne Pierre-doray | ae2c15a | 2022-04-29 18:50:59 | [diff] [blame] | 83 | // Under this feature, tasks that need high resolution timer are determined |
| 84 | // based on explicit DelayPolicy rather than based on a threshold. |
| 85 | extern const BASE_EXPORT base::Feature kExplicitHighResolutionTimerWin; |
| 86 | |
Alex Attar | 9fcc01e | 2022-05-20 14:01:27 | [diff] [blame^] | 87 | // Feature to run tasks by batches before pumping out messages. |
| 88 | extern const BASE_EXPORT base::Feature kRunTasksByBatches; |
| 89 | |
Leszek Swirski | 2987cc8 | 2018-11-05 15:19:28 | [diff] [blame] | 90 | } // namespace base |
| 91 | |
| 92 | #endif // BASE_TASK_TASK_FEATURES_H_ |