• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "base/threading/platform_thread.h"
12 #include "build/build_config.h"
13 
14 namespace base {
15 
16 // Note to implementers: thread pool code using task features must absolutely
17 // not invoke FeatureList::IsEnabled outside of the main thread. Doing so
18 // causes data races between worker threads and ~FeatureList when tests end
19 // (crbug.com/1344573). A reliable moment to query and cache the feature state
20 // is on ThreadPoolImpl::Start (and thus also on the first WorkerThread::Start,
21 // not the later ones) as this is invoked from the main thread after
22 // initializing the FeatureList. If caching the feature state in a static, you
23 // must be aware that all tests sharing a process will have the same state,
24 // regardless of future ScopedFeatureList instances.
25 
26 BASE_FEATURE(kUseUtilityThreadGroup,
27              "UseUtilityThreadGroup",
28              base::FEATURE_DISABLED_BY_DEFAULT);
29 
30 BASE_FEATURE(kNoWorkerThreadReclaim,
31              "NoWorkerThreadReclaim",
32              base::FEATURE_ENABLED_BY_DEFAULT);
33 
34 BASE_FEATURE(kDelayFirstWorkerWake,
35              "DelayFirstWorkerWake",
36              base::FEATURE_DISABLED_BY_DEFAULT);
37 
38 BASE_FEATURE(kAddTaskLeewayFeature,
39              "AddTaskLeeway",
40              base::FEATURE_ENABLED_BY_DEFAULT);
41 
42 const base::FeatureParam<TimeDelta> kTaskLeewayParam{&kAddTaskLeewayFeature,
43                                                      "leeway", kDefaultLeeway};
44 const base::FeatureParam<TimeDelta> kMaxPreciseDelay{
45     &kAddTaskLeewayFeature, "max_precise_delay", kDefaultMaxPreciseDelay};
46 
47 BASE_FEATURE(kAlignWakeUps, "AlignWakeUps", base::FEATURE_DISABLED_BY_DEFAULT);
48 
49 BASE_FEATURE(kTimerSlackMac,
50              "TimerSlackMac",
51              base::FEATURE_DISABLED_BY_DEFAULT);
52 
53 BASE_FEATURE(kExplicitHighResolutionTimerWin,
54              "ExplicitHighResolutionTimerWin",
55              base::FEATURE_ENABLED_BY_DEFAULT);
56 
57 BASE_FEATURE(kRunTasksByBatches,
58              "RunTasksByBatches",
59 #if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_CHROMEOS)
60              base::FEATURE_ENABLED_BY_DEFAULT);
61 #else
62              base::FEATURE_DISABLED_BY_DEFAULT);
63 #endif
64 
65 BASE_FEATURE(kThreadPoolCap2,
66              "ThreadPoolCap2",
67              base::FEATURE_DISABLED_BY_DEFAULT);
68 
69 const base::FeatureParam<int> kThreadPoolCapRestrictedCount{
70     &kThreadPoolCap2, "restricted_count", 3};
71 
72 // Leeway value applied to delayed tasks. An atomic is used here because the
73 // value is queried from multiple threads.
74 std::atomic<TimeDelta> g_task_leeway{kDefaultLeeway};
75 
InitializeTaskLeeway()76 BASE_EXPORT void InitializeTaskLeeway() {
77   g_task_leeway.store(kTaskLeewayParam.Get(), std::memory_order_relaxed);
78 }
79 
GetTaskLeewayForCurrentThread()80 BASE_EXPORT TimeDelta GetTaskLeewayForCurrentThread() {
81   // For some threads, there might be a override of the leeway, so check it
82   // first.
83   auto leeway_override = PlatformThread::GetThreadLeewayOverride();
84   if (leeway_override.has_value())
85     return leeway_override.value();
86   return g_task_leeway.load(std::memory_order_relaxed);
87 }
88 
GetDefaultTaskLeeway()89 BASE_EXPORT TimeDelta GetDefaultTaskLeeway() {
90   return g_task_leeway.load(std::memory_order_relaxed);
91 }
92 
93 BASE_FEATURE(kMaxDelayedStarvationTasks,
94              "MaxDelayedStarvationTasks",
95              base::FEATURE_ENABLED_BY_DEFAULT);
96 
97 const base::FeatureParam<int> kMaxDelayedStarvationTasksParam{
98     &kMaxDelayedStarvationTasks, "count", 3};
99 
100 BASE_FEATURE(kUseNewJobImplementation,
101              "UseNewJobImplementation",
102              base::FEATURE_DISABLED_BY_DEFAULT);
103 
104 }  // namespace base
105