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 SequencedToken of the current thread. | |
147 // If current thread is not a SequencedWorkerPool worker thread, this returns | |
148 // false and |result_token| is unmodified. |result_token| may not be NULL. | |
149 static bool CurrentThreadSequenceToken(SequenceToken* result_token); | |
akalin
2013/07/03 20:41:14
valid sequence tokens are non-zero. can you have t
tommycli
2013/07/03 21:04:02
This is kind of a messed-up point about SequencedW
akalin
2013/07/03 22:43:46
Hmm. Is there a need to distinguish the case where
tommycli
2013/07/03 23:23:12
Either way seems fine since they both require look
| |
150 | |
146 // When constructing a SequencedWorkerPool, there must be a | 151 // When constructing a SequencedWorkerPool, there must be a |
147 // MessageLoop on the current thread unless you plan to deliberately | 152 // MessageLoop on the current thread unless you plan to deliberately |
148 // leak it. | 153 // leak it. |
149 | 154 |
150 // Pass the maximum number of threads (they will be lazily created as needed) | 155 // 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. | 156 // and a prefix for the thread name to aid in debugging. |
152 SequencedWorkerPool(size_t max_threads, | 157 SequencedWorkerPool(size_t max_threads, |
153 const std::string& thread_name_prefix); | 158 const std::string& thread_name_prefix); |
154 | 159 |
155 // Like above, but with |observer| for testing. Does not take | 160 // Like above, but with |observer| for testing. Does not take |
156 // ownership of |observer|. | 161 // ownership of |observer|. |
157 SequencedWorkerPool(size_t max_threads, | 162 SequencedWorkerPool(size_t max_threads, |
158 const std::string& thread_name_prefix, | 163 const std::string& thread_name_prefix, |
159 TestingObserver* observer); | 164 TestingObserver* observer); |
160 | 165 |
161 // Returns a unique token that can be used to sequence tasks posted to | 166 // Returns a unique token that can be used to sequence tasks posted to |
162 // PostSequencedWorkerTask(). Valid tokens are alwys nonzero. | 167 // PostSequencedWorkerTask(). Valid tokens are always nonzero. |
163 SequenceToken GetSequenceToken(); | 168 SequenceToken GetSequenceToken(); |
164 | 169 |
165 // Returns the sequence token associated with the given name. Calling this | 170 // Returns the sequence token associated with the given name. Calling this |
166 // function multiple times with the same string will always produce the | 171 // 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 | 172 // same sequence token. If the name has not been used before, a new token |
168 // will be created. | 173 // will be created. |
169 SequenceToken GetNamedSequenceToken(const std::string& name); | 174 SequenceToken GetNamedSequenceToken(const std::string& name); |
170 | 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 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 // Avoid pulling in too many headers by putting (almost) everything | 338 // Avoid pulling in too many headers by putting (almost) everything |
334 // into |inner_|. | 339 // into |inner_|. |
335 const scoped_ptr<Inner> inner_; | 340 const scoped_ptr<Inner> inner_; |
336 | 341 |
337 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); | 342 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); |
338 }; | 343 }; |
339 | 344 |
340 } // namespace base | 345 } // namespace base |
341 | 346 |
342 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ | 347 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ |
OLD | NEW |