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

Unified Diff: base/task_scheduler/task_tracker.h

Issue 2362253002: TaskScheduler: Add FlushForTesting(). (Closed)
Patch Set: fix build error 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
« no previous file with comments | « base/task_scheduler/task_scheduler_impl.cc ('k') | base/task_scheduler/task_tracker.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..93769f1751bc1525c8c1cf13cf19b271ea6b1567 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 Flush();
+
// 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,30 @@ class BASE_EXPORT TaskTracker {
// shutdown has started.
void OnBlockingShutdownTasksComplete();
+ // Decrements the number of pending undelayed tasks and signals |flush_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. Is
+ // incremented and decremented without a barrier. When it reaches zero,
+ // |flush_lock_| is acquired (forcing memory synchronization) and |flush_cv_|
+ // is signaled.
+ subtle::Atomic32 num_pending_undelayed_tasks_ = 0;
+
+ // Lock associated with |flush_cv_|. Partially synchronizes access to
+ // |num_pending_undelayed_tasks_|. Full synchronization isn't needed because
+ // it's atomic, but synchronization is needed to coordinate waking and
+ // sleeping at the right time.
+ mutable SchedulerLock flush_lock_;
+
+ // Signaled when |num_pending_undelayed_tasks_| is zero or when shutdown
+ // completes.
+ const std::unique_ptr<ConditionVariable> flush_cv_;
+
// Synchronizes access to shutdown related members below.
mutable SchedulerLock shutdown_lock_;
« no previous file with comments | « base/task_scheduler/task_scheduler_impl.cc ('k') | base/task_scheduler/task_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698