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> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 | 14 |
15 class TimeDelta; | 15 class TimeDelta; |
16 | 16 |
17 class BASE_EXPORT SchedulerWorkerPoolParams final { | 17 class BASE_EXPORT SchedulerWorkerPoolParams final { |
18 public: | 18 public: |
19 enum class IORestriction { | 19 enum class IORestriction { |
20 ALLOWED, | 20 ALLOWED, |
21 DISALLOWED, | 21 DISALLOWED, |
22 }; | 22 }; |
23 | 23 |
| 24 enum class StandbyThreadPolicy { |
| 25 // Create threads as needed on demand, reclaimed as necessary. |
| 26 LAZY, |
| 27 // When possible, keep one idle thread alive on standby, reclaimed as |
| 28 // necessary. |
| 29 ONE, |
| 30 }; |
| 31 |
24 // Construct a scheduler worker pool parameter object. |name| will be used to | 32 // Construct a scheduler worker pool parameter object. |name| will be used to |
25 // label the pool's threads ("TaskScheduler" + |name| + index) and histograms | 33 // label the pool's threads ("TaskScheduler" + |name| + index) and histograms |
26 // ("TaskScheduler." + histogram name + "." + |name| + extra suffixes). The | 34 // ("TaskScheduler." + histogram name + "." + |name| + extra suffixes). The |
27 // pool will contain up to |max_threads|. |priority_hint| is the preferred | 35 // pool will contain up to |max_threads|. |priority_hint| is the preferred |
28 // thread priority; the actual thread priority depends on shutdown state and | 36 // thread priority; the actual thread priority depends on shutdown state and |
29 // platform capabilities. |io_restriction| indicates whether Tasks on the pool | 37 // platform capabilities. |io_restriction| indicates whether Tasks on the pool |
30 // are allowed to make I/O calls. |suggested_reclaim_time| sets a suggestion | 38 // are allowed to make I/O calls. |suggested_reclaim_time| sets a suggestion |
31 // on when to reclaim idle threads. The pool is free to ignore this value for | 39 // on when to reclaim idle threads. The pool is free to ignore this value for |
32 // performance or correctness reasons. | 40 // performance or correctness reasons. |
33 SchedulerWorkerPoolParams(const std::string& name, | 41 SchedulerWorkerPoolParams(const std::string& name, |
34 ThreadPriority priority_hint, | 42 ThreadPriority priority_hint, |
35 IORestriction io_restriction, | 43 IORestriction io_restriction, |
| 44 StandbyThreadPolicy standby_thread_policy, |
36 int max_threads, | 45 int max_threads, |
37 const TimeDelta& suggested_reclaim_time); | 46 const TimeDelta& suggested_reclaim_time); |
38 SchedulerWorkerPoolParams(SchedulerWorkerPoolParams&& other); | 47 SchedulerWorkerPoolParams(SchedulerWorkerPoolParams&& other); |
39 SchedulerWorkerPoolParams& operator=(SchedulerWorkerPoolParams&& other); | 48 SchedulerWorkerPoolParams& operator=(SchedulerWorkerPoolParams&& other); |
40 | 49 |
41 const std::string& name() const { return name_; } | 50 const std::string& name() const { return name_; } |
42 ThreadPriority priority_hint() const { return priority_hint_; } | 51 ThreadPriority priority_hint() const { return priority_hint_; } |
43 IORestriction io_restriction() const { return io_restriction_; } | 52 IORestriction io_restriction() const { return io_restriction_; } |
| 53 StandbyThreadPolicy standby_thread_policy() const { |
| 54 return standby_thread_policy_; |
| 55 } |
44 size_t max_threads() const { return max_threads_; } | 56 size_t max_threads() const { return max_threads_; } |
45 const TimeDelta& suggested_reclaim_time() const { | 57 const TimeDelta& suggested_reclaim_time() const { |
46 return suggested_reclaim_time_; | 58 return suggested_reclaim_time_; |
47 } | 59 } |
48 | 60 |
49 private: | 61 private: |
50 std::string name_; | 62 std::string name_; |
51 ThreadPriority priority_hint_; | 63 ThreadPriority priority_hint_; |
52 IORestriction io_restriction_; | 64 IORestriction io_restriction_; |
| 65 StandbyThreadPolicy standby_thread_policy_; |
53 size_t max_threads_; | 66 size_t max_threads_; |
54 TimeDelta suggested_reclaim_time_; | 67 TimeDelta suggested_reclaim_time_; |
55 | 68 |
56 DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerPoolParams); | 69 DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerPoolParams); |
57 }; | 70 }; |
58 | 71 |
59 } // namespace base | 72 } // namespace base |
60 | 73 |
61 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_PARAMS_H_ | 74 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_PARAMS_H_ |
OLD | NEW |