xref: /aosp_15_r20/external/cronet/base/task/task_features.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2018 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/task/task_features.h"
6 
7 #include <atomic>
8 
9 #include "base/base_export.h"
10 #include "base/feature_list.h"
11 #include "build/build_config.h"
12 
13 namespace base {
14 
15 // Note to implementers: thread pool code using task features must absolutely
16 // not invoke FeatureList::IsEnabled outside of the main thread. Doing so
17 // causes data races between worker threads and ~FeatureList when tests end
18 // (crbug.com/1344573). A reliable moment to query and cache the feature state
19 // is on ThreadPoolImpl::Start (and thus also on the first WorkerThread::Start,
20 // not the later ones) as this is invoked from the main thread after
21 // initializing the FeatureList. If caching the feature state in a static, you
22 // must be aware that all tests sharing a process will have the same state,
23 // regardless of future ScopedFeatureList instances.
24 
25 BASE_FEATURE(kUseUtilityThreadGroup,
26              "UseUtilityThreadGroup",
27              base::FEATURE_DISABLED_BY_DEFAULT);
28 
29 BASE_FEATURE(kNoWorkerThreadReclaim,
30              "NoWorkerThreadReclaim",
31              base::FEATURE_ENABLED_BY_DEFAULT);
32 
33 BASE_FEATURE(kDelayFirstWorkerWake,
34              "DelayFirstWorkerWake",
35              base::FEATURE_ENABLED_BY_DEFAULT);
36 
37 BASE_FEATURE(kAddTaskLeewayFeature,
38              "AddTaskLeeway",
39              base::FEATURE_ENABLED_BY_DEFAULT);
40 
41 const base::FeatureParam<TimeDelta> kTaskLeewayParam{&kAddTaskLeewayFeature,
42                                                      "leeway", kDefaultLeeway};
43 const base::FeatureParam<TimeDelta> kMaxPreciseDelay{
44     &kAddTaskLeewayFeature, "max_precise_delay", kDefaultMaxPreciseDelay};
45 
46 BASE_FEATURE(kAlignWakeUps, "AlignWakeUps", base::FEATURE_DISABLED_BY_DEFAULT);
47 
48 BASE_FEATURE(kTimerSlackMac,
49              "TimerSlackMac",
50              base::FEATURE_DISABLED_BY_DEFAULT);
51 
52 BASE_FEATURE(kExplicitHighResolutionTimerWin,
53              "ExplicitHighResolutionTimerWin",
54              base::FEATURE_ENABLED_BY_DEFAULT);
55 
56 BASE_FEATURE(kUIPumpImprovementsWin,
57              "UIPumpImprovementsWin",
58              base::FEATURE_DISABLED_BY_DEFAULT);
59 
60 BASE_FEATURE(kRunTasksByBatches,
61              "RunTasksByBatches",
62 #if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_CHROMEOS)
63              base::FEATURE_ENABLED_BY_DEFAULT);
64 #else
65              base::FEATURE_DISABLED_BY_DEFAULT);
66 #endif
67 
68 BASE_FEATURE(kThreadPoolCap2,
69              "ThreadPoolCap2",
70              base::FEATURE_DISABLED_BY_DEFAULT);
71 
72 const base::FeatureParam<int> kThreadPoolCapRestrictedCount{
73     &kThreadPoolCap2, "restricted_count", 3};
74 
75 BASE_FEATURE(kMaxDelayedStarvationTasks,
76              "MaxDelayedStarvationTasks",
77              base::FEATURE_ENABLED_BY_DEFAULT);
78 
79 const base::FeatureParam<int> kMaxDelayedStarvationTasksParam{
80     &kMaxDelayedStarvationTasks, "count", 3};
81 
82 BASE_FEATURE(kThreadGroupSemaphore,
83              "ThreadGroupSemaphore",
84              base::FEATURE_DISABLED_BY_DEFAULT);
85 const base::FeatureParam<int> kMaxNumWorkersCreated{
86     &kThreadGroupSemaphore, "max_num_workers_created", 2};
87 
88 }  // namespace base
89