blob: 66d12660da32b3f9bb62a89c328ca28729f95afa [file] [log] [blame]
Leszek Swirski2987cc82018-11-05 15:19:281// 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-Dorayd6b575b22018-11-21 19:32:299#include "base/metrics/field_trial_params.h"
Aditya Keerthia41eda52019-04-01 15:03:2510#include "build/build_config.h"
Leszek Swirski2987cc82018-11-05 15:19:2811
12namespace base {
13
14struct Feature;
Francois Doray5b44e33f2018-11-09 22:08:1315
Etienne Pierre-doray3ed41382019-02-06 04:40:4716// Under this feature, workers blocked with MayBlock are replaced immediately
Etienne Pierre-dorayf7d85262019-11-20 23:37:0617// instead of waiting for a threshold in the foreground thread group.
Etienne Pierre-doray3ed41382019-02-06 04:40:4718extern const BASE_EXPORT Feature kMayBlockWithoutDelay;
19
Etienne Pierre-dorayea2b21e2020-10-26 22:38:5920// Under this feature, ThreadPool::ShouldYield() always returns false
21extern 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.
24extern const BASE_EXPORT Feature kDisableFairJobScheduling;
25// Under this feature, priority update on Jobs is disabled.
26extern const BASE_EXPORT Feature kDisableJobUpdatePriority;
27// Under this feature, another WorkerThread is signaled only after the current
28// thread was assigned work.
29extern const BASE_EXPORT Feature kWakeUpAfterGetWork;
30
31// Strategy affecting how WorkerThreads are signaled to pick up pending work.
32enum 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-dorayb5fe0b5f2021-01-29 18:37:2741 // Each thread signals as many threads as necessary, either when scheduling
42 // new work or picking up pending work.
43 kGreedyWakeUps,
Etienne Pierre-dorayea2b21e2020-10-26 22:38:5944};
45
46// Under this feature, a given WakeUpStrategy param is used.
47extern const BASE_EXPORT Feature kWakeUpStrategyFeature;
48extern const BASE_EXPORT base::FeatureParam<WakeUpStrategy>
49 kWakeUpStrategyParam;
50
Xiaohan Wangbba17e22022-01-15 17:58:1451#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE)
Francois Doray7f777312019-05-16 12:26:3152#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 Dorayee4a5532021-03-30 00:17:1758// Under this feature, ThreadPoolImpl will use a foreground ThreadGroup backed
59// by a native thread pool implementation. The Windows Thread Pool API and
Aditya Keerthia41eda52019-04-01 15:03:2560// libdispatch are used on Windows and macOS/iOS respectively.
61extern const BASE_EXPORT Feature kUseNativeThreadPool;
Francois Dorayee4a5532021-03-30 00:17:1762// Under this feature, ThreadPoolImpl will use a background ThreadGroup backed
63// by a native thread pool implementation.
64extern const BASE_EXPORT Feature kUseBackgroundNativeThreadPool;
Aditya Keerthia41eda52019-04-01 15:03:2565#endif
66
Francois Doraya20b6df22019-06-27 15:04:1967// Whether threads in the ThreadPool should be reclaimed after being idle for 5
68// minutes, instead of 30 seconds.
69extern const BASE_EXPORT Feature kUseFiveMinutesThreadReclaimTime;
70
Patrick Monetteeaaa2382021-12-08 17:06:5971// Controls whether or not canceled delayed tasks are removed from task queues.
72extern const BASE_EXPORT base::Feature kRemoveCanceledTasksInTaskQueue;
73
Etienne Pierre-doraya8792732022-02-05 02:27:2574// 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.
76extern const BASE_EXPORT Feature kAddTaskLeewayFeature;
77extern const BASE_EXPORT base::FeatureParam<TimeDelta> kTaskLeewayParam;
78
Etienne Pierre-doray048472eb2022-02-07 16:24:4879// Under this feature, wake ups are aligned at a 4ms boundary when allowed per
80// DelayPolicy.
81extern const BASE_EXPORT base::Feature kAlignWakeUps;
82
Etienne Pierre-dorayae2c15a2022-04-29 18:50:5983// Under this feature, tasks that need high resolution timer are determined
84// based on explicit DelayPolicy rather than based on a threshold.
85extern const BASE_EXPORT base::Feature kExplicitHighResolutionTimerWin;
86
Alex Attar9fcc01e2022-05-20 14:01:2787// Feature to run tasks by batches before pumping out messages.
88extern const BASE_EXPORT base::Feature kRunTasksByBatches;
89
Leszek Swirski2987cc82018-11-05 15:19:2890} // namespace base
91
92#endif // BASE_TASK_TASK_FEATURES_H_