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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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. |
| 191 // |task_priority| will be used to hint base::TaskScheduler for an experiment |
| 192 // in which all SequencedWorkerPool tasks will be redirected to it. |
190 SequencedWorkerPool(size_t max_threads, | 193 SequencedWorkerPool(size_t max_threads, |
191 const std::string& thread_name_prefix); | 194 const std::string& thread_name_prefix, |
| 195 base::TaskPriority task_priority); |
192 | 196 |
193 // Like above, but with |observer| for testing. Does not take ownership of | 197 // Like above, but with |observer| for testing. Does not take ownership of |
194 // |observer|. | 198 // |observer|. |
195 SequencedWorkerPool(size_t max_threads, | 199 SequencedWorkerPool(size_t max_threads, |
196 const std::string& thread_name_prefix, | 200 const std::string& thread_name_prefix, |
| 201 base::TaskPriority task_priority, |
197 TestingObserver* observer); | 202 TestingObserver* observer); |
198 | 203 |
199 // Returns the sequence token associated with the given name. Calling this | 204 // Returns the sequence token associated with the given name. Calling this |
200 // function multiple times with the same string will always produce the | 205 // 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 | 206 // same sequence token. If the name has not been used before, a new token |
202 // will be created. | 207 // will be created. |
203 SequenceToken GetNamedSequenceToken(const std::string& name); | 208 SequenceToken GetNamedSequenceToken(const std::string& name); |
204 | 209 |
205 // Returns a SequencedTaskRunner wrapper which posts to this | 210 // Returns a SequencedTaskRunner wrapper which posts to this |
206 // SequencedWorkerPool using the given sequence token. Tasks with nonzero | 211 // 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 | 380 // Avoid pulling in too many headers by putting (almost) everything |
376 // into |inner_|. | 381 // into |inner_|. |
377 const std::unique_ptr<Inner> inner_; | 382 const std::unique_ptr<Inner> inner_; |
378 | 383 |
379 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); | 384 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); |
380 }; | 385 }; |
381 | 386 |
382 } // namespace base | 387 } // namespace base |
383 | 388 |
384 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ | 389 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ |
OLD | NEW |