OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_THREADING_SEQUENCED_WORKER_POOL_H_ | 5 #ifndef BASE_THREADING_SEQUENCED_WORKER_POOL_H_ |
6 #define BASE_THREADING_SEQUENCED_WORKER_POOL_H_ | 6 #define BASE_THREADING_SEQUENCED_WORKER_POOL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <cstddef> | 10 #include <cstddef> |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 static SequenceToken GetSequenceToken(); | 173 static SequenceToken GetSequenceToken(); |
174 | 174 |
175 // Starts redirecting tasks posted to this process' SequencedWorkerPools to | 175 // Starts redirecting tasks posted to this process' SequencedWorkerPools to |
176 // the registered TaskScheduler. This cannot be called after a task has been | 176 // the registered TaskScheduler. This cannot be called after a task has been |
177 // posted to a SequencedWorkerPool. This is not thread-safe; proper | 177 // posted to a SequencedWorkerPool. This is not thread-safe; proper |
178 // synchronization is required to use any SequencedWorkerPool method after | 178 // synchronization is required to use any SequencedWorkerPool method after |
179 // calling this. There must be a registered TaskScheduler when this is called. | 179 // calling this. There must be a registered TaskScheduler when this is called. |
180 // Ideally, call this on the main thread of a process, before any other | 180 // Ideally, call this on the main thread of a process, before any other |
181 // threads are created and before any tasks are posted to that process' | 181 // threads are created and before any tasks are posted to that process' |
182 // SequencedWorkerPools. | 182 // SequencedWorkerPools. |
183 // Note: SequencedWorkerPool instances with |max_threads == 1| will be special | |
184 // cased to send all of their work as ExecutionMode::SINGLE_THREADED. | |
185 // TODO(gab): Remove this if http://crbug.com/622400 fails | 183 // TODO(gab): Remove this if http://crbug.com/622400 fails |
186 // (SequencedWorkerPool will be phased out completely otherwise). | 184 // (SequencedWorkerPool will be phased out completely otherwise). |
187 static void RedirectToTaskSchedulerForProcess(); | 185 static void RedirectToTaskSchedulerForProcess(); |
188 | 186 |
189 // Stops redirecting tasks posted to this process' SequencedWorkerPools to the | 187 // Stops redirecting tasks posted to this process' SequencedWorkerPools to the |
190 // registered TaskScheduler and allows RedirectToTaskSchedulerForProcess() to | 188 // registered TaskScheduler and allows RedirectToTaskSchedulerForProcess() to |
191 // be called even if tasks have already posted to a SequencedWorkerPool in | 189 // be called even if tasks have already posted to a SequencedWorkerPool in |
192 // this process. Calling this while there are active SequencedWorkerPools is | 190 // this process. Calling this while there are active SequencedWorkerPools is |
193 // not supported. This is not thread-safe; proper synchronization is required | 191 // not supported. This is not thread-safe; proper synchronization is required |
194 // to use any SequencedWorkerPool method after calling this. | 192 // to use any SequencedWorkerPool method after calling this. |
195 static void ResetRedirectToTaskSchedulerForProcessForTesting(); | 193 static void ResetRedirectToTaskSchedulerForProcessForTesting(); |
196 | 194 |
197 // When constructing a SequencedWorkerPool, there must be a | 195 // When constructing a SequencedWorkerPool, there must be a |
198 // ThreadTaskRunnerHandle on the current thread unless you plan to | 196 // ThreadTaskRunnerHandle on the current thread unless you plan to |
199 // deliberately leak it. | 197 // deliberately leak it. |
200 | 198 |
201 // Pass the maximum number of threads (they will be lazily created as needed) | 199 // Constructs a SequencedWorkerPool which will lazily create up to |
202 // and a prefix for the thread name to aid in debugging. |task_priority| will | 200 // |max_threads| and a prefix for the thread name to aid in debugging. |
203 // be used to hint base::TaskScheduler for an experiment in which all | 201 // |max_threads| must be greater than 1. |task_priority| will be used to hint |
204 // SequencedWorkerPool tasks will be redirected to it in processes where a | 202 // base::TaskScheduler for an experiment in which all SequencedWorkerPool |
205 // base::TaskScheduler was instantiated. | 203 // tasks will be redirected to it in processes where a base::TaskScheduler was |
| 204 // instantiated. |
206 SequencedWorkerPool(size_t max_threads, | 205 SequencedWorkerPool(size_t max_threads, |
207 const std::string& thread_name_prefix, | 206 const std::string& thread_name_prefix, |
208 base::TaskPriority task_priority); | 207 base::TaskPriority task_priority); |
209 | 208 |
210 // Like above, but with |observer| for testing. Does not take ownership of | 209 // Like above, but with |observer| for testing. Does not take ownership of |
211 // |observer|. | 210 // |observer|. |
212 SequencedWorkerPool(size_t max_threads, | 211 SequencedWorkerPool(size_t max_threads, |
213 const std::string& thread_name_prefix, | 212 const std::string& thread_name_prefix, |
214 base::TaskPriority task_priority, | 213 base::TaskPriority task_priority, |
215 TestingObserver* observer); | 214 TestingObserver* observer); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 // Avoid pulling in too many headers by putting (almost) everything | 389 // Avoid pulling in too many headers by putting (almost) everything |
391 // into |inner_|. | 390 // into |inner_|. |
392 const std::unique_ptr<Inner> inner_; | 391 const std::unique_ptr<Inner> inner_; |
393 | 392 |
394 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); | 393 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); |
395 }; | 394 }; |
396 | 395 |
397 } // namespace base | 396 } // namespace base |
398 | 397 |
399 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ | 398 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ |
OLD | NEW |