task_features.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // 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. #ifndef BASE_TASK_TASK_FEATURES_H_
  5. #define BASE_TASK_TASK_FEATURES_H_
  6. #include "base/base_export.h"
  7. #include "base/metrics/field_trial_params.h"
  8. #include "build/build_config.h"
  9. namespace base {
  10. struct Feature;
  11. // Under this feature, workers blocked with MayBlock are replaced immediately
  12. // instead of waiting for a threshold in the foreground thread group.
  13. extern const BASE_EXPORT Feature kMayBlockWithoutDelay;
  14. // Under this feature, ThreadPool::ShouldYield() always returns false
  15. extern const BASE_EXPORT Feature kDisableJobYield;
  16. // Under this feature, JobTaskSource doesn't use worker count in its sort key
  17. // such that worker threads are not distributed among running jobs equally.
  18. extern const BASE_EXPORT Feature kDisableFairJobScheduling;
  19. // Under this feature, priority update on Jobs is disabled.
  20. extern const BASE_EXPORT Feature kDisableJobUpdatePriority;
  21. // Under this feature, another WorkerThread is signaled only after the current
  22. // thread was assigned work.
  23. extern const BASE_EXPORT Feature kWakeUpAfterGetWork;
  24. // Strategy affecting how WorkerThreads are signaled to pick up pending work.
  25. enum class WakeUpStrategy {
  26. // A single thread scheduling new work signals all required WorkerThreads.
  27. kCentralizedWakeUps,
  28. // Each thread signals at most a single thread, either when scheduling new
  29. // work or picking up pending work.
  30. kSerializedWakeUps,
  31. // Each thread signals at most 2 threads, either when scheduling new
  32. // work or picking up pending work.
  33. kExponentialWakeUps,
  34. // Each thread signals as many threads as necessary, either when scheduling
  35. // new work or picking up pending work.
  36. kGreedyWakeUps,
  37. };
  38. // Under this feature, a given WakeUpStrategy param is used.
  39. extern const BASE_EXPORT Feature kWakeUpStrategyFeature;
  40. extern const BASE_EXPORT base::FeatureParam<WakeUpStrategy>
  41. kWakeUpStrategyParam;
  42. #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE)
  43. #define HAS_NATIVE_THREAD_POOL() 1
  44. #else
  45. #define HAS_NATIVE_THREAD_POOL() 0
  46. #endif
  47. #if HAS_NATIVE_THREAD_POOL()
  48. // Under this feature, ThreadPoolImpl will use a foreground ThreadGroup backed
  49. // by a native thread pool implementation. The Windows Thread Pool API and
  50. // libdispatch are used on Windows and macOS/iOS respectively.
  51. extern const BASE_EXPORT Feature kUseNativeThreadPool;
  52. // Under this feature, ThreadPoolImpl will use a background ThreadGroup backed
  53. // by a native thread pool implementation.
  54. extern const BASE_EXPORT Feature kUseBackgroundNativeThreadPool;
  55. #endif
  56. // Whether threads in the ThreadPool should be reclaimed after being idle for 5
  57. // minutes, instead of 30 seconds.
  58. extern const BASE_EXPORT Feature kUseFiveMinutesThreadReclaimTime;
  59. // This feature controls whether wake ups are possible for canceled tasks.
  60. extern const BASE_EXPORT Feature kNoWakeUpsForCanceledTasks;
  61. // Controls whether or not canceled delayed tasks are removed from task queues.
  62. extern const BASE_EXPORT base::Feature kRemoveCanceledTasksInTaskQueue;
  63. // This feature controls whether or not the scheduled task is always abandoned
  64. // when a timer is stopped or reset. The re-use of the scheduled task is an
  65. // optimization that ensures a timer can not leave multiple canceled tasks in
  66. // the task queue. Meant to be used in conjunction with
  67. // kRemoveCanceledTasksInTaskQueue.
  68. extern const BASE_EXPORT base::Feature kAlwaysAbandonScheduledTask;
  69. // Under this feature, a non-zero leeway is added to delayed tasks. Along with
  70. // DelayPolicy, this affects the time at which a delayed task runs.
  71. extern const BASE_EXPORT Feature kAddTaskLeewayFeature;
  72. constexpr TimeDelta kDefaultLeeway = Milliseconds(8);
  73. extern const BASE_EXPORT base::FeatureParam<TimeDelta> kTaskLeewayParam;
  74. // Under this feature, wake ups are aligned at a 8ms boundary when allowed per
  75. // DelayPolicy.
  76. extern const BASE_EXPORT base::Feature kAlignWakeUps;
  77. // Under this feature, tasks that need high resolution timer are determined
  78. // based on explicit DelayPolicy rather than based on a threshold.
  79. extern const BASE_EXPORT base::Feature kExplicitHighResolutionTimerWin;
  80. // Feature to run tasks by batches before pumping out messages.
  81. extern const BASE_EXPORT base::Feature kRunTasksByBatches;
  82. BASE_EXPORT void InitializeTaskLeeway();
  83. BASE_EXPORT TimeDelta GetTaskLeeway();
  84. } // namespace base
  85. #endif // BASE_TASK_TASK_FEATURES_H_