blob: f41e62817ff54e01fb76216c80c34ca8831ff746 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2018 The Chromium Authors
Leszek Swirski2987cc82018-11-05 15:19:282// 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-Dubois9dbbbda32022-08-26 01:25:319#include "base/feature_list.h"
Etienne Pierre-Dorayd6b575b22018-11-21 19:32:2910#include "base/metrics/field_trial_params.h"
Aditya Keerthia41eda52019-04-01 15:03:2511#include "build/build_config.h"
Leszek Swirski2987cc82018-11-05 15:19:2812
13namespace base {
14
Xiaohan Wangbba17e22022-01-15 17:58:1415#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE)
Francois Doray7f777312019-05-16 12:26:3116#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 Dorayee4a5532021-03-30 00:17:1722// Under this feature, ThreadPoolImpl will use a foreground ThreadGroup backed
23// by a native thread pool implementation. The Windows Thread Pool API and
Aditya Keerthia41eda52019-04-01 15:03:2524// libdispatch are used on Windows and macOS/iOS respectively.
Daniel Cheng0fff5c232022-09-21 17:43:3425BASE_EXPORT BASE_DECLARE_FEATURE(kUseNativeThreadPool);
Francois Dorayee4a5532021-03-30 00:17:1726// Under this feature, ThreadPoolImpl will use a background ThreadGroup backed
27// by a native thread pool implementation.
Daniel Cheng0fff5c232022-09-21 17:43:3428BASE_EXPORT BASE_DECLARE_FEATURE(kUseBackgroundNativeThreadPool);
Aditya Keerthia41eda52019-04-01 15:03:2529#endif
30
Etienne Pierre-dorayb2895232022-08-30 18:15:0331// Under this feature, worker threads are not reclaimed after a timeout. Rather,
32// only excess workers are cleaned up immediately after finishing a task.
Daniel Cheng0fff5c232022-09-21 17:43:3433BASE_EXPORT BASE_DECLARE_FEATURE(kNoWorkerThreadReclaim);
Francois Doraya20b6df22019-06-27 15:04:1934
Patrick Monette6497eae2022-08-09 17:59:5835// This feature controls whether wake ups are possible for canceled tasks.
Daniel Cheng0fff5c232022-09-21 17:43:3436BASE_EXPORT BASE_DECLARE_FEATURE(kNoWakeUpsForCanceledTasks);
Patrick Monette6497eae2022-08-09 17:59:5837
Patrick Monetteeaaa2382021-12-08 17:06:5938// Controls whether or not canceled delayed tasks are removed from task queues.
Daniel Cheng0fff5c232022-09-21 17:43:3439BASE_EXPORT BASE_DECLARE_FEATURE(kRemoveCanceledTasksInTaskQueue);
Patrick Monetteeaaa2382021-12-08 17:06:5940
Patrick Monette4efba9c2022-08-18 16:41:3241// 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.
Daniel Cheng0fff5c232022-09-21 17:43:3446BASE_EXPORT BASE_DECLARE_FEATURE(kAlwaysAbandonScheduledTask);
Patrick Monette4efba9c2022-08-18 16:41:3247
Etienne Pierre-doraya8792732022-02-05 02:27:2548// 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.
Daniel Cheng0fff5c232022-09-21 17:43:3450BASE_EXPORT BASE_DECLARE_FEATURE(kAddTaskLeewayFeature);
Jiahe Zhang07cf33132022-08-09 09:42:4951constexpr TimeDelta kDefaultLeeway = Milliseconds(8);
Etienne Pierre-doraya8792732022-02-05 02:27:2552extern const BASE_EXPORT base::FeatureParam<TimeDelta> kTaskLeewayParam;
53
Jiahe Zhang07cf33132022-08-09 09:42:4954// Under this feature, wake ups are aligned at a 8ms boundary when allowed per
Etienne Pierre-doray048472eb2022-02-07 16:24:4855// DelayPolicy.
Daniel Cheng0fff5c232022-09-21 17:43:3456BASE_EXPORT BASE_DECLARE_FEATURE(kAlignWakeUps);
Etienne Pierre-doray048472eb2022-02-07 16:24:4857
Etienne Pierre-dorayae2c15a2022-04-29 18:50:5958// Under this feature, tasks that need high resolution timer are determined
59// based on explicit DelayPolicy rather than based on a threshold.
Daniel Cheng0fff5c232022-09-21 17:43:3460BASE_EXPORT BASE_DECLARE_FEATURE(kExplicitHighResolutionTimerWin);
Etienne Pierre-dorayae2c15a2022-04-29 18:50:5961
Alex Attar9fcc01e2022-05-20 14:01:2762// Feature to run tasks by batches before pumping out messages.
Daniel Cheng0fff5c232022-09-21 17:43:3463BASE_EXPORT BASE_DECLARE_FEATURE(kRunTasksByBatches);
Alex Attar9fcc01e2022-05-20 14:01:2764
Stephen Nusko408b9a92022-09-15 10:03:5765// Feature to run tasks by batches before pumping out messages.
Daniel Cheng0fff5c232022-09-21 17:43:3466BASE_EXPORT BASE_DECLARE_FEATURE(kBrowserPeriodicYieldingToNative);
Stephen Nusko408b9a92022-09-15 10:03:5767extern const BASE_EXPORT base::FeatureParam<TimeDelta>
68 kBrowserPeriodicYieldingToNativeNormalInputAfterMsParam;
69extern const BASE_EXPORT base::FeatureParam<TimeDelta>
70 kBrowserPeriodicYieldingToNativeFlingInputAfterMsParam;
71extern const BASE_EXPORT base::FeatureParam<TimeDelta>
72 kBrowserPeriodicYieldingToNativeNoInputAfterMsParam;
73extern const BASE_EXPORT base::FeatureParam<TimeDelta>
74 kBrowserPeriodicYieldingToNativeDelay;
75
Jiahe Zhang07cf33132022-08-09 09:42:4976BASE_EXPORT void InitializeTaskLeeway();
77BASE_EXPORT TimeDelta GetTaskLeeway();
78
Leszek Swirski2987cc82018-11-05 15:19:2879} // namespace base
80
81#endif // BASE_TASK_TASK_FEATURES_H_