blob: df357a38949351083e26d3a28c3758a64548750a [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"
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.
25extern const BASE_EXPORT 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.
28extern const BASE_EXPORT Feature kUseBackgroundNativeThreadPool;
Aditya Keerthia41eda52019-04-01 15:03:2529#endif
30
Francois Doraya20b6df22019-06-27 15:04:1931// Whether threads in the ThreadPool should be reclaimed after being idle for 5
32// minutes, instead of 30 seconds.
33extern const BASE_EXPORT Feature kUseFiveMinutesThreadReclaimTime;
34
Patrick Monette6497eae2022-08-09 17:59:5835// This feature controls whether wake ups are possible for canceled tasks.
36extern const BASE_EXPORT Feature kNoWakeUpsForCanceledTasks;
37
Patrick Monetteeaaa2382021-12-08 17:06:5938// Controls whether or not canceled delayed tasks are removed from task queues.
39extern const BASE_EXPORT base::Feature kRemoveCanceledTasksInTaskQueue;
40
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.
46extern const BASE_EXPORT base::Feature kAlwaysAbandonScheduledTask;
47
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.
50extern const BASE_EXPORT 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.
56extern const BASE_EXPORT base::Feature kAlignWakeUps;
57
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.
60extern const BASE_EXPORT base::Feature kExplicitHighResolutionTimerWin;
61
Alex Attar9fcc01e2022-05-20 14:01:2762// Feature to run tasks by batches before pumping out messages.
63extern const BASE_EXPORT base::Feature kRunTasksByBatches;
64
Jiahe Zhang07cf33132022-08-09 09:42:4965BASE_EXPORT void InitializeTaskLeeway();
66BASE_EXPORT TimeDelta GetTaskLeeway();
67
Leszek Swirski2987cc82018-11-05 15:19:2868} // namespace base
69
70#endif // BASE_TASK_TASK_FEATURES_H_