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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BASE_TASK_SCHEDULER_SHUTDOWN_MANAGER_H_
6 #define BASE_TASK_SCHEDULER_SHUTDOWN_MANAGER_H_
7
8 #include "base/base_export.h"
9 #include "base/macros.h"
10 #include "base/synchronization/condition_variable.h"
11 #include "base/task_scheduler/scheduler_lock.h"
12 #include "base/task_scheduler/task_traits.h"
13
14 namespace base {
15 namespace internal {
16
17 // Ensures proper shutdown behavior of the task scheduler. Unless otherwise
18 // noted, the methods of this class are thread-safe.
19 class BASE_EXPORT ShutdownManager {
20 public:
21 ShutdownManager();
22
23 // Shuts down the task scheduler. After this is called, only tasks posted with
24 // the BLOCK_SHUTDOWN behavior are scheduled. Returns when:
25 // - All SKIP_ON_SHUTDOWN tasks that were already running have completed their
26 // execution.
27 // - There is no pending BLOCK_SHUTDOWN tasks.
28 // This cannot be called simultaneously on multiple threads.
29 void Shutdown();
30
31 // Indicates whether a task with this |shutdown_behavior| should be posted.
32 bool ShouldPostTask(TaskShutdownBehavior shutdown_behavior);
33
34 // Indicates whether a task with this |shutdown_behavior| should be scheduled.
35 bool ShouldScheduleTask(TaskShutdownBehavior shutdown_behavior);
36
37 // Notifies the shutdown manager that a task with this |shutdown_behavior|
38 // completed its execution.
39 void DidExecuteTask(TaskShutdownBehavior shutdown_behavior);
40
41 void set_is_shutting_down_for_testing(bool is_shutting_down_for_testing);
42 bool is_shutting_down_for_testing() const;
43
44 bool shutdown_completed() const;
45
46 private:
47 // Lock protecting all members.
48 SchedulerLock lock_;
49
50 // Condition variable signaled when |num_tasks_blocking_shutdown_| reaches
51 // zero.
52 ConditionVariable cv_;
53
54 // Number of tasks blocking shutdown.
55 size_t num_tasks_blocking_shutdown_;
56
57 // True when Shutdown() is waiting for tasks blocking shutdown to complete
58 // their execution.
59 bool is_shutting_down_;
60
61 // Returns true once Shutdown() has returned. No new task can be scheduled
62 // after this point.
63 bool shutdown_completed_;
64
65 DISALLOW_COPY_AND_ASSIGN(ShutdownManager);
66 };
67
68 } // namespace internal
69 } // namespace base
70
71 #endif // BASE_TASK_SCHEDULER_SHUTDOWN_MANAGER_H_
OLDNEW
« 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