Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/memory/scoped_ptr.h" | |
| 11 #include "base/synchronization/condition_variable.h" | |
| 12 #include "base/task_scheduler/scheduler_lock.h" | |
| 13 #include "base/task_scheduler/task_traits.h" | |
| 14 | |
| 15 namespace base { | |
| 16 namespace internal { | |
| 17 | |
| 18 // Ensures proper shutdown behavior of the task scheduler. Unless otherwise | |
| 19 // noted, the methods of this class are thread-safe. | |
| 20 class BASE_EXPORT ShutdownManager { | |
| 21 public: | |
| 22 ShutdownManager(); | |
| 23 ~ShutdownManager(); | |
| 24 | |
| 25 // Shuts down the task scheduler. After this is called, only tasks posted with | |
| 26 // the BLOCK_SHUTDOWN behavior are scheduled. Returns when: | |
| 27 // - All SKIP_ON_SHUTDOWN tasks that were already running have completed their | |
| 28 // execution. | |
| 29 // - There is no pending BLOCK_SHUTDOWN tasks. | |
|
gab
2016/02/23 22:28:23
s/is/are/
fdoray
2016/02/26 15:53:28
Done.
| |
| 30 // This cannot be called simultaneously on multiple threads. | |
|
gab
2016/02/23 22:28:23
// This should only be called on shutdown from one
fdoray
2016/02/26 15:53:28
Done. "Must only be called once" implies "from one
| |
| 31 void Shutdown(); | |
| 32 | |
| 33 // Indicates whether a task with this |shutdown_behavior| should be posted. | |
| 34 bool ShouldPostTask(TaskShutdownBehavior shutdown_behavior); | |
|
gab
2016/02/23 22:28:23
This actually does more than return its opinion, i
robliao
2016/02/23 22:47:02
What I like about the ShutdownManager right now is
fdoray
2016/02/24 17:01:06
OPTION 1:
Pro: ShutdownManager doesn't have to kn
| |
| 35 | |
| 36 // Indicates whether a task with this |shutdown_behavior| should be scheduled. | |
| 37 bool ShouldScheduleTask(TaskShutdownBehavior shutdown_behavior); | |
| 38 | |
| 39 // Notifies the shutdown manager that a task with this |shutdown_behavior| | |
| 40 // completed its execution. | |
| 41 void DidExecuteTask(TaskShutdownBehavior shutdown_behavior); | |
| 42 | |
| 43 void set_is_shutting_down_for_testing(bool is_shutting_down_for_testing); | |
| 44 bool is_shutting_down_for_testing() const; | |
| 45 | |
| 46 bool shutdown_completed() const; | |
|
gab
2016/02/23 22:28:23
Inline impl of lower_case_getters_and_setters() ab
fdoray
2016/02/26 15:53:28
Done.
| |
| 47 | |
| 48 private: | |
| 49 // Lock protecting all members. | |
| 50 SchedulerLock lock_; | |
| 51 | |
| 52 // Condition variable signaled when |num_tasks_blocking_shutdown_| reaches | |
| 53 // zero. | |
|
gab
2016/02/23 22:28:23
[gab TODO]
Append "while |is_shutting_down_|"?
fdoray
2016/02/26 15:53:28
Done.
| |
| 54 scoped_ptr<ConditionVariable> cv_; | |
| 55 | |
| 56 // Number of tasks blocking shutdown. | |
| 57 size_t num_tasks_blocking_shutdown_; | |
| 58 | |
| 59 // True when Shutdown() is waiting for tasks blocking shutdown to complete | |
| 60 // their execution. | |
| 61 bool is_shutting_down_; | |
| 62 | |
| 63 // True once Shutdown() has returned. No new task can be scheduled after this. | |
| 64 bool shutdown_completed_; | |
| 65 | |
| 66 DISALLOW_COPY_AND_ASSIGN(ShutdownManager); | |
| 67 }; | |
| 68 | |
| 69 } // namespace internal | |
| 70 } // namespace base | |
| 71 | |
| 72 #endif // BASE_TASK_SCHEDULER_SHUTDOWN_MANAGER_H_ | |
| OLD | NEW |