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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 static SequenceToken GetSequenceTokenForCurrentThread(); | 165 static SequenceToken GetSequenceTokenForCurrentThread(); |
166 | 166 |
167 // Returns the SequencedWorkerPool that owns this thread, or null if the | 167 // Returns the SequencedWorkerPool that owns this thread, or null if the |
168 // current thread is not a SequencedWorkerPool worker thread. | 168 // current thread is not a SequencedWorkerPool worker thread. |
169 static scoped_refptr<SequencedWorkerPool> GetWorkerPoolForCurrentThread(); | 169 static scoped_refptr<SequencedWorkerPool> GetWorkerPoolForCurrentThread(); |
170 | 170 |
171 // Returns a unique token that can be used to sequence tasks posted to | 171 // Returns a unique token that can be used to sequence tasks posted to |
172 // PostSequencedWorkerTask(). Valid tokens are always nonzero. | 172 // PostSequencedWorkerTask(). Valid tokens are always nonzero. |
173 static SequenceToken GetSequenceToken(); | 173 static SequenceToken GetSequenceToken(); |
174 | 174 |
175 // Invoke this once on the main thread of a process, before any other threads | 175 // Invoke this to start redirecting tasks posted to this process' |
176 // are created and before any tasks are posted to that process' | 176 // SequencedWorkerPools to the registered TaskScheduler. This cannot be called |
177 // SequencedWorkerPools but after TaskScheduler was instantiated, to force all | 177 // after a task has been posted to a SequencedWorkerPool. This is not thread- |
178 // SequencedWorkerPools in that process to redirect their tasks to the | 178 // safe; proper synchronization is required to use any method of |
179 // TaskScheduler. Note: SequencedWorkerPool instances with |max_threads == 1| | 179 // SequencedWorkerPool after calling this. There must be a registered |
180 // will be special cased to send all of their work as | 180 // TaskScheduler when this is called. Ideally, call this on the main thread of |
181 // ExecutionMode::SINGLE_THREADED. | 181 // a process, before any other threads are created and before any tasks are |
| 182 // posted to that process' SequencedWorkerPools. |
| 183 // Note: SequencedWorkerPool instances with |max_threads == 1| will be special |
| 184 // cased to send all of their work as ExecutionMode::SINGLE_THREADED. |
182 // TODO(gab): Remove this if http://crbug.com/622400 fails | 185 // TODO(gab): Remove this if http://crbug.com/622400 fails |
183 // (SequencedWorkerPool will be phased out completely otherwise). | 186 // (SequencedWorkerPool will be phased out completely otherwise). |
184 static void RedirectSequencedWorkerPoolsToTaskSchedulerForProcess(); | 187 static void RedirectToTaskSchedulerForProcess(); |
| 188 |
| 189 // Stops redirecting tasks posted to this process' SequencedWorkerPools to the |
| 190 // registered TaskScheduler. Also allows RedirectToTaskSchedulerForProcess() |
| 191 // to be called again after tasks have been posted to this process' |
| 192 // SequencedWorkerPools. Calling this while there are active |
| 193 // SequencedWorkerPools isn't supported. This is not thread-safe; proper |
| 194 // synchronization is required to call any method of SequencedWorkerPool after |
| 195 // calling this. |
| 196 static void ResetRedirectToTaskSchedulerForProcessForTesting(); |
185 | 197 |
186 // When constructing a SequencedWorkerPool, there must be a | 198 // When constructing a SequencedWorkerPool, there must be a |
187 // ThreadTaskRunnerHandle on the current thread unless you plan to | 199 // ThreadTaskRunnerHandle on the current thread unless you plan to |
188 // deliberately leak it. | 200 // deliberately leak it. |
189 | 201 |
190 // Pass the maximum number of threads (they will be lazily created as needed) | 202 // Pass the maximum number of threads (they will be lazily created as needed) |
191 // and a prefix for the thread name to aid in debugging. |task_priority| will | 203 // and a prefix for the thread name to aid in debugging. |task_priority| will |
192 // be used to hint base::TaskScheduler for an experiment in which all | 204 // be used to hint base::TaskScheduler for an experiment in which all |
193 // SequencedWorkerPool tasks will be redirected to it in processes where a | 205 // SequencedWorkerPool tasks will be redirected to it in processes where a |
194 // base::TaskScheduler was instantiated. | 206 // base::TaskScheduler was instantiated. |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 // Avoid pulling in too many headers by putting (almost) everything | 390 // Avoid pulling in too many headers by putting (almost) everything |
379 // into |inner_|. | 391 // into |inner_|. |
380 const std::unique_ptr<Inner> inner_; | 392 const std::unique_ptr<Inner> inner_; |
381 | 393 |
382 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); | 394 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); |
383 }; | 395 }; |
384 | 396 |
385 } // namespace base | 397 } // namespace base |
386 | 398 |
387 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ | 399 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ |
OLD | NEW |