Chromium Code Reviews| 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 <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/atomicops.h" | 9 #include "base/atomicops.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 } | 212 } |
| 213 | 213 |
| 214 AfterRunTask(shutdown_behavior); | 214 AfterRunTask(shutdown_behavior); |
| 215 } | 215 } |
| 216 | 216 |
| 217 bool TaskTracker::IsShutdownComplete() const { | 217 bool TaskTracker::IsShutdownComplete() const { |
| 218 AutoSchedulerLock auto_lock(shutdown_lock_); | 218 AutoSchedulerLock auto_lock(shutdown_lock_); |
| 219 return shutdown_event_ && shutdown_event_->IsSignaled(); | 219 return shutdown_event_ && shutdown_event_->IsSignaled(); |
| 220 } | 220 } |
| 221 | 221 |
| 222 bool TaskTracker::IsShuttingDownForTesting() const { | 222 bool TaskTracker::IsShutdownInProgress() const { |
| 223 AutoSchedulerLock auto_lock(shutdown_lock_); | 223 AutoSchedulerLock auto_lock(shutdown_lock_); |
| 224 return shutdown_event_ && !shutdown_event_->IsSignaled(); | 224 return shutdown_event_ && !shutdown_event_->IsSignaled(); |
| 225 } | 225 } |
| 226 | 226 |
| 227 void TaskTracker::SetIsShutdownInProgressForTesting() { | |
| 228 AutoSchedulerLock auto_lock(shutdown_lock_); | |
| 229 DCHECK(!shutdown_event_); | |
| 230 shutdown_event_.reset( | |
| 231 new WaitableEvent(WaitableEvent::ResetPolicy::MANUAL, | |
|
robliao
2016/07/19 22:41:28
Unify this event creation with the one in Shutdown
fdoray
2016/07/20 18:22:21
n/a
| |
| 232 WaitableEvent::InitialState::NOT_SIGNALED)); | |
| 233 } | |
| 234 | |
| 227 bool TaskTracker::BeforePostTask(TaskShutdownBehavior shutdown_behavior) { | 235 bool TaskTracker::BeforePostTask(TaskShutdownBehavior shutdown_behavior) { |
| 228 if (shutdown_behavior == TaskShutdownBehavior::BLOCK_SHUTDOWN) { | 236 if (shutdown_behavior == TaskShutdownBehavior::BLOCK_SHUTDOWN) { |
| 229 // BLOCK_SHUTDOWN tasks block shutdown between the moment they are posted | 237 // BLOCK_SHUTDOWN tasks block shutdown between the moment they are posted |
| 230 // and the moment they complete their execution. | 238 // and the moment they complete their execution. |
| 231 const bool shutdown_started = state_->IncrementNumTasksBlockingShutdown(); | 239 const bool shutdown_started = state_->IncrementNumTasksBlockingShutdown(); |
| 232 | 240 |
| 233 if (shutdown_started) { | 241 if (shutdown_started) { |
| 234 AutoSchedulerLock auto_lock(shutdown_lock_); | 242 AutoSchedulerLock auto_lock(shutdown_lock_); |
| 235 | 243 |
| 236 // A BLOCK_SHUTDOWN task posted after shutdown has completed is an | 244 // A BLOCK_SHUTDOWN task posted after shutdown has completed is an |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 | 326 |
| 319 // This method can only be called after shutdown has started. | 327 // This method can only be called after shutdown has started. |
| 320 DCHECK(state_->HasShutdownStarted()); | 328 DCHECK(state_->HasShutdownStarted()); |
| 321 DCHECK(shutdown_event_); | 329 DCHECK(shutdown_event_); |
| 322 | 330 |
| 323 shutdown_event_->Signal(); | 331 shutdown_event_->Signal(); |
| 324 } | 332 } |
| 325 | 333 |
| 326 } // namespace internal | 334 } // namespace internal |
| 327 } // namespace base | 335 } // namespace base |
| OLD | NEW |