| 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> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/base_export.h" | 14 #include "base/base_export.h" |
| 15 #include "base/callback_forward.h" | 15 #include "base/callback_forward.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 19 #include "base/task_runner.h" | 19 #include "base/task_runner.h" |
| 20 #include "base/task_scheduler/task_traits.h" |
| 20 | 21 |
| 21 namespace tracked_objects { | 22 namespace tracked_objects { |
| 22 class Location; | 23 class Location; |
| 23 } // namespace tracked_objects | 24 } // namespace tracked_objects |
| 24 | 25 |
| 25 namespace base { | 26 namespace base { |
| 26 | 27 |
| 27 class SingleThreadTaskRunner; | 28 class SingleThreadTaskRunner; |
| 28 | 29 |
| 29 template <class T> class DeleteHelper; | 30 template <class T> class DeleteHelper; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 | 180 |
| 180 // Returns the SequencedWorkerPool that owns this thread, or null if the | 181 // Returns the SequencedWorkerPool that owns this thread, or null if the |
| 181 // current thread is not a SequencedWorkerPool worker thread. | 182 // current thread is not a SequencedWorkerPool worker thread. |
| 182 static scoped_refptr<SequencedWorkerPool> GetWorkerPoolForCurrentThread(); | 183 static scoped_refptr<SequencedWorkerPool> GetWorkerPoolForCurrentThread(); |
| 183 | 184 |
| 184 // When constructing a SequencedWorkerPool, there must be a | 185 // When constructing a SequencedWorkerPool, there must be a |
| 185 // ThreadTaskRunnerHandle on the current thread unless you plan to | 186 // ThreadTaskRunnerHandle on the current thread unless you plan to |
| 186 // deliberately leak it. | 187 // deliberately leak it. |
| 187 | 188 |
| 188 // Pass the maximum number of threads (they will be lazily created as needed) | 189 // Pass the maximum number of threads (they will be lazily created as needed) |
| 189 // and a prefix for the thread name to aid in debugging. | 190 // and a prefix for the thread name to aid in debugging. |task_priority| will |
| 191 // be used to hint base::TaskScheduler for an experiment in which all |
| 192 // SequencedWorkerPool tasks will be redirected to it in processes where a |
| 193 // base::TaskScheduler was instantiated. |
| 194 SequencedWorkerPool(size_t max_threads, |
| 195 const std::string& thread_name_prefix, |
| 196 base::TaskPriority task_priority); |
| 197 |
| 198 // Deprecated, use the above constructor with |task_priority| instead. |
| 199 // TODO(gab): Cleanup last few use cases of this before running the |
| 200 // aforementioned base::TaskScheduler experiment (or make sure this |
| 201 // constructor results in callers being opted out of the experiment). |
| 190 SequencedWorkerPool(size_t max_threads, | 202 SequencedWorkerPool(size_t max_threads, |
| 191 const std::string& thread_name_prefix); | 203 const std::string& thread_name_prefix); |
| 192 | 204 |
| 193 // Like above, but with |observer| for testing. Does not take ownership of | 205 // Like above, but with |observer| for testing. Does not take ownership of |
| 194 // |observer|. | 206 // |observer|. |
| 195 SequencedWorkerPool(size_t max_threads, | 207 SequencedWorkerPool(size_t max_threads, |
| 196 const std::string& thread_name_prefix, | 208 const std::string& thread_name_prefix, |
| 209 base::TaskPriority task_priority, |
| 197 TestingObserver* observer); | 210 TestingObserver* observer); |
| 198 | 211 |
| 199 // Returns the sequence token associated with the given name. Calling this | 212 // Returns the sequence token associated with the given name. Calling this |
| 200 // function multiple times with the same string will always produce the | 213 // function multiple times with the same string will always produce the |
| 201 // same sequence token. If the name has not been used before, a new token | 214 // same sequence token. If the name has not been used before, a new token |
| 202 // will be created. | 215 // will be created. |
| 203 SequenceToken GetNamedSequenceToken(const std::string& name); | 216 SequenceToken GetNamedSequenceToken(const std::string& name); |
| 204 | 217 |
| 205 // Returns a SequencedTaskRunner wrapper which posts to this | 218 // Returns a SequencedTaskRunner wrapper which posts to this |
| 206 // SequencedWorkerPool using the given sequence token. Tasks with nonzero | 219 // SequencedWorkerPool using the given sequence token. Tasks with nonzero |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 // Avoid pulling in too many headers by putting (almost) everything | 388 // Avoid pulling in too many headers by putting (almost) everything |
| 376 // into |inner_|. | 389 // into |inner_|. |
| 377 const std::unique_ptr<Inner> inner_; | 390 const std::unique_ptr<Inner> inner_; |
| 378 | 391 |
| 379 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); | 392 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); |
| 380 }; | 393 }; |
| 381 | 394 |
| 382 } // namespace base | 395 } // namespace base |
| 383 | 396 |
| 384 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ | 397 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ |
| OLD | NEW |