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

Unified Diff: base/task_scheduler/task_tracker.h

Issue 2019763002: TaskScheduler: Atomic operations in TaskTracker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR gab/robliao #30-31 Created 4 years, 6 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 795ae4937058d0a8f24719b9ae0edfa3641e0b5f..00e11e083a5acd66ec10c00146d05c6018f8decb 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 ShutdownCompleted() 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);
};

Powered by Google App Engine
This is Rietveld 408576698