OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_TASK_SCHEDULER_TASK_TRACKER_H_ | 5 #ifndef BASE_TASK_SCHEDULER_TASK_TRACKER_H_ |
6 #define BASE_TASK_SCHEDULER_TASK_TRACKER_H_ | 6 #define BASE_TASK_SCHEDULER_TASK_TRACKER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 ~TaskTracker(); | 28 ~TaskTracker(); |
29 | 29 |
30 // Synchronously shuts down the scheduler. Once this is called, only tasks | 30 // Synchronously shuts down the scheduler. Once this is called, only tasks |
31 // posted with the BLOCK_SHUTDOWN behavior will be run. Returns when: | 31 // posted with the BLOCK_SHUTDOWN behavior will be run. Returns when: |
32 // - All SKIP_ON_SHUTDOWN tasks that were already running have completed their | 32 // - All SKIP_ON_SHUTDOWN tasks that were already running have completed their |
33 // execution. | 33 // execution. |
34 // - All posted BLOCK_SHUTDOWN tasks have completed their execution. | 34 // - All posted BLOCK_SHUTDOWN tasks have completed their execution. |
35 // This must only be called once. | 35 // This must only be called once. |
36 void Shutdown(); | 36 void Shutdown(); |
37 | 37 |
38 // Posts |task| by calling |post_task_callback| unless the current shutdown | 38 // Informs this TaskTracker that |task| is about to be posted. Returns true if |
39 // state prevents that. A task forwarded to |post_task_callback| must be | 39 // this operation is allowed (|task| should be posted if-and-only-if it is). |
40 // handed back to this instance's RunTask() when it is to be executed. | 40 bool WillPostTask(const Task* task); |
41 void PostTask(const Callback<void(std::unique_ptr<Task>)>& post_task_callback, | |
42 std::unique_ptr<Task> task); | |
43 | 41 |
44 // Runs |task| unless the current shutdown state prevents that. |task| must | 42 // Runs |task| unless the current shutdown state prevents that. WillPostTask() |
45 // have been successfully posted via PostTask() first. | 43 // must have allowed |task| to be posted. |
46 void RunTask(const Task* task); | 44 void RunTask(const Task* task); |
47 | 45 |
48 // Returns true while shutdown is in progress (i.e. Shutdown() has been called | 46 // Returns true while shutdown is in progress (i.e. Shutdown() has been called |
49 // but hasn't returned). | 47 // but hasn't returned). |
50 bool IsShuttingDownForTesting() const; | 48 bool IsShuttingDownForTesting() const; |
51 | 49 |
52 bool shutdown_completed() const { | 50 bool shutdown_completed() const { |
53 AutoSchedulerLock auto_lock(lock_); | 51 AutoSchedulerLock auto_lock(lock_); |
54 return shutdown_completed_; | 52 return shutdown_completed_; |
55 } | 53 } |
56 | 54 |
57 private: | 55 private: |
58 // Called before a task with |shutdown_behavior| is handed off to | 56 // Called before WillPostTask() informs the tracing system that a task has |
59 // |post_task_callback| by PostTask(). Updates |num_tasks_blocking_shutdown_| | 57 // been posted. Updates |num_tasks_blocking_shutdown_| if necessary and |
60 // if necessary and returns true if the current shutdown state allows the task | 58 // returns true if the current shutdown state allows the task to be posted. |
61 // to be posted. | |
62 bool BeforePostTask(TaskShutdownBehavior shutdown_behavior); | 59 bool BeforePostTask(TaskShutdownBehavior shutdown_behavior); |
63 | 60 |
64 // Called before a task with |shutdown_behavior| is run by RunTask(). Updates | 61 // Called before a task with |shutdown_behavior| is run by RunTask(). Updates |
65 // |num_tasks_blocking_shutdown_| if necessary and returns true if the current | 62 // |num_tasks_blocking_shutdown_| if necessary and returns true if the current |
66 // shutdown state allows the task to be run. | 63 // shutdown state allows the task to be run. |
67 bool BeforeRunTask(TaskShutdownBehavior shutdown_behavior); | 64 bool BeforeRunTask(TaskShutdownBehavior shutdown_behavior); |
68 | 65 |
69 // Called after a task with |shutdown_behavior| has been run by RunTask(). | 66 // Called after a task with |shutdown_behavior| has been run by RunTask(). |
70 // Updates |num_tasks_blocking_shutdown_| and signals |shutdown_cv_| if | 67 // Updates |num_tasks_blocking_shutdown_| and signals |shutdown_cv_| if |
71 // necessary. | 68 // necessary. |
(...skipping 15 matching lines...) Expand all Loading... |
87 // True once Shutdown() has returned. No new task can be scheduled after this. | 84 // True once Shutdown() has returned. No new task can be scheduled after this. |
88 bool shutdown_completed_ = false; | 85 bool shutdown_completed_ = false; |
89 | 86 |
90 DISALLOW_COPY_AND_ASSIGN(TaskTracker); | 87 DISALLOW_COPY_AND_ASSIGN(TaskTracker); |
91 }; | 88 }; |
92 | 89 |
93 } // namespace internal | 90 } // namespace internal |
94 } // namespace base | 91 } // namespace base |
95 | 92 |
96 #endif // BASE_TASK_SCHEDULER_TASK_TRACKER_H_ | 93 #endif // BASE_TASK_SCHEDULER_TASK_TRACKER_H_ |
OLD | NEW |