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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 // Does not wait for delayed tasks. Waits for undelayed tasks posted from | 128 // Does not wait for delayed tasks. Waits for undelayed tasks posted from |
129 // other threads during the call. Returns immediately when shutdown completes. | 129 // other threads during the call. Returns immediately when shutdown completes. |
130 virtual void FlushForTesting() = 0; | 130 virtual void FlushForTesting() = 0; |
131 | 131 |
132 // Joins all threads. Tasks that are already running are allowed to complete | 132 // Joins all threads. Tasks that are already running are allowed to complete |
133 // their execution. This can only be called once. Using this task scheduler | 133 // their execution. This can only be called once. Using this task scheduler |
134 // instance to create task runners or post tasks is not permitted during or | 134 // instance to create task runners or post tasks is not permitted during or |
135 // after this call. | 135 // after this call. |
136 virtual void JoinForTesting() = 0; | 136 virtual void JoinForTesting() = 0; |
137 | 137 |
138 // CreateAndSetSimpleTaskScheduler(), CreateAndSetDefaultTaskScheduler(), and | 138 // CreateAndStartWithDefaultParams(), Create(), and SetInstance() register a |
139 // SetInstance() register a TaskScheduler to handle tasks posted through the | 139 // TaskScheduler to handle tasks posted through the post_task.h API for this |
140 // post_task.h API for this process. The registered TaskScheduler will only be | 140 // process. The registered TaskScheduler will only be deleted when a new |
141 // deleted when a new TaskScheduler is registered and is leaked on shutdown. | 141 // TaskScheduler is registered and is leaked on shutdown. The methods must not |
142 // The methods must not be called when TaskRunners created by the previous | 142 // be called when TaskRunners created by the previous TaskScheduler are still |
143 // TaskScheduler are still alive. The methods are not thread-safe; proper | 143 // alive. The methods are not thread-safe; proper synchronization is required to |
144 // synchronization is required to use the post_task.h API after registering a | 144 // use the post_task.h API after registering a new TaskScheduler. |
145 // new TaskScheduler. | |
146 | 145 |
147 #if !defined(OS_NACL) | 146 #if !defined(OS_NACL) |
148 // Creates and sets a task scheduler using default params. |name| is used to | 147 // Creates and starts a task scheduler using default params. |name| is used to |
149 // label threads and histograms. It should identify the component that calls | 148 // label threads and histograms. It should identify the component that calls |
150 // this. CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler | 149 // this. Start() is called by this method; it is invalid to call it again |
151 // (ensures isolation). | 150 // afterwards. CHECKs on failure. For tests, prefer |
151 // base::test::ScopedTaskEnvironment (ensures isolation). | |
152 static void CreateAndStartWithDefaultParams(StringPiece name); | |
153 | |
154 // Deprecated. | |
gab
2017/04/25 15:23:40
// TODO(fdoray): Redirect callers to CreateAndStar
fdoray
2017/04/25 21:56:11
Done.
| |
152 static void CreateAndSetSimpleTaskScheduler(StringPiece name); | 155 static void CreateAndSetSimpleTaskScheduler(StringPiece name); |
153 #endif // !defined(OS_NACL) | 156 #endif // !defined(OS_NACL) |
154 | 157 |
155 // Creates and sets a task scheduler using custom params. |name| is used to | 158 // Creates a task scheduler. |name| is used to label threads and histograms. |
156 // label threads and histograms. It should identify the component that creates | 159 // It should identify the component that creates the TaskScheduler. The task |
157 // the TaskScheduler. |init_params| is used to initialize the worker pools. | 160 // scheduler doesn't create threads until Start() is called. Tasks can be |
158 // CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler | 161 // posted before Start() is called, but they don't run until Start() is |
159 // (ensures isolation). | 162 // called. For tests, prefer base::test::ScopedTaskEnvironment (ensures |
163 // isolation). | |
164 static void Create(StringPiece name); | |
165 | |
166 // Deprecated. | |
gab
2017/04/25 15:23:40
Mention what to use instead.
fdoray
2017/04/25 21:56:11
Done.
| |
160 static void CreateAndSetDefaultTaskScheduler(StringPiece name, | 167 static void CreateAndSetDefaultTaskScheduler(StringPiece name, |
161 const InitParams& init_params); | 168 const InitParams& init_params); |
162 | 169 |
163 // Registers |task_scheduler| to handle tasks posted through the post_task.h | 170 // Registers |task_scheduler| to handle tasks posted through the post_task.h |
164 // API for this process. For tests, prefer base::test::ScopedTaskScheduler | 171 // API for this process. For tests, prefer base::test::ScopedTaskScheduler |
165 // (ensures isolation). | 172 // (ensures isolation). |
166 static void SetInstance(std::unique_ptr<TaskScheduler> task_scheduler); | 173 static void SetInstance(std::unique_ptr<TaskScheduler> task_scheduler); |
167 | 174 |
168 // Retrieve the TaskScheduler set via SetInstance() or | 175 // Retrieve the TaskScheduler set via SetInstance() or |
169 // CreateAndSet(Simple|Default)TaskScheduler(). This should be used very | 176 // CreateAndSet(Simple|Default)TaskScheduler(). This should be used very |
(...skipping 19 matching lines...) Expand all Loading... | |
189 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items. | 196 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items. |
190 // | 197 // |
191 // TODO(fdoray): Remove this method. https://crbug.com/687264 | 198 // TODO(fdoray): Remove this method. https://crbug.com/687264 |
192 virtual int GetMaxConcurrentTasksWithTraitsDeprecated( | 199 virtual int GetMaxConcurrentTasksWithTraitsDeprecated( |
193 const TaskTraits& traits) const = 0; | 200 const TaskTraits& traits) const = 0; |
194 }; | 201 }; |
195 | 202 |
196 } // namespace base | 203 } // namespace base |
197 | 204 |
198 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ | 205 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ |
OLD | NEW |