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

Unified Diff: base/task_scheduler/shutdown_manager.h

Issue 1698183005: Reference CL for the new task scheduler. (Closed) Base URL: https://luckyluke-private.googlesource.com/src@bigmaster2
Patch Set: Created 4 years, 10 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/sequence_unittest.cc ('k') | base/task_scheduler/shutdown_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/task_scheduler/shutdown_manager.h
diff --git a/base/task_scheduler/shutdown_manager.h b/base/task_scheduler/shutdown_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..9ca42c339f2ee51a7929693e0dd2122e45ef9ee7
--- /dev/null
+++ b/base/task_scheduler/shutdown_manager.h
@@ -0,0 +1,71 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_TASK_SCHEDULER_SHUTDOWN_MANAGER_H_
+#define BASE_TASK_SCHEDULER_SHUTDOWN_MANAGER_H_
+
+#include "base/base_export.h"
+#include "base/macros.h"
+#include "base/synchronization/condition_variable.h"
+#include "base/task_scheduler/scheduler_lock.h"
+#include "base/task_scheduler/task_traits.h"
+
+namespace base {
+namespace internal {
+
+// Ensures proper shutdown behavior of the task scheduler. Unless otherwise
+// noted, the methods of this class are thread-safe.
+class BASE_EXPORT ShutdownManager {
+ public:
+ ShutdownManager();
+
+ // Shuts down the task scheduler. After this is called, only tasks posted with
+ // the BLOCK_SHUTDOWN behavior are scheduled. Returns when:
+ // - All SKIP_ON_SHUTDOWN tasks that were already running have completed their
+ // execution.
+ // - There is no pending BLOCK_SHUTDOWN tasks.
+ // This cannot be called simultaneously on multiple threads.
+ void Shutdown();
+
+ // Indicates whether a task with this |shutdown_behavior| should be posted.
+ bool ShouldPostTask(TaskShutdownBehavior shutdown_behavior);
+
+ // Indicates whether a task with this |shutdown_behavior| should be scheduled.
+ bool ShouldScheduleTask(TaskShutdownBehavior shutdown_behavior);
+
+ // Notifies the shutdown manager that a task with this |shutdown_behavior|
+ // completed its execution.
+ void DidExecuteTask(TaskShutdownBehavior shutdown_behavior);
+
+ void set_is_shutting_down_for_testing(bool is_shutting_down_for_testing);
+ bool is_shutting_down_for_testing() const;
+
+ bool shutdown_completed() const;
+
+ private:
+ // Lock protecting all members.
+ SchedulerLock lock_;
+
+ // Condition variable signaled when |num_tasks_blocking_shutdown_| reaches
+ // zero.
+ ConditionVariable cv_;
+
+ // Number of tasks blocking shutdown.
+ size_t num_tasks_blocking_shutdown_;
+
+ // True when Shutdown() is waiting for tasks blocking shutdown to complete
+ // their execution.
+ bool is_shutting_down_;
+
+ // Returns true once Shutdown() has returned. No new task can be scheduled
+ // after this point.
+ bool shutdown_completed_;
+
+ DISALLOW_COPY_AND_ASSIGN(ShutdownManager);
+};
+
+} // namespace internal
+} // namespace base
+
+#endif // BASE_TASK_SCHEDULER_SHUTDOWN_MANAGER_H_
« no previous file with comments | « base/task_scheduler/sequence_unittest.cc ('k') | base/task_scheduler/shutdown_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698