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_TASK_SCHEDULER_H_ | 5 #ifndef BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ |
6 #define BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ | 6 #define BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/base_export.h" | 12 #include "base/base_export.h" |
13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/sequenced_task_runner.h" | 15 #include "base/sequenced_task_runner.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
17 #include "base/task_runner.h" | 17 #include "base/task_runner.h" |
18 #include "base/task_scheduler/scheduler_worker_pool_params.h" | |
18 #include "base/task_scheduler/task_traits.h" | 19 #include "base/task_scheduler/task_traits.h" |
19 #include "base/time/time.h" | 20 #include "base/time/time.h" |
20 | 21 |
21 namespace gin { | 22 namespace gin { |
22 class V8Platform; | 23 class V8Platform; |
23 } | 24 } |
24 | 25 |
25 namespace tracked_objects { | 26 namespace tracked_objects { |
26 class Location; | 27 class Location; |
27 } | 28 } |
28 | 29 |
29 namespace base { | 30 namespace base { |
30 | 31 |
31 class HistogramBase; | 32 class HistogramBase; |
32 class SchedulerWorkerPoolParams; | |
33 | 33 |
34 // Interface for a task scheduler and static methods to manage the instance used | 34 // Interface for a task scheduler and static methods to manage the instance used |
35 // by the post_task.h API. Note: all base/task_scheduler users should go through | 35 // by the post_task.h API. Note: all base/task_scheduler users should go through |
36 // post_task.h instead of TaskScheduler except for the one callsite per process | 36 // post_task.h instead of TaskScheduler except for the one callsite per process |
37 // which manages the process' instance. | 37 // which manages the process' instance. |
38 class BASE_EXPORT TaskScheduler { | 38 class BASE_EXPORT TaskScheduler { |
39 public: | 39 public: |
40 struct BASE_EXPORT InitParams { | |
robliao
2017/03/24 21:41:06
You'll want to fix this:
E:\b\c\b\win_clang\src\b
fdoray
2017/03/28 13:42:37
Done.
| |
41 InitParams( | |
42 const SchedulerWorkerPoolParams& background_worker_pool_params_in, | |
43 const SchedulerWorkerPoolParams& | |
44 background_blocking_worker_pool_params_in, | |
45 const SchedulerWorkerPoolParams& foreground_worker_pool_params_in, | |
46 const SchedulerWorkerPoolParams& | |
47 foreground_blocking_worker_pool_params_in); | |
48 | |
49 const SchedulerWorkerPoolParams background_worker_pool_params; | |
50 const SchedulerWorkerPoolParams background_blocking_worker_pool_params; | |
51 const SchedulerWorkerPoolParams foreground_worker_pool_params; | |
52 const SchedulerWorkerPoolParams foreground_blocking_worker_pool_params; | |
53 }; | |
54 | |
40 // Returns the index of the worker pool in which a task with |traits| should | 55 // Returns the index of the worker pool in which a task with |traits| should |
41 // run. This should be coded in a future-proof way: new traits should | 56 // run. This should be coded in a future-proof way: new traits should |
42 // gracefully map to a default pool. | 57 // gracefully map to a default pool. |
43 using WorkerPoolIndexForTraitsCallback = | 58 using WorkerPoolIndexForTraitsCallback = |
44 Callback<size_t(const TaskTraits& traits)>; | 59 Callback<size_t(const TaskTraits& traits)>; |
45 | 60 |
46 // Destroying a TaskScheduler is not allowed in production; it is always | 61 // Destroying a TaskScheduler is not allowed in production; it is always |
47 // leaked. In tests, it should only be destroyed after JoinForTesting() has | 62 // leaked. In tests, it should only be destroyed after JoinForTesting() has |
48 // returned. | 63 // returned. |
49 virtual ~TaskScheduler() = default; | 64 virtual ~TaskScheduler() = default; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 // this. CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler | 129 // this. CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler |
115 // (ensures isolation). | 130 // (ensures isolation). |
116 static void CreateAndSetSimpleTaskScheduler(const std::string& name); | 131 static void CreateAndSetSimpleTaskScheduler(const std::string& name); |
117 #endif // !defined(OS_NACL) | 132 #endif // !defined(OS_NACL) |
118 | 133 |
119 // Creates and sets a task scheduler with custom worker pools. CHECKs on | 134 // Creates and sets a task scheduler with custom worker pools. CHECKs on |
120 // failure. |worker_pool_params_vector| describes the worker pools to create. | 135 // failure. |worker_pool_params_vector| describes the worker pools to create. |
121 // |worker_pool_index_for_traits_callback| returns the index in |worker_pools| | 136 // |worker_pool_index_for_traits_callback| returns the index in |worker_pools| |
122 // of the worker pool in which a task with given traits should run. For tests, | 137 // of the worker pool in which a task with given traits should run. For tests, |
123 // prefer base::test::ScopedTaskScheduler (ensures isolation). | 138 // prefer base::test::ScopedTaskScheduler (ensures isolation). |
139 // | |
140 // Deprecated. Use the overload below instead. https://crbug.com/690706 | |
124 static void CreateAndSetDefaultTaskScheduler( | 141 static void CreateAndSetDefaultTaskScheduler( |
125 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector, | 142 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector, |
126 const WorkerPoolIndexForTraitsCallback& | 143 const WorkerPoolIndexForTraitsCallback& |
127 worker_pool_index_for_traits_callback); | 144 worker_pool_index_for_traits_callback); |
128 | 145 |
146 // Creates and sets a task scheduler using custom params. |name| is used to | |
147 // label threads and histograms. It should identify the component that creates | |
148 // the TaskScheduler. |init_params| is used to initialize the worker pools. | |
149 // CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler | |
150 // (ensures isolation). | |
151 // | |
152 // Note: The names and priority hints in |init_params| are ignored (ref. TODO | |
153 // to remove them). | |
154 static void CreateAndSetDefaultTaskScheduler(const std::string& name, | |
155 const InitParams& init_params); | |
156 | |
129 // Registers |task_scheduler| to handle tasks posted through the post_task.h | 157 // Registers |task_scheduler| to handle tasks posted through the post_task.h |
130 // API for this process. For tests, prefer base::test::ScopedTaskScheduler | 158 // API for this process. For tests, prefer base::test::ScopedTaskScheduler |
131 // (ensures isolation). | 159 // (ensures isolation). |
132 static void SetInstance(std::unique_ptr<TaskScheduler> task_scheduler); | 160 static void SetInstance(std::unique_ptr<TaskScheduler> task_scheduler); |
133 | 161 |
134 // Retrieve the TaskScheduler set via SetInstance() or | 162 // Retrieve the TaskScheduler set via SetInstance() or |
135 // CreateAndSet(Simple|Default)TaskScheduler(). This should be used very | 163 // CreateAndSet(Simple|Default)TaskScheduler(). This should be used very |
136 // rarely; most users of TaskScheduler should use the post_task.h API. In | 164 // rarely; most users of TaskScheduler should use the post_task.h API. In |
137 // particular, refrain from doing | 165 // particular, refrain from doing |
138 // if (!TaskScheduler::GetInstance()) { | 166 // if (!TaskScheduler::GetInstance()) { |
(...skipping 16 matching lines...) Expand all Loading... | |
155 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items. | 183 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items. |
156 // | 184 // |
157 // TODO(fdoray): Remove this method. https://crbug.com/687264 | 185 // TODO(fdoray): Remove this method. https://crbug.com/687264 |
158 virtual int GetMaxConcurrentTasksWithTraitsDeprecated( | 186 virtual int GetMaxConcurrentTasksWithTraitsDeprecated( |
159 const TaskTraits& traits) const = 0; | 187 const TaskTraits& traits) const = 0; |
160 }; | 188 }; |
161 | 189 |
162 } // namespace base | 190 } // namespace base |
163 | 191 |
164 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ | 192 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ |
OLD | NEW |