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 <cstddef> | 8 #include <cstddef> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 SequencedWorkerPool(size_t max_threads, | 152 SequencedWorkerPool(size_t max_threads, |
153 const std::string& thread_name_prefix); | 153 const std::string& thread_name_prefix); |
154 | 154 |
155 // Like above, but with |observer| for testing. Does not take | 155 // Like above, but with |observer| for testing. Does not take |
156 // ownership of |observer|. | 156 // ownership of |observer|. |
157 SequencedWorkerPool(size_t max_threads, | 157 SequencedWorkerPool(size_t max_threads, |
158 const std::string& thread_name_prefix, | 158 const std::string& thread_name_prefix, |
159 TestingObserver* observer); | 159 TestingObserver* observer); |
160 | 160 |
161 // Returns a unique token that can be used to sequence tasks posted to | 161 // Returns a unique token that can be used to sequence tasks posted to |
162 // PostSequencedWorkerTask(). Valid tokens are alwys nonzero. | 162 // PostSequencedWorkerTask(). Valid tokens are always nonzero. |
163 SequenceToken GetSequenceToken(); | 163 SequenceToken GetSequenceToken(); |
164 | 164 |
165 // Returns the sequence token associated with the given name. Calling this | 165 // Returns the sequence token associated with the given name. Calling this |
166 // function multiple times with the same string will always produce the | 166 // function multiple times with the same string will always produce the |
167 // same sequence token. If the name has not been used before, a new token | 167 // same sequence token. If the name has not been used before, a new token |
168 // will be created. | 168 // will be created. |
169 SequenceToken GetNamedSequenceToken(const std::string& name); | 169 SequenceToken GetNamedSequenceToken(const std::string& name); |
170 | 170 |
| 171 // Retrieves the sequence token associated with the current thread. |
| 172 // If current thread is not part in worker pool, this returns false and |
| 173 // |result_token| is unmodified. |result_token| may not be NULL. |
| 174 bool GetCurrentThreadSequenceToken(SequenceToken* result_token) const; |
| 175 |
171 // Returns a SequencedTaskRunner wrapper which posts to this | 176 // Returns a SequencedTaskRunner wrapper which posts to this |
172 // SequencedWorkerPool using the given sequence token. Tasks with nonzero | 177 // SequencedWorkerPool using the given sequence token. Tasks with nonzero |
173 // delay are posted with SKIP_ON_SHUTDOWN behavior and tasks with zero delay | 178 // delay are posted with SKIP_ON_SHUTDOWN behavior and tasks with zero delay |
174 // are posted with BLOCK_SHUTDOWN behavior. | 179 // are posted with BLOCK_SHUTDOWN behavior. |
175 scoped_refptr<SequencedTaskRunner> GetSequencedTaskRunner( | 180 scoped_refptr<SequencedTaskRunner> GetSequencedTaskRunner( |
176 SequenceToken token); | 181 SequenceToken token); |
177 | 182 |
178 // Returns a SequencedTaskRunner wrapper which posts to this | 183 // Returns a SequencedTaskRunner wrapper which posts to this |
179 // SequencedWorkerPool using the given sequence token. Tasks with nonzero | 184 // SequencedWorkerPool using the given sequence token. Tasks with nonzero |
180 // delay are posted with SKIP_ON_SHUTDOWN behavior and tasks with zero delay | 185 // delay are posted with SKIP_ON_SHUTDOWN behavior and tasks with zero delay |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 // | 320 // |
316 // Must be called from the same thread this object was constructed on. | 321 // Must be called from the same thread this object was constructed on. |
317 void Shutdown(int max_new_blocking_tasks_after_shutdown); | 322 void Shutdown(int max_new_blocking_tasks_after_shutdown); |
318 | 323 |
319 protected: | 324 protected: |
320 virtual ~SequencedWorkerPool(); | 325 virtual ~SequencedWorkerPool(); |
321 | 326 |
322 virtual void OnDestruct() const OVERRIDE; | 327 virtual void OnDestruct() const OVERRIDE; |
323 | 328 |
324 private: | 329 private: |
| 330 friend class SequenceCheckerImpl; |
| 331 |
| 332 // Gets the SequencedWorkerPool that owns the current thread. May be NULL. |
| 333 static SequencedWorkerPool* Owner(); |
| 334 |
325 friend class RefCountedThreadSafe<SequencedWorkerPool>; | 335 friend class RefCountedThreadSafe<SequencedWorkerPool>; |
326 friend class DeleteHelper<SequencedWorkerPool>; | 336 friend class DeleteHelper<SequencedWorkerPool>; |
327 | 337 |
328 class Inner; | 338 class Inner; |
329 class Worker; | 339 class Worker; |
330 | 340 |
331 const scoped_refptr<MessageLoopProxy> constructor_message_loop_; | 341 const scoped_refptr<MessageLoopProxy> constructor_message_loop_; |
332 | 342 |
333 // Avoid pulling in too many headers by putting (almost) everything | 343 // Avoid pulling in too many headers by putting (almost) everything |
334 // into |inner_|. | 344 // into |inner_|. |
335 const scoped_ptr<Inner> inner_; | 345 const scoped_ptr<Inner> inner_; |
336 | 346 |
337 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); | 347 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); |
338 }; | 348 }; |
339 | 349 |
340 } // namespace base | 350 } // namespace base |
341 | 351 |
342 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ | 352 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ |
OLD | NEW |