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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 // pool.PostSequencedWorkerTask(token, SequencedWorkerPool::SKIP_ON_SHUTDOWN, | 54 // pool.PostSequencedWorkerTask(token, SequencedWorkerPool::SKIP_ON_SHUTDOWN, |
55 // FROM_HERE, base::Bind(...)); | 55 // FROM_HERE, base::Bind(...)); |
56 // | 56 // |
57 // You can make named sequence tokens to make it easier to share a token | 57 // You can make named sequence tokens to make it easier to share a token |
58 // across different components. | 58 // across different components. |
59 // | 59 // |
60 // You can also post tasks to the pool without ordering using PostWorkerTask. | 60 // You can also post tasks to the pool without ordering using PostWorkerTask. |
61 // These will be executed in an unspecified order. The order of execution | 61 // These will be executed in an unspecified order. The order of execution |
62 // between tasks with different sequence tokens is also unspecified. | 62 // between tasks with different sequence tokens is also unspecified. |
63 // | 63 // |
64 // You must call EnableForProcess() or | |
65 // EnableWithRedirectionToTaskSchedulerForProcess() before starting to post | |
66 // tasks to a process' SequencedWorkerPools. | |
67 // | |
64 // This class may be leaked on shutdown to facilitate fast shutdown. The | 68 // This class may be leaked on shutdown to facilitate fast shutdown. The |
65 // expected usage, however, is to call Shutdown(), which correctly accounts | 69 // expected usage, however, is to call Shutdown(), which correctly accounts |
66 // for CONTINUE_ON_SHUTDOWN behavior and is required for BLOCK_SHUTDOWN | 70 // for CONTINUE_ON_SHUTDOWN behavior and is required for BLOCK_SHUTDOWN |
67 // behavior. | 71 // behavior. |
68 // | 72 // |
69 // Implementation note: This does not use a base::WorkerPool since that does | 73 // Implementation note: This does not use a base::WorkerPool since that does |
70 // not enforce shutdown semantics or allow us to specify how many worker | 74 // not enforce shutdown semantics or allow us to specify how many worker |
71 // threads to run. For the typical use case of random background work, we don't | 75 // threads to run. For the typical use case of random background work, we don't |
72 // necessarily want to be super aggressive about creating threads. | 76 // necessarily want to be super aggressive about creating threads. |
73 // | 77 // |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 // DEPRECATED. Use SequencedTaskRunnerHandle::Get() instead. Consequentially | 177 // DEPRECATED. Use SequencedTaskRunnerHandle::Get() instead. Consequentially |
174 // the only remaining use case is in sequenced_task_runner_handle.cc to | 178 // the only remaining use case is in sequenced_task_runner_handle.cc to |
175 // implement that and will soon be removed along with SequencedWorkerPool: | 179 // implement that and will soon be removed along with SequencedWorkerPool: |
176 // http://crbug.com/622400. | 180 // http://crbug.com/622400. |
177 static scoped_refptr<SequencedWorkerPool> GetWorkerPoolForCurrentThread(); | 181 static scoped_refptr<SequencedWorkerPool> GetWorkerPoolForCurrentThread(); |
178 | 182 |
179 // Returns a unique token that can be used to sequence tasks posted to | 183 // Returns a unique token that can be used to sequence tasks posted to |
180 // PostSequencedWorkerTask(). Valid tokens are always nonzero. | 184 // PostSequencedWorkerTask(). Valid tokens are always nonzero. |
181 static SequenceToken GetSequenceToken(); | 185 static SequenceToken GetSequenceToken(); |
182 | 186 |
183 // Starts redirecting tasks posted to this process' SequencedWorkerPools to | 187 // Enables posting tasks to this process' SequencedWorkerPools. Cannot be |
184 // the registered TaskScheduler. This cannot be called after a task has been | 188 // called if already enabled. This is not thread-safe; proper synchronization |
185 // posted to a SequencedWorkerPool. This is not thread-safe; proper | 189 // is required to use any SequencedWorkerPool method after calling this. |
186 // synchronization is required to use any SequencedWorkerPool method after | 190 static void EnableForProcess(); |
187 // calling this. There must be a registered TaskScheduler when this is called. | 191 |
188 // Ideally, call this on the main thread of a process, before any other | 192 // Same as EnableForProcess(), but tasks are redirected to the registered |
189 // threads are created and before any tasks are posted to that process' | 193 // TaskScheduler. There must be a registered TaskScheduler when this is |
190 // SequencedWorkerPools. | 194 // called. |
191 // TODO(gab): Remove this if http://crbug.com/622400 fails | 195 // TODO(gab): Remove this if http://crbug.com/622400 fails |
192 // (SequencedWorkerPool will be phased out completely otherwise). | 196 // (SequencedWorkerPool will be phased out completely otherwise). |
193 static void RedirectToTaskSchedulerForProcess(); | 197 static void EnableWithRedirectionToTaskSchedulerForProcess(); |
194 | 198 |
195 // Stops redirecting tasks posted to this process' SequencedWorkerPools to the | 199 // Disables posting tasks to this process' SequencedWorkerPools. Calling this |
196 // registered TaskScheduler and allows RedirectToTaskSchedulerForProcess() to | 200 // while there are active SequencedWorkerPools is not supported. This is not |
197 // be called even if tasks have already posted to a SequencedWorkerPool in | 201 // thread-safe; proper synchronization is required to use any |
198 // this process. Calling this while there are active SequencedWorkerPools is | 202 // SequencedWorkerPool method after calling this. |
199 // not supported. This is not thread-safe; proper synchronization is required | 203 static void DisableForProcessForTesting(); |
200 // to use any SequencedWorkerPool method after calling this. | 204 |
201 static void ResetRedirectToTaskSchedulerForProcessForTesting(); | 205 // Returns true is posting tasks to this process' SequencedWorkerPool is |
gab
2016/11/01 21:48:02
s/is/if/
fdoray
2016/11/02 12:56:09
Done.
| |
206 // enabled (with or without redirection to TaskScheduler). | |
207 static bool IsEnabled(); | |
202 | 208 |
203 // When constructing a SequencedWorkerPool, there must be a | 209 // When constructing a SequencedWorkerPool, there must be a |
204 // ThreadTaskRunnerHandle on the current thread unless you plan to | 210 // ThreadTaskRunnerHandle on the current thread unless you plan to |
205 // deliberately leak it. | 211 // deliberately leak it. |
206 | 212 |
207 // Constructs a SequencedWorkerPool which will lazily create up to | 213 // Constructs a SequencedWorkerPool which will lazily create up to |
208 // |max_threads| and a prefix for the thread name to aid in debugging. | 214 // |max_threads| and a prefix for the thread name to aid in debugging. |
209 // |max_threads| must be greater than 1. |task_priority| will be used to hint | 215 // |max_threads| must be greater than 1. |task_priority| will be used to hint |
210 // base::TaskScheduler for an experiment in which all SequencedWorkerPool | 216 // base::TaskScheduler for an experiment in which all SequencedWorkerPool |
211 // tasks will be redirected to it in processes where a base::TaskScheduler was | 217 // tasks will be redirected to it in processes where a base::TaskScheduler was |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 // Avoid pulling in too many headers by putting (almost) everything | 409 // Avoid pulling in too many headers by putting (almost) everything |
404 // into |inner_|. | 410 // into |inner_|. |
405 const std::unique_ptr<Inner> inner_; | 411 const std::unique_ptr<Inner> inner_; |
406 | 412 |
407 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); | 413 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); |
408 }; | 414 }; |
409 | 415 |
410 } // namespace base | 416 } // namespace base |
411 | 417 |
412 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ | 418 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ |
OLD | NEW |