OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_PARAMS_H_ | 5 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_PARAMS_H_ |
6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_PARAMS_H_ | 6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_PARAMS_H_ |
7 | 7 |
8 #include <string> | |
9 | |
10 #include "base/task_scheduler/scheduler_worker_params.h" | 8 #include "base/task_scheduler/scheduler_worker_params.h" |
11 #include "base/threading/platform_thread.h" | |
12 #include "base/time/time.h" | 9 #include "base/time/time.h" |
13 | 10 |
14 namespace base { | 11 namespace base { |
15 | 12 |
16 class BASE_EXPORT SchedulerWorkerPoolParams final { | 13 class BASE_EXPORT SchedulerWorkerPoolParams final { |
17 public: | 14 public: |
18 enum class StandbyThreadPolicy { | 15 enum class StandbyThreadPolicy { |
19 // Create threads as needed on demand, reclaimed as necessary. | 16 // Create threads as needed on demand, reclaimed as necessary. |
20 LAZY, | 17 LAZY, |
21 // When possible, keep one idle thread alive on standby, reclaimed as | 18 // When possible, keep one idle thread alive on standby, reclaimed as |
22 // necessary. | 19 // necessary. |
23 ONE, | 20 ONE, |
24 }; | 21 }; |
25 | 22 |
26 // Construct a scheduler worker pool parameter object. |name| will be used to | 23 // Constructs an invalid scheduler worker pool parameter object. |
27 // label the pool's threads ("TaskScheduler" + |name| + index) and histograms | 24 SchedulerWorkerPoolParams(); |
28 // ("TaskScheduler." + histogram name + "." + |name| + extra suffixes). The | 25 |
29 // pool will contain up to |max_threads|. |priority_hint| is the preferred | 26 // Constructs a scheduler worker pool parameter object. The pool will contain |
30 // thread priority; the actual thread priority depends on shutdown state and | 27 // up to |max_threads|. |standby_thread_policy| indicates whether an idle |
31 // platform capabilities. |standby_thread_policy| indicates whether an idle | |
32 // thread should be kept alive on standby. |suggested_reclaim_time| sets a | 28 // thread should be kept alive on standby. |suggested_reclaim_time| sets a |
33 // suggestion on when to reclaim idle threads. The pool is free to ignore this | 29 // suggestion on when to reclaim idle threads. The pool is free to ignore this |
34 // value for performance or correctness reasons. |backward_compatibility| | 30 // value for performance or correctness reasons. |backward_compatibility| |
35 // indicates whether backward compatibility is enabled. | 31 // indicates whether backward compatibility is enabled. |
36 SchedulerWorkerPoolParams( | 32 SchedulerWorkerPoolParams( |
37 const std::string& name, | |
38 ThreadPriority priority_hint, | |
39 StandbyThreadPolicy standby_thread_policy, | 33 StandbyThreadPolicy standby_thread_policy, |
40 int max_threads, | 34 int max_threads, |
41 TimeDelta suggested_reclaim_time, | 35 TimeDelta suggested_reclaim_time, |
42 SchedulerBackwardCompatibility backward_compatibility = | 36 SchedulerBackwardCompatibility backward_compatibility = |
43 SchedulerBackwardCompatibility::DISABLED); | 37 SchedulerBackwardCompatibility::DISABLED); |
| 38 |
44 SchedulerWorkerPoolParams(const SchedulerWorkerPoolParams& other); | 39 SchedulerWorkerPoolParams(const SchedulerWorkerPoolParams& other); |
45 SchedulerWorkerPoolParams& operator=(const SchedulerWorkerPoolParams& other); | 40 SchedulerWorkerPoolParams& operator=(const SchedulerWorkerPoolParams& other); |
46 | 41 |
47 const std::string& name() const { return name_; } | 42 // Returns true if this object can be used to initialize a worker pool. |
48 ThreadPriority priority_hint() const { return priority_hint_; } | 43 bool IsValid() const; |
| 44 |
49 StandbyThreadPolicy standby_thread_policy() const { | 45 StandbyThreadPolicy standby_thread_policy() const { |
50 return standby_thread_policy_; | 46 return standby_thread_policy_; |
51 } | 47 } |
52 size_t max_threads() const { return max_threads_; } | 48 size_t max_threads() const { return max_threads_; } |
53 TimeDelta suggested_reclaim_time() const { return suggested_reclaim_time_; } | 49 TimeDelta suggested_reclaim_time() const { return suggested_reclaim_time_; } |
54 SchedulerBackwardCompatibility backward_compatibility() const { | 50 SchedulerBackwardCompatibility backward_compatibility() const { |
55 return backward_compatibility_; | 51 return backward_compatibility_; |
56 } | 52 } |
57 | 53 |
58 private: | 54 private: |
59 std::string name_; | |
60 ThreadPriority priority_hint_; | |
61 StandbyThreadPolicy standby_thread_policy_; | 55 StandbyThreadPolicy standby_thread_policy_; |
62 size_t max_threads_; | 56 size_t max_threads_; |
63 TimeDelta suggested_reclaim_time_; | 57 TimeDelta suggested_reclaim_time_; |
64 SchedulerBackwardCompatibility backward_compatibility_; | 58 SchedulerBackwardCompatibility backward_compatibility_; |
65 }; | 59 }; |
66 | 60 |
67 } // namespace base | 61 } // namespace base |
68 | 62 |
69 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_PARAMS_H_ | 63 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_PARAMS_H_ |
OLD | NEW |