Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Unified Diff: base/task_scheduler/task_tracker.h

Issue 2362253002: TaskScheduler: Add FlushForTesting(). (Closed)
Patch Set: self-review Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..97d76159af4337ba1fdaa5d638d148e9b1051727 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 PerformShutdown();
+
// 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;
danakj 2016/09/23 20:51:41 I think it'd be nice to document that you intend t
fdoray 2016/09/23 21:09:46 Done.
+
+ // 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_;

Powered by Google App Engine
This is Rietveld 408576698