OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_IMPL_H_ | 5 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_IMPL_H_ |
6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_IMPL_H_ | 6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_IMPL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 140 |
141 const std::string name_; | 141 const std::string name_; |
142 const ThreadPriority priority_hint_; | 142 const ThreadPriority priority_hint_; |
143 const ReEnqueueSequenceCallback re_enqueue_sequence_callback_; | 143 const ReEnqueueSequenceCallback re_enqueue_sequence_callback_; |
144 | 144 |
145 // PriorityQueue from which all threads of this worker pool get work. | 145 // PriorityQueue from which all threads of this worker pool get work. |
146 PriorityQueue shared_priority_queue_; | 146 PriorityQueue shared_priority_queue_; |
147 | 147 |
148 // All workers owned by this worker pool. Initialized by Start() within the | 148 // All workers owned by this worker pool. Initialized by Start() within the |
149 // scope of |idle_workers_stack_lock_|. Never modified afterwards (i.e. can be | 149 // scope of |idle_workers_stack_lock_|. Never modified afterwards (i.e. can be |
150 // read without synchronization once |workers_created_.IsSignaled()|). | 150 // read without synchronization once |workers_created_.IsSet()|). |
151 std::vector<scoped_refptr<SchedulerWorker>> workers_; | 151 std::vector<scoped_refptr<SchedulerWorker>> workers_; |
152 | 152 |
153 // Suggested reclaim time for workers. Initialized by Start(). Never modified | 153 // Suggested reclaim time for workers. Initialized by Start(). Never modified |
154 // afterwards (i.e. can be read without synchronization once | 154 // afterwards (i.e. can be read without synchronization once |
155 // |workers_created_.IsSignaled()|). | 155 // |workers_created_.IsSet()|). |
156 TimeDelta suggested_reclaim_time_; | 156 TimeDelta suggested_reclaim_time_; |
157 | 157 |
158 // Synchronizes access to |idle_workers_stack_|, | 158 // Synchronizes access to |idle_workers_stack_|, |
159 // |idle_workers_stack_cv_for_testing_| and |num_wake_ups_before_start_|. Has | 159 // |idle_workers_stack_cv_for_testing_| and |num_wake_ups_before_start_|. Has |
160 // |shared_priority_queue_|'s lock as its predecessor so that a worker can be | 160 // |shared_priority_queue_|'s lock as its predecessor so that a worker can be |
161 // pushed to |idle_workers_stack_| within the scope of a Transaction (more | 161 // pushed to |idle_workers_stack_| within the scope of a Transaction (more |
162 // details in GetWork()). | 162 // details in GetWork()). |
163 mutable SchedulerLock idle_workers_stack_lock_; | 163 mutable SchedulerLock idle_workers_stack_lock_; |
164 | 164 |
165 // Stack of idle workers. Initially, all workers are on this stack. A worker | 165 // Stack of idle workers. Initially, all workers are on this stack. A worker |
166 // is removed from the stack before its WakeUp() function is called and when | 166 // is removed from the stack before its WakeUp() function is called and when |
167 // it receives work from GetWork() (a worker calls GetWork() when its sleep | 167 // it receives work from GetWork() (a worker calls GetWork() when its sleep |
168 // timeout expires, even if its WakeUp() method hasn't been called). A worker | 168 // timeout expires, even if its WakeUp() method hasn't been called). A worker |
169 // is pushed on this stack when it receives nullptr from GetWork(). | 169 // is pushed on this stack when it receives nullptr from GetWork(). |
170 SchedulerWorkerStack idle_workers_stack_; | 170 SchedulerWorkerStack idle_workers_stack_; |
171 | 171 |
172 // Signaled when all workers become idle. | 172 // Signaled when all workers become idle. |
173 std::unique_ptr<ConditionVariable> idle_workers_stack_cv_for_testing_; | 173 std::unique_ptr<ConditionVariable> idle_workers_stack_cv_for_testing_; |
174 | 174 |
175 // Number of wake ups that occurred before Start(). | 175 // Number of wake ups that occurred before Start(). Never modified after |
| 176 // Start() (i.e. can be read without synchronization once |
| 177 // |workers_created_.IsSet()|). |
176 int num_wake_ups_before_start_ = 0; | 178 int num_wake_ups_before_start_ = 0; |
177 | 179 |
178 // Signaled once JoinForTesting() has returned. | 180 // Signaled once JoinForTesting() has returned. |
179 WaitableEvent join_for_testing_returned_; | 181 WaitableEvent join_for_testing_returned_; |
180 | 182 |
181 // Indicates to the delegates that workers are not permitted to detach their | 183 // Indicates to the delegates that workers are not permitted to detach their |
182 // threads. | 184 // threads. |
183 AtomicFlag worker_detachment_disallowed_; | 185 AtomicFlag worker_detachment_disallowed_; |
184 | 186 |
185 #if DCHECK_IS_ON() | 187 #if DCHECK_IS_ON() |
186 // Signaled when all workers have been created. | 188 // Set when all workers have been created. |
187 mutable WaitableEvent workers_created_; | 189 AtomicFlag workers_created_; |
188 #endif | 190 #endif |
189 | 191 |
190 // TaskScheduler.DetachDuration.[worker pool name] histogram. Intentionally | 192 // TaskScheduler.DetachDuration.[worker pool name] histogram. Intentionally |
191 // leaked. | 193 // leaked. |
192 HistogramBase* const detach_duration_histogram_; | 194 HistogramBase* const detach_duration_histogram_; |
193 | 195 |
194 // TaskScheduler.NumTasksBeforeDetach.[worker pool name] histogram. | 196 // TaskScheduler.NumTasksBeforeDetach.[worker pool name] histogram. |
195 // Intentionally leaked. | 197 // Intentionally leaked. |
196 HistogramBase* const num_tasks_before_detach_histogram_; | 198 HistogramBase* const num_tasks_before_detach_histogram_; |
197 | 199 |
198 // TaskScheduler.NumTasksBetweenWaits.[worker pool name] histogram. | 200 // TaskScheduler.NumTasksBetweenWaits.[worker pool name] histogram. |
199 // Intentionally leaked. | 201 // Intentionally leaked. |
200 HistogramBase* const num_tasks_between_waits_histogram_; | 202 HistogramBase* const num_tasks_between_waits_histogram_; |
201 | 203 |
202 TaskTracker* const task_tracker_; | 204 TaskTracker* const task_tracker_; |
203 DelayedTaskManager* const delayed_task_manager_; | 205 DelayedTaskManager* const delayed_task_manager_; |
204 | 206 |
205 DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerPoolImpl); | 207 DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerPoolImpl); |
206 }; | 208 }; |
207 | 209 |
208 } // namespace internal | 210 } // namespace internal |
209 } // namespace base | 211 } // namespace base |
210 | 212 |
211 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_IMPL_H_ | 213 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_IMPL_H_ |
OLD | NEW |