Index: base/task_scheduler/task_tracker.h |
diff --git a/base/task_scheduler/task_tracker.h b/base/task_scheduler/task_tracker.h |
index 795ae4937058d0a8f24719b9ae0edfa3641e0b5f..fc0901f7c139ade379e6e334a3aa7603efec7b49 100644 |
--- a/base/task_scheduler/task_tracker.h |
+++ b/base/task_scheduler/task_tracker.h |
@@ -11,7 +11,7 @@ |
#include "base/callback_forward.h" |
#include "base/macros.h" |
#include "base/metrics/histogram_base.h" |
-#include "base/synchronization/condition_variable.h" |
+#include "base/synchronization/waitable_event.h" |
#include "base/task_scheduler/scheduler_lock.h" |
#include "base/task_scheduler/task.h" |
#include "base/task_scheduler/task_traits.h" |
@@ -44,16 +44,16 @@ class BASE_EXPORT TaskTracker { |
// must have allowed |task| to be posted. |
void RunTask(const Task* task); |
+ // Returns true if shutdown has completed. |
+ bool IsShutdownComplete() const; |
+ |
// Returns true while shutdown is in progress (i.e. Shutdown() has been called |
// but hasn't returned). |
bool IsShuttingDownForTesting() const; |
- bool shutdown_completed() const { |
- AutoSchedulerLock auto_lock(lock_); |
- return shutdown_completed_; |
- } |
- |
private: |
+ class State; |
+ |
// Called before WillPostTask() informs the tracing system that a task has |
// been posted. Updates |num_tasks_blocking_shutdown_| if necessary and |
// returns true if the current shutdown state allows the task to be posted. |
@@ -69,22 +69,24 @@ class BASE_EXPORT TaskTracker { |
// necessary. |
void AfterRunTask(TaskShutdownBehavior shutdown_behavior); |
- // Synchronizes access to all members. |
- mutable SchedulerLock lock_; |
+ // Called when the number of tasks blocking shutdown becomes zero after |
+ // shutdown has started. |
+ void OnBlockingShutdownTasksComplete(); |
- // Condition variable signaled when |num_tasks_blocking_shutdown_| reaches |
- // zero while shutdown is in progress. Null if shutdown isn't in progress. |
- std::unique_ptr<ConditionVariable> shutdown_cv_; |
+ // Number of tasks blocking shutdown and boolean indicating whether shutdown |
+ // has started. |
+ const std::unique_ptr<State> state_; |
- // Number of tasks blocking shutdown. |
- size_t num_tasks_blocking_shutdown_ = 0; |
+ // Synchronizes access to shutdown related members below. |
+ mutable SchedulerLock shutdown_lock_; |
+ |
+ // Event instantiated when shutdown starts and signaled when shutdown |
+ // completes. |
+ std::unique_ptr<WaitableEvent> shutdown_event_; |
// Number of BLOCK_SHUTDOWN tasks posted during shutdown. |
HistogramBase::Sample num_block_shutdown_tasks_posted_during_shutdown_ = 0; |
- // True once Shutdown() has returned. No new task can be scheduled after this. |
- bool shutdown_completed_ = false; |
- |
DISALLOW_COPY_AND_ASSIGN(TaskTracker); |
}; |