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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 | 120 |
121 // Allows tests to perform certain actions. | 121 // Allows tests to perform certain actions. |
122 class TestingObserver { | 122 class TestingObserver { |
123 public: | 123 public: |
124 virtual ~TestingObserver() {} | 124 virtual ~TestingObserver() {} |
125 virtual void OnHasWork() = 0; | 125 virtual void OnHasWork() = 0; |
126 virtual void WillWaitForShutdown() = 0; | 126 virtual void WillWaitForShutdown() = 0; |
127 virtual void OnDestruct() = 0; | 127 virtual void OnDestruct() = 0; |
128 }; | 128 }; |
129 | 129 |
130 // When constructing a SequencedWorkerPool, there must be a | |
131 // MessageLoop on the current thread unless you plan to deliberately | |
132 // leak it. | |
joth
2012/03/16 12:04:04
FWIW reading this another approach occurred to me:
| |
133 | |
130 // Pass the maximum number of threads (they will be lazily created as needed) | 134 // Pass the maximum number of threads (they will be lazily created as needed) |
131 // and a prefix for the thread name to ad in debugging. | 135 // and a prefix for the thread name to aid in debugging. |
132 SequencedWorkerPool(size_t max_threads, | 136 SequencedWorkerPool(size_t max_threads, |
133 const std::string& thread_name_prefix); | 137 const std::string& thread_name_prefix); |
134 | 138 |
135 // Like above, but with |observer| for testing. Does not take | 139 // Like above, but with |observer| for testing. Does not take |
136 // ownership of |observer|. | 140 // ownership of |observer|. |
137 SequencedWorkerPool(size_t max_threads, | 141 SequencedWorkerPool(size_t max_threads, |
138 const std::string& thread_name_prefix, | 142 const std::string& thread_name_prefix, |
139 TestingObserver* observer); | 143 TestingObserver* observer); |
140 | 144 |
141 // Returns a unique token that can be used to sequence tasks posted to | 145 // Returns a unique token that can be used to sequence tasks posted to |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 // Avoid pulling in too many headers by putting (almost) everything | 256 // Avoid pulling in too many headers by putting (almost) everything |
253 // into |inner_|. | 257 // into |inner_|. |
254 const scoped_ptr<Inner> inner_; | 258 const scoped_ptr<Inner> inner_; |
255 | 259 |
256 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); | 260 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); |
257 }; | 261 }; |
258 | 262 |
259 } // namespace base | 263 } // namespace base |
260 | 264 |
261 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ | 265 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ |
OLD | NEW |