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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <cstddef> | 9 #include <cstddef> |
10 #include <string> | 10 #include <string> |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 const Closure& task, | 207 const Closure& task, |
208 TimeDelta delay) OVERRIDE; | 208 TimeDelta delay) OVERRIDE; |
209 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; | 209 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; |
210 | 210 |
211 // Blocks until all pending tasks are complete. This should only be called in | 211 // Blocks until all pending tasks are complete. This should only be called in |
212 // unit tests when you want to validate something that should have happened. | 212 // unit tests when you want to validate something that should have happened. |
213 // | 213 // |
214 // Note that calling this will not prevent other threads from posting work to | 214 // Note that calling this will not prevent other threads from posting work to |
215 // the queue while the calling thread is waiting on Flush(). In this case, | 215 // the queue while the calling thread is waiting on Flush(). In this case, |
216 // Flush will return only when there's no more work in the queue. Normally, | 216 // Flush will return only when there's no more work in the queue. Normally, |
217 // this doesn't come up sine in a test, all the work is being posted from | 217 // this doesn't come up since in a test, all the work is being posted from |
218 // the main thread. | 218 // the main thread. |
219 void FlushForTesting(); | 219 void FlushForTesting(); |
220 | 220 |
| 221 // Spuriously signal that there is work to be done. |
| 222 void TriggerSpuriousWorkSignalForTesting(); |
| 223 |
| 224 // Get the number of times the work signal has been triggered. |
| 225 int GetWorkSignalCountForTesting() const; |
| 226 |
221 // Implements the worker pool shutdown. This should be called during app | 227 // Implements the worker pool shutdown. This should be called during app |
222 // shutdown, and will discard/join with appropriate tasks before returning. | 228 // shutdown, and will discard/join with appropriate tasks before returning. |
223 // After this call, subsequent calls to post tasks will fail. | 229 // After this call, subsequent calls to post tasks will fail. |
| 230 // |
| 231 // Must be called from the same thread this object was constructed on. |
224 void Shutdown(); | 232 void Shutdown(); |
225 | 233 |
226 // Called by tests to set the testing observer. This is NULL by default | 234 // Called by tests to set the testing observer. This is NULL by default |
227 // and ownership of the pointer is kept with the caller. | 235 // and ownership of the pointer is kept with the caller. |
228 void SetTestingObserver(TestingObserver* observer); | 236 void SetTestingObserver(TestingObserver* observer); |
229 | 237 |
230 protected: | 238 protected: |
231 virtual ~SequencedWorkerPool(); | 239 virtual ~SequencedWorkerPool(); |
232 | 240 |
233 virtual void OnDestruct() const OVERRIDE; | 241 virtual void OnDestruct() const OVERRIDE; |
(...skipping 10 matching lines...) Expand all Loading... |
244 // Avoid pulling in too many headers by putting (almost) everything | 252 // Avoid pulling in too many headers by putting (almost) everything |
245 // into |inner_|. | 253 // into |inner_|. |
246 const scoped_ptr<Inner> inner_; | 254 const scoped_ptr<Inner> inner_; |
247 | 255 |
248 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); | 256 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); |
249 }; | 257 }; |
250 | 258 |
251 } // namespace base | 259 } // namespace base |
252 | 260 |
253 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ | 261 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ |
OLD | NEW |