Chromium Code Reviews| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 | 136 |
| 137 // Allows tests to perform certain actions. | 137 // Allows tests to perform certain actions. |
| 138 class TestingObserver { | 138 class TestingObserver { |
| 139 public: | 139 public: |
| 140 virtual ~TestingObserver() {} | 140 virtual ~TestingObserver() {} |
| 141 virtual void OnHasWork() = 0; | 141 virtual void OnHasWork() = 0; |
| 142 virtual void WillWaitForShutdown() = 0; | 142 virtual void WillWaitForShutdown() = 0; |
| 143 virtual void OnDestruct() = 0; | 143 virtual void OnDestruct() = 0; |
| 144 }; | 144 }; |
| 145 | 145 |
| 146 // Gets the SequencedWorkerPool for the current thread. Result may be NULL. | |
| 147 static SequencedWorkerPool* Get(); | |
|
vandebo (ex-Chrome)
2013/06/28 21:00:06
nit: Current() is a more traditional name for this
tommycli
2013/06/28 22:37:07
Done.
| |
| 148 | |
| 146 // When constructing a SequencedWorkerPool, there must be a | 149 // When constructing a SequencedWorkerPool, there must be a |
| 147 // MessageLoop on the current thread unless you plan to deliberately | 150 // MessageLoop on the current thread unless you plan to deliberately |
| 148 // leak it. | 151 // leak it. |
| 149 | 152 |
| 150 // Pass the maximum number of threads (they will be lazily created as needed) | 153 // Pass the maximum number of threads (they will be lazily created as needed) |
| 151 // and a prefix for the thread name to aid in debugging. | 154 // and a prefix for the thread name to aid in debugging. |
| 152 SequencedWorkerPool(size_t max_threads, | 155 SequencedWorkerPool(size_t max_threads, |
| 153 const std::string& thread_name_prefix); | 156 const std::string& thread_name_prefix); |
| 154 | 157 |
| 155 // Like above, but with |observer| for testing. Does not take | 158 // Like above, but with |observer| for testing. Does not take |
| 156 // ownership of |observer|. | 159 // ownership of |observer|. |
| 157 SequencedWorkerPool(size_t max_threads, | 160 SequencedWorkerPool(size_t max_threads, |
| 158 const std::string& thread_name_prefix, | 161 const std::string& thread_name_prefix, |
| 159 TestingObserver* observer); | 162 TestingObserver* observer); |
| 160 | 163 |
| 161 // Returns a unique token that can be used to sequence tasks posted to | 164 // Returns a unique token that can be used to sequence tasks posted to |
| 162 // PostSequencedWorkerTask(). Valid tokens are alwys nonzero. | 165 // PostSequencedWorkerTask(). Valid tokens are always nonzero. |
| 163 SequenceToken GetSequenceToken(); | 166 SequenceToken GetSequenceToken(); |
| 164 | 167 |
| 165 // Returns the sequence token associated with the given name. Calling this | 168 // Returns the sequence token associated with the given name. Calling this |
| 166 // function multiple times with the same string will always produce the | 169 // 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 | 170 // same sequence token. If the name has not been used before, a new token |
| 168 // will be created. | 171 // will be created. |
| 169 SequenceToken GetNamedSequenceToken(const std::string& name); | 172 SequenceToken GetNamedSequenceToken(const std::string& name); |
| 170 | 173 |
| 174 // Retrieves the sequence token associated with the current thread. | |
| 175 // If current thread is not part in worker pool, this returns false and | |
| 176 // |result_token| is unmodified. |result_token| may not be NULL. | |
| 177 bool GetCurrentThreadSequenceToken(SequenceToken* result_token) const; | |
| 178 | |
| 171 // Returns a SequencedTaskRunner wrapper which posts to this | 179 // Returns a SequencedTaskRunner wrapper which posts to this |
| 172 // SequencedWorkerPool using the given sequence token. Tasks with nonzero | 180 // SequencedWorkerPool using the given sequence token. Tasks with nonzero |
| 173 // delay are posted with SKIP_ON_SHUTDOWN behavior and tasks with zero delay | 181 // delay are posted with SKIP_ON_SHUTDOWN behavior and tasks with zero delay |
| 174 // are posted with BLOCK_SHUTDOWN behavior. | 182 // are posted with BLOCK_SHUTDOWN behavior. |
| 175 scoped_refptr<SequencedTaskRunner> GetSequencedTaskRunner( | 183 scoped_refptr<SequencedTaskRunner> GetSequencedTaskRunner( |
| 176 SequenceToken token); | 184 SequenceToken token); |
| 177 | 185 |
| 178 // Returns a SequencedTaskRunner wrapper which posts to this | 186 // Returns a SequencedTaskRunner wrapper which posts to this |
| 179 // SequencedWorkerPool using the given sequence token. Tasks with nonzero | 187 // SequencedWorkerPool using the given sequence token. Tasks with nonzero |
| 180 // delay are posted with SKIP_ON_SHUTDOWN behavior and tasks with zero delay | 188 // delay are posted with SKIP_ON_SHUTDOWN behavior and tasks with zero delay |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 // Avoid pulling in too many headers by putting (almost) everything | 341 // Avoid pulling in too many headers by putting (almost) everything |
| 334 // into |inner_|. | 342 // into |inner_|. |
| 335 const scoped_ptr<Inner> inner_; | 343 const scoped_ptr<Inner> inner_; |
| 336 | 344 |
| 337 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); | 345 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); |
| 338 }; | 346 }; |
| 339 | 347 |
| 340 } // namespace base | 348 } // namespace base |
| 341 | 349 |
| 342 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ | 350 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ |
| OLD | NEW |