Home | History | Annotate | Download | only in task_scheduler
      1 // Copyright 2017 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_SCHEDULER_ENVIRONMENT_CONFIG_H_
      6 #define BASE_TASK_SCHEDULER_ENVIRONMENT_CONFIG_H_
      7 
      8 #include <stddef.h>
      9 
     10 #include "base/base_export.h"
     11 #include "base/task_scheduler/task_traits.h"
     12 #include "base/threading/thread.h"
     13 
     14 namespace base {
     15 namespace internal {
     16 
     17 enum EnvironmentType {
     18   FOREGROUND = 0,
     19   FOREGROUND_BLOCKING,
     20   // Pools will only be created for the environment above on platforms that
     21   // don't support SchedulerWorkers running with a background priority.
     22   ENVIRONMENT_COUNT_WITHOUT_BACKGROUND_PRIORITY,
     23   BACKGROUND = ENVIRONMENT_COUNT_WITHOUT_BACKGROUND_PRIORITY,
     24   BACKGROUND_BLOCKING,
     25   ENVIRONMENT_COUNT  // Always last.
     26 };
     27 
     28 // Order must match the EnvironmentType enum.
     29 constexpr struct {
     30   // The threads and histograms of this environment will be labeled with
     31   // the task scheduler name concatenated to this.
     32   const char* name_suffix;
     33 
     34   // Preferred priority for threads in this environment; the actual thread
     35   // priority depends on shutdown state and platform capabilities.
     36   ThreadPriority priority_hint;
     37 } kEnvironmentParams[] = {
     38     {"Foreground", base::ThreadPriority::NORMAL},
     39     {"ForegroundBlocking", base::ThreadPriority::NORMAL},
     40     {"Background", base::ThreadPriority::BACKGROUND},
     41     {"BackgroundBlocking", base::ThreadPriority::BACKGROUND},
     42 };
     43 
     44 size_t BASE_EXPORT GetEnvironmentIndexForTraits(const TaskTraits& traits);
     45 
     46 // Returns true if this platform supports having SchedulerWorkers running with a
     47 // background priority.
     48 bool BASE_EXPORT CanUseBackgroundPriorityForSchedulerWorker();
     49 
     50 }  // namespace internal
     51 }  // namespace base
     52 
     53 #endif  // BASE_TASK_SCHEDULER_ENVIRONMENT_CONFIG_H_
     54