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 a set of params used to initialize a pool. The pool will contain |
27 // label the pool's threads ("TaskScheduler" + |name| + index) and histograms | 24 // up to |max_threads|. |standby_thread_policy| indicates whether an idle |
28 // ("TaskScheduler." + histogram name + "." + |name| + extra suffixes). The | |
29 // pool will contain up to |max_threads|. |priority_hint| is the preferred | |
30 // thread priority; the actual thread priority depends on shutdown state and | |
31 // platform capabilities. |standby_thread_policy| indicates whether an idle | |
32 // thread should be kept alive on standby. |suggested_reclaim_time| sets a | 25 // 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 | 26 // suggestion on when to reclaim idle threads. The pool is free to ignore this |
34 // value for performance or correctness reasons. |backward_compatibility| | 27 // value for performance or correctness reasons. |backward_compatibility| |
35 // indicates whether backward compatibility is enabled. | 28 // indicates whether backward compatibility is enabled. |
36 // | |
37 // TODO(fdoray): Remove this constructor. https://crbug.com/690706 | |
38 SchedulerWorkerPoolParams( | |
39 const std::string& name, | |
40 ThreadPriority priority_hint, | |
41 StandbyThreadPolicy standby_thread_policy, | |
42 int max_threads, | |
43 TimeDelta suggested_reclaim_time, | |
44 SchedulerBackwardCompatibility backward_compatibility = | |
45 SchedulerBackwardCompatibility::DISABLED); | |
46 | |
47 // Same as above, with no explicit |name| and |priority_hint|. | |
48 SchedulerWorkerPoolParams( | 29 SchedulerWorkerPoolParams( |
49 StandbyThreadPolicy standby_thread_policy, | 30 StandbyThreadPolicy standby_thread_policy, |
50 int max_threads, | 31 int max_threads, |
51 TimeDelta suggested_reclaim_time, | 32 TimeDelta suggested_reclaim_time, |
52 SchedulerBackwardCompatibility backward_compatibility = | 33 SchedulerBackwardCompatibility backward_compatibility = |
53 SchedulerBackwardCompatibility::DISABLED); | 34 SchedulerBackwardCompatibility::DISABLED); |
54 | 35 |
55 SchedulerWorkerPoolParams(const SchedulerWorkerPoolParams& other); | 36 SchedulerWorkerPoolParams(const SchedulerWorkerPoolParams& other); |
56 SchedulerWorkerPoolParams& operator=(const SchedulerWorkerPoolParams& other); | 37 SchedulerWorkerPoolParams& operator=(const SchedulerWorkerPoolParams& other); |
57 | 38 |
58 const std::string& name() const { return name_; } | |
59 ThreadPriority priority_hint() const { return priority_hint_; } | |
60 StandbyThreadPolicy standby_thread_policy() const { | 39 StandbyThreadPolicy standby_thread_policy() const { |
61 return standby_thread_policy_; | 40 return standby_thread_policy_; |
62 } | 41 } |
63 int max_threads() const { return max_threads_; } | 42 int max_threads() const { return max_threads_; } |
64 TimeDelta suggested_reclaim_time() const { return suggested_reclaim_time_; } | 43 TimeDelta suggested_reclaim_time() const { return suggested_reclaim_time_; } |
65 SchedulerBackwardCompatibility backward_compatibility() const { | 44 SchedulerBackwardCompatibility backward_compatibility() const { |
66 return backward_compatibility_; | 45 return backward_compatibility_; |
67 } | 46 } |
68 | 47 |
69 private: | 48 private: |
70 // TODO(fdoray): Remove |name_| and |priority_hint_|. https://crbug.com/690706 | |
71 std::string name_; | |
72 ThreadPriority priority_hint_; | |
73 StandbyThreadPolicy standby_thread_policy_; | 49 StandbyThreadPolicy standby_thread_policy_; |
74 int max_threads_; | 50 int max_threads_; |
75 TimeDelta suggested_reclaim_time_; | 51 TimeDelta suggested_reclaim_time_; |
76 SchedulerBackwardCompatibility backward_compatibility_; | 52 SchedulerBackwardCompatibility backward_compatibility_; |
77 }; | 53 }; |
78 | 54 |
79 } // namespace base | 55 } // namespace base |
80 | 56 |
81 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_PARAMS_H_ | 57 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_PARAMS_H_ |
OLD | NEW |