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

Side by Side Diff: components/scheduler/child/scheduler_helper.h

Issue 1101703003: Adds a SHUTDOWN_TASK_QUEUE and a PreShutdown api to the scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase of DOOM Created 5 years, 8 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 COMPONENTS_SCHEDULER_CHILD_SCHEDULER_HELPER_H_ 5 #ifndef COMPONENTS_SCHEDULER_CHILD_SCHEDULER_HELPER_H_
6 #define COMPONENTS_SCHEDULER_CHILD_SCHEDULER_HELPER_H_ 6 #define COMPONENTS_SCHEDULER_CHILD_SCHEDULER_HELPER_H_
7 7
8 #include "components/scheduler/child/cancelable_closure_holder.h" 8 #include "components/scheduler/child/cancelable_closure_holder.h"
9 #include "components/scheduler/child/single_thread_idle_task_runner.h" 9 #include "components/scheduler/child/single_thread_idle_task_runner.h"
10 #include "components/scheduler/child/task_queue_manager.h" 10 #include "components/scheduler/child/task_queue_manager.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 ~SchedulerHelper(); 54 ~SchedulerHelper();
55 55
56 // Returns the default task runner. 56 // Returns the default task runner.
57 scoped_refptr<base::SingleThreadTaskRunner> DefaultTaskRunner(); 57 scoped_refptr<base::SingleThreadTaskRunner> DefaultTaskRunner();
58 58
59 // Returns the idle task runner. Tasks posted to this runner may be reordered 59 // Returns the idle task runner. Tasks posted to this runner may be reordered
60 // relative to other task types and may be starved for an arbitrarily long 60 // relative to other task types and may be starved for an arbitrarily long
61 // time if no idle time is available. 61 // time if no idle time is available.
62 scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner(); 62 scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner();
63 63
64 // Returns the shutdown task runner. Intended for tasks that must be able to
65 // run, even after PreShutdown() is called.
66 scoped_refptr<base::SingleThreadTaskRunner> ShutdownTaskRunner();
67
64 // Returns the control task runner. Tasks posted to this runner are executed 68 // Returns the control task runner. Tasks posted to this runner are executed
65 // with the highest priority. Care must be taken to avoid starvation of other 69 // with the highest priority. Care must be taken to avoid starvation of other
66 // task queues. 70 // task queues.
67 scoped_refptr<base::SingleThreadTaskRunner> ControlTaskRunner(); 71 scoped_refptr<base::SingleThreadTaskRunner> ControlTaskRunner();
68 72
69 // Returns true if a currently running idle task could exceed its deadline 73 // Returns true if a currently running idle task could exceed its deadline
70 // without impacting user experience too much. This should only be used if 74 // without impacting user experience too much. This should only be used if
71 // there is a task which cannot be pre-empted and is likely to take longer 75 // there is a task which cannot be pre-empted and is likely to take longer
72 // than the largest expected idle task deadline. It should NOT be polled to 76 // than the largest expected idle task deadline. It should NOT be polled to
73 // check whether more work can be performed on the current idle task after 77 // check whether more work can be performed on the current idle task after
74 // its deadline has expired - post a new idle task for the continuation of the 78 // its deadline has expired - post a new idle task for the continuation of the
75 // work in this case. 79 // work in this case.
76 // Must be called from the thread this class was created on. 80 // Must be called from the thread this class was created on.
77 bool CanExceedIdleDeadlineIfRequired() const; 81 bool CanExceedIdleDeadlineIfRequired() const;
78 82
79 // Adds or removes a task observer from the scheduler. The observer will be 83 // Adds or removes a task observer from the scheduler. The observer will be
80 // notified before and after every executed task. These functions can only be 84 // notified before and after every executed task. These functions can only be
81 // called on the thread this class was created on. 85 // called on the thread this class was created on.
82 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer); 86 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer);
83 void RemoveTaskObserver(base::MessageLoop::TaskObserver* task_observer); 87 void RemoveTaskObserver(base::MessageLoop::TaskObserver* task_observer);
84 88
89 // Optional. This stops all queues except for shutdown and control queues.
90 // Also ends any idle periods. If posted from a different thread, it blocks
91 // until the thread this class was created on has completed the pre-shutdown.
92 void PreShutdown();
93
85 // Shuts down the scheduler by dropping any remaining pending work in the work 94 // Shuts down the scheduler by dropping any remaining pending work in the work
86 // queues. After this call any work posted to the task runners will be 95 // queues. After this call any work posted to the task runners will be
87 // silently dropped. 96 // silently dropped.
88 void Shutdown(); 97 void Shutdown();
89 98
90 // Returns true if Shutdown() has been called. Otherwise returns false. 99 // Returns true if Shutdown() has been called. Otherwise returns false.
91 bool IsShutdown() const { return !task_queue_manager_.get(); } 100 bool IsShutdown() const { return !task_queue_manager_.get(); }
92 101
93 // Keep SchedulerHelper::TaskQueueIdToString in sync with this enum. 102 // Keep SchedulerHelper::TaskQueueIdToString in sync with this enum.
94 enum QueueId { 103 enum QueueId {
95 DEFAULT_TASK_QUEUE, 104 DEFAULT_TASK_QUEUE,
96 IDLE_TASK_QUEUE, 105 IDLE_TASK_QUEUE,
106 SHUTDOWN_TASK_QUEUE,
97 CONTROL_TASK_QUEUE, 107 CONTROL_TASK_QUEUE,
98 CONTROL_TASK_AFTER_WAKEUP_QUEUE, 108 CONTROL_TASK_AFTER_WAKEUP_QUEUE,
99 // Must be the last entry. 109 // Must be the last entry.
100 TASK_QUEUE_COUNT, 110 TASK_QUEUE_COUNT,
101 }; 111 };
102 112
103 // Keep SchedulerHelper::IdlePeriodStateToString in sync with this enum. 113 // Keep SchedulerHelper::IdlePeriodStateToString in sync with this enum.
104 enum class IdlePeriodState { 114 enum class IdlePeriodState {
105 NOT_IN_IDLE_PERIOD, 115 NOT_IN_IDLE_PERIOD,
106 IN_SHORT_IDLE_PERIOD, 116 IN_SHORT_IDLE_PERIOD,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // Test helpers. 178 // Test helpers.
169 void SetTimeSourceForTesting(scoped_ptr<TimeSource> time_source); 179 void SetTimeSourceForTesting(scoped_ptr<TimeSource> time_source);
170 void SetWorkBatchSizeForTesting(size_t work_batch_size); 180 void SetWorkBatchSizeForTesting(size_t work_batch_size);
171 TaskQueueManager* GetTaskQueueManagerForTesting(); 181 TaskQueueManager* GetTaskQueueManagerForTesting();
172 182
173 private: 183 private:
174 friend class SchedulerHelperTest; 184 friend class SchedulerHelperTest;
175 185
176 bool ShouldWaitForQuiescence(); 186 bool ShouldWaitForQuiescence();
177 void EnableLongIdlePeriodAfterWakeup(); 187 void EnableLongIdlePeriodAfterWakeup();
188 void PreShutdownInternal(base::WaitableEvent* completion);
178 189
179 base::ThreadChecker thread_checker_; 190 base::ThreadChecker thread_checker_;
180 scoped_ptr<PrioritizingTaskQueueSelector> task_queue_selector_; 191 scoped_ptr<PrioritizingTaskQueueSelector> task_queue_selector_;
181 scoped_ptr<TaskQueueManager> task_queue_manager_; 192 scoped_ptr<TaskQueueManager> task_queue_manager_;
182 193
183 CancelableClosureHolder end_idle_period_closure_; 194 CancelableClosureHolder end_idle_period_closure_;
184 CancelableClosureHolder enable_next_long_idle_period_closure_; 195 CancelableClosureHolder enable_next_long_idle_period_closure_;
185 CancelableClosureHolder enable_next_long_idle_period_after_wakeup_closure_; 196 CancelableClosureHolder enable_next_long_idle_period_after_wakeup_closure_;
186 197
187 IdlePeriodState idle_period_state_; 198 IdlePeriodState idle_period_state_;
188 SchedulerHelperDelegate* scheduler_helper_delegate_; // NOT OWNED 199 SchedulerHelperDelegate* scheduler_helper_delegate_; // NOT OWNED
189 200
190 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_; 201 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_;
191 scoped_refptr<base::SingleThreadTaskRunner> control_task_after_wakeup_runner_; 202 scoped_refptr<base::SingleThreadTaskRunner> control_task_after_wakeup_runner_;
192 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; 203 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_;
204 scoped_refptr<base::SingleThreadTaskRunner> shutdown_task_runner_;
193 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; 205 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_;
194 206
207 size_t total_task_queue_count_;
208
195 // A bitmap which controls the set of queues that are checked for quiescence 209 // A bitmap which controls the set of queues that are checked for quiescence
196 // before triggering a long idle period. 210 // before triggering a long idle period.
197 uint64 quiescence_monitored_task_queue_mask_; 211 uint64 quiescence_monitored_task_queue_mask_;
198 base::TimeDelta required_quiescence_duration_before_long_idle_period_; 212 base::TimeDelta required_quiescence_duration_before_long_idle_period_;
199 213
200 base::TimeTicks idle_period_deadline_; 214 base::TimeTicks idle_period_deadline_;
201 scoped_ptr<TimeSource> time_source_; 215 scoped_ptr<TimeSource> time_source_;
202 216
203 const char* tracing_category_; 217 const char* tracing_category_;
204 const char* disabled_by_default_tracing_category_; 218 const char* disabled_by_default_tracing_category_;
205 const char* idle_period_tracing_name_; 219 const char* idle_period_tracing_name_;
206 220
207 base::WeakPtr<SchedulerHelper> weak_scheduler_ptr_; 221 base::WeakPtr<SchedulerHelper> weak_scheduler_ptr_;
208 base::WeakPtrFactory<SchedulerHelper> weak_factory_; 222 base::WeakPtrFactory<SchedulerHelper> weak_factory_;
209 223
210 DISALLOW_COPY_AND_ASSIGN(SchedulerHelper); 224 DISALLOW_COPY_AND_ASSIGN(SchedulerHelper);
211 }; 225 };
212 226
213 } // namespace scheduler 227 } // namespace scheduler
214 228
215 #endif // COMPONENTS_SCHEDULER_CHILD_SCHEDULER_HELPER_H_ 229 #endif // COMPONENTS_SCHEDULER_CHILD_SCHEDULER_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698