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 // Starts redirecting tasks posted to this process' SequencedWorkerPools to |
176 // are created and before any tasks are posted to that process' | 176 // the registered TaskScheduler. This cannot be called after a task has been |
177 // SequencedWorkerPools but after TaskScheduler was instantiated, to force all | 177 // posted to a SequencedWorkerPool. This is not thread-safe; proper |
178 // SequencedWorkerPools in that process to redirect their tasks to the | 178 // synchronization is required to use any SequencedWorkerPool method after |
179 // TaskScheduler. Note: SequencedWorkerPool instances with |max_threads == 1| | 179 // calling this. There must be a registered TaskScheduler when this is called. |
180 // will be special cased to send all of their work as | 180 // Ideally, call this on the main thread of a process, before any other |
181 // ExecutionMode::SINGLE_THREADED. | 181 // threads are created and before any tasks are posted to that process' |
| 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. |
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 and allows RedirectToTaskSchedulerForProcess() to |
| 191 // be called even if tasks have already posted to a SequencedWorkerPool in |
| 192 // this process. Calling this while there are active SequencedWorkerPools is |
| 193 // not supported. This is not thread-safe; proper synchronization is required |
| 194 // to use any SequencedWorkerPool method after calling this. |
| 195 static void ResetRedirectToTaskSchedulerForProcessForTesting(); |
185 | 196 |
186 // When constructing a SequencedWorkerPool, there must be a | 197 // When constructing a SequencedWorkerPool, there must be a |
187 // ThreadTaskRunnerHandle on the current thread unless you plan to | 198 // ThreadTaskRunnerHandle on the current thread unless you plan to |
188 // deliberately leak it. | 199 // deliberately leak it. |
189 | 200 |
190 // Pass the maximum number of threads (they will be lazily created as needed) | 201 // 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 | 202 // 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 | 203 // be used to hint base::TaskScheduler for an experiment in which all |
193 // SequencedWorkerPool tasks will be redirected to it in processes where a | 204 // SequencedWorkerPool tasks will be redirected to it in processes where a |
194 // base::TaskScheduler was instantiated. | 205 // base::TaskScheduler was instantiated. |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 // Avoid pulling in too many headers by putting (almost) everything | 390 // Avoid pulling in too many headers by putting (almost) everything |
380 // into |inner_|. | 391 // into |inner_|. |
381 const std::unique_ptr<Inner> inner_; | 392 const std::unique_ptr<Inner> inner_; |
382 | 393 |
383 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); | 394 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); |
384 }; | 395 }; |
385 | 396 |
386 } // namespace base | 397 } // namespace base |
387 | 398 |
388 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ | 399 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ |
OLD | NEW |