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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 // Returns true while shutdown is in progress (i.e. Shutdown() has been called | 47 // Returns true while shutdown is in progress (i.e. Shutdown() has been called |
48 // but hasn't returned). | 48 // but hasn't returned). |
49 bool IsShuttingDownForTesting() const; | 49 bool IsShuttingDownForTesting() const; |
50 | 50 |
51 bool shutdown_completed() const { | 51 bool shutdown_completed() const { |
52 AutoSchedulerLock auto_lock(lock_); | 52 AutoSchedulerLock auto_lock(lock_); |
53 return shutdown_completed_; | 53 return shutdown_completed_; |
54 } | 54 } |
55 | 55 |
56 private: | 56 private: |
57 class State; | |
58 | |
57 // Called before WillPostTask() informs the tracing system that a task has | 59 // Called before WillPostTask() informs the tracing system that a task has |
58 // been posted. Updates |num_tasks_blocking_shutdown_| if necessary and | 60 // been posted. Updates |num_tasks_blocking_shutdown_| if necessary and |
59 // returns true if the current shutdown state allows the task to be posted. | 61 // returns true if the current shutdown state allows the task to be posted. |
60 bool BeforePostTask(TaskShutdownBehavior shutdown_behavior); | 62 bool BeforePostTask(TaskShutdownBehavior shutdown_behavior); |
61 | 63 |
62 // Called before a task with |shutdown_behavior| is run by RunTask(). Updates | 64 // Called before a task with |shutdown_behavior| is run by RunTask(). Updates |
63 // |num_tasks_blocking_shutdown_| if necessary and returns true if the current | 65 // |num_tasks_blocking_shutdown_| if necessary and returns true if the current |
64 // shutdown state allows the task to be run. | 66 // shutdown state allows the task to be run. |
65 bool BeforeRunTask(TaskShutdownBehavior shutdown_behavior); | 67 bool BeforeRunTask(TaskShutdownBehavior shutdown_behavior); |
66 | 68 |
67 // Called after a task with |shutdown_behavior| has been run by RunTask(). | 69 // Called after a task with |shutdown_behavior| has been run by RunTask(). |
68 // Updates |num_tasks_blocking_shutdown_| and signals |shutdown_cv_| if | 70 // Updates |num_tasks_blocking_shutdown_| and signals |shutdown_cv_| if |
69 // necessary. | 71 // necessary. |
70 void AfterRunTask(TaskShutdownBehavior shutdown_behavior); | 72 void AfterRunTask(TaskShutdownBehavior shutdown_behavior); |
71 | 73 |
72 // Synchronizes access to all members. | 74 // Called when the number of tasks blocking shutdown becomes zero after |
75 // shutdown has started. | |
76 void OnNumTasksBlockingShutdownIsZero(); | |
robliao
2016/05/27 22:16:14
Alternately
OnBlockingShutdownTasksComplete
fdoray
2016/05/30 15:48:05
Done.
| |
77 | |
78 // Number of tasks blocking shutdown and boolean indicating whether shutdown | |
79 // has started. | |
80 const std::unique_ptr<State> state_; | |
81 | |
82 // Synchronizes access to all members below. | |
73 mutable SchedulerLock lock_; | 83 mutable SchedulerLock lock_; |
74 | 84 |
75 // Condition variable signaled when |num_tasks_blocking_shutdown_| reaches | 85 // Condition variable signaled when the number of tasks blocking shutdown |
76 // zero while shutdown is in progress. Null if shutdown isn't in progress. | 86 // reaches zero while shutdown is in progress. Null if shutdown isn't in |
87 // progress. | |
77 std::unique_ptr<ConditionVariable> shutdown_cv_; | 88 std::unique_ptr<ConditionVariable> shutdown_cv_; |
78 | 89 |
79 // Number of tasks blocking shutdown. | |
80 size_t num_tasks_blocking_shutdown_ = 0; | |
81 | |
82 // Number of BLOCK_SHUTDOWN tasks posted during shutdown. | 90 // Number of BLOCK_SHUTDOWN tasks posted during shutdown. |
83 HistogramBase::Sample num_block_shutdown_tasks_posted_during_shutdown_ = 0; | 91 HistogramBase::Sample num_block_shutdown_tasks_posted_during_shutdown_ = 0; |
84 | 92 |
85 // True once Shutdown() has returned. No new task can be scheduled after this. | 93 // True once Shutdown() has returned. No new task can be scheduled after this. |
86 bool shutdown_completed_ = false; | 94 bool shutdown_completed_ = false; |
87 | 95 |
88 DISALLOW_COPY_AND_ASSIGN(TaskTracker); | 96 DISALLOW_COPY_AND_ASSIGN(TaskTracker); |
89 }; | 97 }; |
90 | 98 |
91 } // namespace internal | 99 } // namespace internal |
92 } // namespace base | 100 } // namespace base |
93 | 101 |
94 #endif // BASE_TASK_SCHEDULER_TASK_TRACKER_H_ | 102 #endif // BASE_TASK_SCHEDULER_TASK_TRACKER_H_ |
OLD | NEW |