xref: /aosp_15_r20/external/libchrome/base/task_scheduler/environment_config.h (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright 2017 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker 
5*635a8641SAndroid Build Coastguard Worker #ifndef BASE_TASK_SCHEDULER_ENVIRONMENT_CONFIG_H_
6*635a8641SAndroid Build Coastguard Worker #define BASE_TASK_SCHEDULER_ENVIRONMENT_CONFIG_H_
7*635a8641SAndroid Build Coastguard Worker 
8*635a8641SAndroid Build Coastguard Worker #include <stddef.h>
9*635a8641SAndroid Build Coastguard Worker 
10*635a8641SAndroid Build Coastguard Worker #include "base/base_export.h"
11*635a8641SAndroid Build Coastguard Worker #include "base/task_scheduler/task_traits.h"
12*635a8641SAndroid Build Coastguard Worker #include "base/threading/thread.h"
13*635a8641SAndroid Build Coastguard Worker 
14*635a8641SAndroid Build Coastguard Worker namespace base {
15*635a8641SAndroid Build Coastguard Worker namespace internal {
16*635a8641SAndroid Build Coastguard Worker 
17*635a8641SAndroid Build Coastguard Worker enum EnvironmentType {
18*635a8641SAndroid Build Coastguard Worker   FOREGROUND = 0,
19*635a8641SAndroid Build Coastguard Worker   FOREGROUND_BLOCKING,
20*635a8641SAndroid Build Coastguard Worker   // Pools will only be created for the environment above on platforms that
21*635a8641SAndroid Build Coastguard Worker   // don't support SchedulerWorkers running with a background priority.
22*635a8641SAndroid Build Coastguard Worker   ENVIRONMENT_COUNT_WITHOUT_BACKGROUND_PRIORITY,
23*635a8641SAndroid Build Coastguard Worker   BACKGROUND = ENVIRONMENT_COUNT_WITHOUT_BACKGROUND_PRIORITY,
24*635a8641SAndroid Build Coastguard Worker   BACKGROUND_BLOCKING,
25*635a8641SAndroid Build Coastguard Worker   ENVIRONMENT_COUNT  // Always last.
26*635a8641SAndroid Build Coastguard Worker };
27*635a8641SAndroid Build Coastguard Worker 
28*635a8641SAndroid Build Coastguard Worker // Order must match the EnvironmentType enum.
29*635a8641SAndroid Build Coastguard Worker constexpr struct {
30*635a8641SAndroid Build Coastguard Worker   // The threads and histograms of this environment will be labeled with
31*635a8641SAndroid Build Coastguard Worker   // the task scheduler name concatenated to this.
32*635a8641SAndroid Build Coastguard Worker   const char* name_suffix;
33*635a8641SAndroid Build Coastguard Worker 
34*635a8641SAndroid Build Coastguard Worker   // Preferred priority for threads in this environment; the actual thread
35*635a8641SAndroid Build Coastguard Worker   // priority depends on shutdown state and platform capabilities.
36*635a8641SAndroid Build Coastguard Worker   ThreadPriority priority_hint;
37*635a8641SAndroid Build Coastguard Worker } kEnvironmentParams[] = {
38*635a8641SAndroid Build Coastguard Worker     {"Foreground", base::ThreadPriority::NORMAL},
39*635a8641SAndroid Build Coastguard Worker     {"ForegroundBlocking", base::ThreadPriority::NORMAL},
40*635a8641SAndroid Build Coastguard Worker     {"Background", base::ThreadPriority::BACKGROUND},
41*635a8641SAndroid Build Coastguard Worker     {"BackgroundBlocking", base::ThreadPriority::BACKGROUND},
42*635a8641SAndroid Build Coastguard Worker };
43*635a8641SAndroid Build Coastguard Worker 
44*635a8641SAndroid Build Coastguard Worker size_t BASE_EXPORT GetEnvironmentIndexForTraits(const TaskTraits& traits);
45*635a8641SAndroid Build Coastguard Worker 
46*635a8641SAndroid Build Coastguard Worker // Returns true if this platform supports having SchedulerWorkers running with a
47*635a8641SAndroid Build Coastguard Worker // background priority.
48*635a8641SAndroid Build Coastguard Worker bool BASE_EXPORT CanUseBackgroundPriorityForSchedulerWorker();
49*635a8641SAndroid Build Coastguard Worker 
50*635a8641SAndroid Build Coastguard Worker }  // namespace internal
51*635a8641SAndroid Build Coastguard Worker }  // namespace base
52*635a8641SAndroid Build Coastguard Worker 
53*635a8641SAndroid Build Coastguard Worker #endif  // BASE_TASK_SCHEDULER_ENVIRONMENT_CONFIG_H_
54