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 #include "base/task_scheduler/task_tracker.h" | 5 #include "base/task_scheduler/task_tracker.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/debug/task_annotator.h" | 8 #include "base/debug/task_annotator.h" |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/threading/sequenced_task_runner_handle.h" | 10 #include "base/threading/sequenced_task_runner_handle.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 164 |
165 bool TaskTracker::BeforeRunTask(TaskShutdownBehavior shutdown_behavior) { | 165 bool TaskTracker::BeforeRunTask(TaskShutdownBehavior shutdown_behavior) { |
166 AutoSchedulerLock auto_lock(lock_); | 166 AutoSchedulerLock auto_lock(lock_); |
167 | 167 |
168 if (shutdown_completed_) { | 168 if (shutdown_completed_) { |
169 // Trying to run a BLOCK_SHUTDOWN task after shutdown has completed is | 169 // Trying to run a BLOCK_SHUTDOWN task after shutdown has completed is |
170 // unexpected as it either shouldn't have been posted if shutdown completed | 170 // unexpected as it either shouldn't have been posted if shutdown completed |
171 // or should be blocking shutdown if it was posted before it did. | 171 // or should be blocking shutdown if it was posted before it did. |
172 DCHECK_NE(shutdown_behavior, TaskShutdownBehavior::BLOCK_SHUTDOWN); | 172 DCHECK_NE(shutdown_behavior, TaskShutdownBehavior::BLOCK_SHUTDOWN); |
173 | 173 |
174 // A WorkerThread might extract a non BLOCK_SHUTDOWN task from a | 174 // A worker might extract a non BLOCK_SHUTDOWN task from a PriorityQueue |
175 // PriorityQueue after shutdown. It shouldn't be allowed to run it. | 175 // after shutdown. It shouldn't be allowed to run it. |
176 return false; | 176 return false; |
177 } | 177 } |
178 | 178 |
179 switch (shutdown_behavior) { | 179 switch (shutdown_behavior) { |
180 case TaskShutdownBehavior::BLOCK_SHUTDOWN: | 180 case TaskShutdownBehavior::BLOCK_SHUTDOWN: |
181 DCHECK_GT(num_tasks_blocking_shutdown_, 0U); | 181 DCHECK_GT(num_tasks_blocking_shutdown_, 0U); |
182 return true; | 182 return true; |
183 | 183 |
184 case TaskShutdownBehavior::SKIP_ON_SHUTDOWN: | 184 case TaskShutdownBehavior::SKIP_ON_SHUTDOWN: |
185 if (shutdown_cv_) | 185 if (shutdown_cv_) |
(...skipping 17 matching lines...) Expand all Loading... |
203 AutoSchedulerLock auto_lock(lock_); | 203 AutoSchedulerLock auto_lock(lock_); |
204 DCHECK_GT(num_tasks_blocking_shutdown_, 0U); | 204 DCHECK_GT(num_tasks_blocking_shutdown_, 0U); |
205 --num_tasks_blocking_shutdown_; | 205 --num_tasks_blocking_shutdown_; |
206 if (num_tasks_blocking_shutdown_ == 0 && shutdown_cv_) | 206 if (num_tasks_blocking_shutdown_ == 0 && shutdown_cv_) |
207 shutdown_cv_->Signal(); | 207 shutdown_cv_->Signal(); |
208 } | 208 } |
209 } | 209 } |
210 | 210 |
211 } // namespace internal | 211 } // namespace internal |
212 } // namespace base | 212 } // namespace base |
OLD | NEW |