| Index: base/task_scheduler/task_tracker.h
|
| diff --git a/base/task_scheduler/task_tracker.h b/base/task_scheduler/task_tracker.h
|
| index 7a4338943341e25609987d8ec61b415514761e5c..7f5c5bb7092b128812b4c4b04975e3a0b9f4ad2e 100644
|
| --- a/base/task_scheduler/task_tracker.h
|
| +++ b/base/task_scheduler/task_tracker.h
|
| @@ -7,6 +7,7 @@
|
|
|
| #include <memory>
|
|
|
| +#include "base/atomicops.h"
|
| #include "base/base_export.h"
|
| #include "base/callback_forward.h"
|
| #include "base/macros.h"
|
| @@ -19,6 +20,7 @@
|
|
|
| namespace base {
|
|
|
| +class ConditionVariable;
|
| class SequenceToken;
|
|
|
| namespace internal {
|
| @@ -40,6 +42,13 @@ class BASE_EXPORT TaskTracker {
|
| // This can only be called once.
|
| void Shutdown();
|
|
|
| + // Waits until there are no pending undelayed tasks. May be called in tests
|
| + // to validate that a condition is met after all undelayed tasks have run.
|
| + //
|
| + // Does not wait for delayed tasks. Waits for undelayed tasks posted from
|
| + // other threads during the call. Returns immediately when shutdown completes.
|
| + void FlushForTesting();
|
| +
|
| // Informs this TaskTracker that |task| is about to be posted. Returns true if
|
| // this operation is allowed (|task| should be posted if-and-only-if it is).
|
| bool WillPostTask(const Task* task);
|
| @@ -67,6 +76,8 @@ class BASE_EXPORT TaskTracker {
|
| private:
|
| class State;
|
|
|
| + void ShutdownInternal();
|
| +
|
| // 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.
|
| @@ -86,10 +97,24 @@ class BASE_EXPORT TaskTracker {
|
| // shutdown has started.
|
| void OnBlockingShutdownTasksComplete();
|
|
|
| + // Decrements the number of pending undelayed tasks and signals
|
| + // |flush_for_testing_cv_| if it reaches zero.
|
| + void DecrementNumPendingUndelayedTasks();
|
| +
|
| // Number of tasks blocking shutdown and boolean indicating whether shutdown
|
| // has started.
|
| const std::unique_ptr<State> state_;
|
|
|
| + // Number of undelayed tasks that haven't completed their execution.
|
| + subtle::Atomic32 num_pending_undelayed_tasks_ = 0;
|
| +
|
| + // Synchronizes access to |flush_for_testing_cv_|.
|
| + mutable SchedulerLock flush_for_testing_lock_;
|
| +
|
| + // Signaled when |num_pending_undelayed_tasks_| is zero or when shutdown
|
| + // completes.
|
| + const std::unique_ptr<ConditionVariable> flush_for_testing_cv_;
|
| +
|
| // Synchronizes access to shutdown related members below.
|
| mutable SchedulerLock shutdown_lock_;
|
|
|
|
|