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 <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... | |
26 | 26 |
27 namespace tracked_objects { | 27 namespace tracked_objects { |
28 class Location; | 28 class Location; |
29 } | 29 } |
30 | 30 |
31 namespace base { | 31 namespace base { |
32 | 32 |
33 class HistogramBase; | 33 class HistogramBase; |
34 | 34 |
35 // Interface for a task scheduler and static methods to manage the instance used | 35 // Interface for a task scheduler and static methods to manage the instance used |
36 // by the post_task.h API. Note: all base/task_scheduler users should go through | 36 // by the post_task.h API. |
37 // post_task.h instead of TaskScheduler except for the one callsite per process | 37 // |
38 // which manages the process' instance. | 38 // The task scheduler doesn't create threads before Start() is called. Tasks can |
39 // be posted before Start() is called, but they don't run until Start() is | |
40 // called. | |
41 // | |
42 // The non-static methods of this class are thread-safe. | |
robliao
2017/04/24 22:32:19
Nit: non-static -> instance
fdoray
2017/04/25 18:43:34
Done.
| |
43 // | |
44 // Note: all base/task_scheduler users should go through post_task.h instead of | |
robliao
2017/04/24 22:32:19
Nit: all -> All
gab
2017/04/25 15:16:15
I don't think this is required (and IMO capital le
robliao
2017/04/25 17:37:28
http://apvschicago.com/2011/04/capitalization-afte
fdoray
2017/04/25 18:43:34
Done.
| |
45 // TaskScheduler except for the one callsite per process which manages the | |
46 // process' instance. | |
robliao
2017/04/24 22:32:19
Nit: process's
gab
2017/04/25 15:16:15
Don't think this is required either (I sure always
robliao
2017/04/25 17:37:27
In this case, because process is singular, process
fdoray
2017/04/25 18:43:34
Done.
| |
39 class BASE_EXPORT TaskScheduler { | 47 class BASE_EXPORT TaskScheduler { |
40 public: | 48 public: |
41 struct BASE_EXPORT InitParams { | 49 struct BASE_EXPORT InitParams { |
42 InitParams( | 50 InitParams( |
43 const SchedulerWorkerPoolParams& background_worker_pool_params_in, | 51 const SchedulerWorkerPoolParams& background_worker_pool_params_in, |
44 const SchedulerWorkerPoolParams& | 52 const SchedulerWorkerPoolParams& |
45 background_blocking_worker_pool_params_in, | 53 background_blocking_worker_pool_params_in, |
46 const SchedulerWorkerPoolParams& foreground_worker_pool_params_in, | 54 const SchedulerWorkerPoolParams& foreground_worker_pool_params_in, |
47 const SchedulerWorkerPoolParams& | 55 const SchedulerWorkerPoolParams& |
48 foreground_blocking_worker_pool_params_in); | 56 foreground_blocking_worker_pool_params_in); |
49 ~InitParams(); | 57 ~InitParams(); |
50 | 58 |
51 const SchedulerWorkerPoolParams background_worker_pool_params; | 59 const SchedulerWorkerPoolParams background_worker_pool_params; |
52 const SchedulerWorkerPoolParams background_blocking_worker_pool_params; | 60 const SchedulerWorkerPoolParams background_blocking_worker_pool_params; |
53 const SchedulerWorkerPoolParams foreground_worker_pool_params; | 61 const SchedulerWorkerPoolParams foreground_worker_pool_params; |
54 const SchedulerWorkerPoolParams foreground_blocking_worker_pool_params; | 62 const SchedulerWorkerPoolParams foreground_blocking_worker_pool_params; |
55 }; | 63 }; |
56 | 64 |
57 // Destroying a TaskScheduler is not allowed in production; it is always | 65 // Destroying a TaskScheduler is not allowed in production; it is always |
58 // leaked. In tests, it should only be destroyed after JoinForTesting() has | 66 // leaked. In tests, it should only be destroyed after JoinForTesting() has |
59 // returned. | 67 // returned. |
60 virtual ~TaskScheduler() = default; | 68 virtual ~TaskScheduler() = default; |
61 | 69 |
70 // Allows the task scheduler to create threads and run tasks following the | |
71 // |init_params| specification. CHECKs on failure. | |
72 virtual void Start(const InitParams& init_params) = 0; | |
73 | |
62 // Posts |task| with a |delay| and specific |traits|. |delay| can be zero. | 74 // Posts |task| with a |delay| and specific |traits|. |delay| can be zero. |
63 // For one off tasks that don't require a TaskRunner. | 75 // For one off tasks that don't require a TaskRunner. |
64 virtual void PostDelayedTaskWithTraits( | 76 virtual void PostDelayedTaskWithTraits( |
65 const tracked_objects::Location& from_here, | 77 const tracked_objects::Location& from_here, |
66 const TaskTraits& traits, | 78 const TaskTraits& traits, |
67 OnceClosure task, | 79 OnceClosure task, |
68 TimeDelta delay) = 0; | 80 TimeDelta delay) = 0; |
69 | 81 |
70 // Returns a TaskRunner whose PostTask invocations result in scheduling tasks | 82 // Returns a TaskRunner whose PostTask invocations result in scheduling tasks |
71 // using |traits|. Tasks may run in any order and in parallel. | 83 // using |traits|. Tasks may run in any order and in parallel. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 // label threads and histograms. It should identify the component that calls | 149 // label threads and histograms. It should identify the component that calls |
138 // this. CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler | 150 // this. CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler |
139 // (ensures isolation). | 151 // (ensures isolation). |
140 static void CreateAndSetSimpleTaskScheduler(StringPiece name); | 152 static void CreateAndSetSimpleTaskScheduler(StringPiece name); |
141 #endif // !defined(OS_NACL) | 153 #endif // !defined(OS_NACL) |
142 | 154 |
143 // Creates and sets a task scheduler using custom params. |name| is used to | 155 // Creates and sets a task scheduler using custom params. |name| is used to |
144 // label threads and histograms. It should identify the component that creates | 156 // label threads and histograms. It should identify the component that creates |
145 // the TaskScheduler. |init_params| is used to initialize the worker pools. | 157 // the TaskScheduler. |init_params| is used to initialize the worker pools. |
146 // CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler | 158 // CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler |
147 // (ensures isolation). | 159 // (ensures isolation). |
gab
2017/04/25 15:20:01
Actually, this is the API that needs to be updated
gab
2017/04/25 15:21:11
Nvm, found answer @ https://codereview.chromium.or
fdoray
2017/04/25 18:43:34
Yes.
| |
148 static void CreateAndSetDefaultTaskScheduler(StringPiece name, | 160 static void CreateAndSetDefaultTaskScheduler(StringPiece name, |
149 const InitParams& init_params); | 161 const InitParams& init_params); |
150 | 162 |
151 // Registers |task_scheduler| to handle tasks posted through the post_task.h | 163 // Registers |task_scheduler| to handle tasks posted through the post_task.h |
152 // API for this process. For tests, prefer base::test::ScopedTaskScheduler | 164 // API for this process. For tests, prefer base::test::ScopedTaskScheduler |
153 // (ensures isolation). | 165 // (ensures isolation). |
154 static void SetInstance(std::unique_ptr<TaskScheduler> task_scheduler); | 166 static void SetInstance(std::unique_ptr<TaskScheduler> task_scheduler); |
155 | 167 |
156 // Retrieve the TaskScheduler set via SetInstance() or | 168 // Retrieve the TaskScheduler set via SetInstance() or |
157 // CreateAndSet(Simple|Default)TaskScheduler(). This should be used very | 169 // CreateAndSet(Simple|Default)TaskScheduler(). This should be used very |
(...skipping 19 matching lines...) Expand all Loading... | |
177 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items. | 189 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items. |
178 // | 190 // |
179 // TODO(fdoray): Remove this method. https://crbug.com/687264 | 191 // TODO(fdoray): Remove this method. https://crbug.com/687264 |
180 virtual int GetMaxConcurrentTasksWithTraitsDeprecated( | 192 virtual int GetMaxConcurrentTasksWithTraitsDeprecated( |
181 const TaskTraits& traits) const = 0; | 193 const TaskTraits& traits) const = 0; |
182 }; | 194 }; |
183 | 195 |
184 } // namespace base | 196 } // namespace base |
185 | 197 |
186 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ | 198 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ |
OLD | NEW |