blob: 1895aa243d7bdea22625bd15d048b0554621be12 [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 Monette6497eae2022-08-09 17:59:5871// This feature controls whether wake ups are possible for canceled tasks.
72extern const BASE_EXPORT Feature kNoWakeUpsForCanceledTasks;
73
Patrick Monetteeaaa2382021-12-08 17:06:5974// Controls whether or not canceled delayed tasks are removed from task queues.
75extern const BASE_EXPORT base::Feature kRemoveCanceledTasksInTaskQueue;
76
Patrick Monette4efba9c2022-08-18 16:41:3277// This feature controls whether or not the scheduled task is always abandoned
78// when a timer is stopped or reset. The re-use of the scheduled task is an
79// optimization that ensures a timer can not leave multiple canceled tasks in
80// the task queue. Meant to be used in conjunction with
81// kRemoveCanceledTasksInTaskQueue.
82extern const BASE_EXPORT base::Feature kAlwaysAbandonScheduledTask;
83
Etienne Pierre-doraya8792732022-02-05 02:27:2584// Under this feature, a non-zero leeway is added to delayed tasks. Along with
85// DelayPolicy, this affects the time at which a delayed task runs.
86extern const BASE_EXPORT Feature kAddTaskLeewayFeature;
Jiahe Zhang07cf33132022-08-09 09:42:4987constexpr TimeDelta kDefaultLeeway = Milliseconds(8);
Etienne Pierre-doraya8792732022-02-05 02:27:2588extern const BASE_EXPORT base::FeatureParam<TimeDelta> kTaskLeewayParam;
89
Jiahe Zhang07cf33132022-08-09 09:42:4990// Under this feature, wake ups are aligned at a 8ms boundary when allowed per
Etienne Pierre-doray048472eb2022-02-07 16:24:4891// DelayPolicy.
92extern const BASE_EXPORT base::Feature kAlignWakeUps;
93
Etienne Pierre-dorayae2c15a2022-04-29 18:50:5994// Under this feature, tasks that need high resolution timer are determined
95// based on explicit DelayPolicy rather than based on a threshold.
96extern const BASE_EXPORT base::Feature kExplicitHighResolutionTimerWin;
97
Alex Attar9fcc01e2022-05-20 14:01:2798// Feature to run tasks by batches before pumping out messages.
99extern const BASE_EXPORT base::Feature kRunTasksByBatches;
100
Jiahe Zhang07cf33132022-08-09 09:42:49101BASE_EXPORT void InitializeTaskLeeway();
102BASE_EXPORT TimeDelta GetTaskLeeway();
103
Leszek Swirski2987cc82018-11-05 15:19:28104} // namespace base
105
106#endif // BASE_TASK_TASK_FEATURES_H_