| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_ | 5 #ifndef CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_ |
| 6 #define CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_ | 6 #define CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/atomic_sequence_num.h" | 10 #include "base/atomic_sequence_num.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 namespace scheduler { | 32 namespace scheduler { |
| 33 namespace internal { | 33 namespace internal { |
| 34 class TaskQueueImpl; | 34 class TaskQueueImpl; |
| 35 } // namespace internal | 35 } // namespace internal |
| 36 | 36 |
| 37 class LazyNow; | 37 class LazyNow; |
| 38 class RealTimeDomain; | 38 class RealTimeDomain; |
| 39 class TimeDomain; | 39 class TimeDomain; |
| 40 class TaskQueueManagerDelegate; | 40 class TaskQueueManagerDelegate; |
| 41 class TaskTimeTracker; |
| 41 | 42 |
| 42 // The task queue manager provides N task queues and a selector interface for | 43 // The task queue manager provides N task queues and a selector interface for |
| 43 // choosing which task queue to service next. Each task queue consists of two | 44 // choosing which task queue to service next. Each task queue consists of two |
| 44 // sub queues: | 45 // sub queues: |
| 45 // | 46 // |
| 46 // 1. Incoming task queue. Tasks that are posted get immediately appended here. | 47 // 1. Incoming task queue. Tasks that are posted get immediately appended here. |
| 47 // When a task is appended into an empty incoming queue, the task manager | 48 // When a task is appended into an empty incoming queue, the task manager |
| 48 // work function (DoWork) is scheduled to run on the main task runner. | 49 // work function (DoWork) is scheduled to run on the main task runner. |
| 49 // | 50 // |
| 50 // 2. Work queue. If a work queue is empty when DoWork() is entered, tasks from | 51 // 2. Work queue. If a work queue is empty when DoWork() is entered, tasks from |
| (...skipping 24 matching lines...) Expand all Loading... |
| 75 void MaybeScheduleDelayedWork(const tracked_objects::Location& from_here, | 76 void MaybeScheduleDelayedWork(const tracked_objects::Location& from_here, |
| 76 base::TimeTicks now, | 77 base::TimeTicks now, |
| 77 base::TimeDelta delay); | 78 base::TimeDelta delay); |
| 78 | 79 |
| 79 // Set the number of tasks executed in a single invocation of the task queue | 80 // Set the number of tasks executed in a single invocation of the task queue |
| 80 // manager. Increasing the batch size can reduce the overhead of yielding | 81 // manager. Increasing the batch size can reduce the overhead of yielding |
| 81 // back to the main message loop -- at the cost of potentially delaying other | 82 // back to the main message loop -- at the cost of potentially delaying other |
| 82 // tasks posted to the main loop. The batch size is 1 by default. | 83 // tasks posted to the main loop. The batch size is 1 by default. |
| 83 void SetWorkBatchSize(int work_batch_size); | 84 void SetWorkBatchSize(int work_batch_size); |
| 84 | 85 |
| 86 // When given a non-null TaskTimeTracker, the TaskQueueManager calls its |
| 87 // ReportTaskTime method for every top level task. The task_time_tracker must |
| 88 // outlive this object, or be removed via SetTaskTimeTracker(nullptr). |
| 89 void SetTaskTimeTracker(TaskTimeTracker* task_time_tracker) { |
| 90 task_time_tracker_ = task_time_tracker; |
| 91 } |
| 92 |
| 85 // These functions can only be called on the same thread that the task queue | 93 // These functions can only be called on the same thread that the task queue |
| 86 // manager executes its tasks on. | 94 // manager executes its tasks on. |
| 87 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer); | 95 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer); |
| 88 void RemoveTaskObserver(base::MessageLoop::TaskObserver* task_observer); | 96 void RemoveTaskObserver(base::MessageLoop::TaskObserver* task_observer); |
| 89 | 97 |
| 90 // Returns true if any task from a monitored task queue was was run since the | 98 // Returns true if any task from a monitored task queue was was run since the |
| 91 // last call to GetAndClearSystemIsQuiescentBit. | 99 // last call to GetAndClearSystemIsQuiescentBit. |
| 92 bool GetAndClearSystemIsQuiescentBit(); | 100 bool GetAndClearSystemIsQuiescentBit(); |
| 93 | 101 |
| 94 // Creates a task queue with the given |spec|. Must be called on the thread | 102 // Creates a task queue with the given |spec|. Must be called on the thread |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 168 |
| 161 // Use the selector to choose a pending task and run it. | 169 // Use the selector to choose a pending task and run it. |
| 162 void DoWork(base::TimeTicks run_time, bool from_main_thread); | 170 void DoWork(base::TimeTicks run_time, bool from_main_thread); |
| 163 | 171 |
| 164 // Delayed Tasks with run_times <= Now() are enqueued onto the work queue. | 172 // Delayed Tasks with run_times <= Now() are enqueued onto the work queue. |
| 165 // Reloads any empty work queues which have automatic pumping enabled and | 173 // Reloads any empty work queues which have automatic pumping enabled and |
| 166 // which are eligible to be auto pumped based on the |previous_task| which was | 174 // which are eligible to be auto pumped based on the |previous_task| which was |
| 167 // run and |should_trigger_wakeup|. Call with an empty |previous_task| if no | 175 // run and |should_trigger_wakeup|. Call with an empty |previous_task| if no |
| 168 // task was just run. | 176 // task was just run. |
| 169 void UpdateWorkQueues(bool should_trigger_wakeup, | 177 void UpdateWorkQueues(bool should_trigger_wakeup, |
| 170 const internal::TaskQueueImpl::Task* previous_task); | 178 const internal::TaskQueueImpl::Task* previous_task, |
| 179 LazyNow lazy_now); |
| 171 | 180 |
| 172 // Chooses the next work queue to service. Returns true if |out_queue| | 181 // Chooses the next work queue to service. Returns true if |out_queue| |
| 173 // indicates the queue from which the next task should be run, false to | 182 // indicates the queue from which the next task should be run, false to |
| 174 // avoid running any tasks. | 183 // avoid running any tasks. |
| 175 bool SelectWorkQueueToService(internal::WorkQueue** out_work_queue); | 184 bool SelectWorkQueueToService(internal::WorkQueue** out_work_queue); |
| 176 | 185 |
| 177 // Runs a single nestable task from the |queue|. On exit, |out_task| will | 186 // Runs a single nestable task from the |queue|. On exit, |out_task| will |
| 178 // contain the task which was executed. Non-nestable task are reposted on the | 187 // contain the task which was executed. Non-nestable task are reposted on the |
| 179 // run loop. The queue must not be empty. | 188 // run loop. The queue must not be empty. |
| 180 enum class ProcessTaskResult { | 189 enum class ProcessTaskResult { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 228 |
| 220 base::ThreadChecker main_thread_checker_; | 229 base::ThreadChecker main_thread_checker_; |
| 221 scoped_refptr<TaskQueueManagerDelegate> delegate_; | 230 scoped_refptr<TaskQueueManagerDelegate> delegate_; |
| 222 internal::TaskQueueSelector selector_; | 231 internal::TaskQueueSelector selector_; |
| 223 | 232 |
| 224 base::Closure from_main_thread_immediate_do_work_closure_; | 233 base::Closure from_main_thread_immediate_do_work_closure_; |
| 225 base::Closure from_other_thread_immediate_do_work_closure_; | 234 base::Closure from_other_thread_immediate_do_work_closure_; |
| 226 | 235 |
| 227 bool task_was_run_on_quiescence_monitored_queue_; | 236 bool task_was_run_on_quiescence_monitored_queue_; |
| 228 | 237 |
| 229 // To reduce locking overhead we track pending calls to DoWork seperatly for | 238 // To reduce locking overhead we track pending calls to DoWork separately for |
| 230 // the main thread and other threads. | 239 // the main thread and other threads. |
| 231 std::set<base::TimeTicks> main_thread_pending_wakeups_; | 240 std::set<base::TimeTicks> main_thread_pending_wakeups_; |
| 232 | 241 |
| 233 // Protects |other_thread_pending_wakeups_|. | 242 // Protects |other_thread_pending_wakeups_|. |
| 234 mutable base::Lock other_thread_lock_; | 243 mutable base::Lock other_thread_lock_; |
| 235 std::set<base::TimeTicks> other_thread_pending_wakeups_; | 244 std::set<base::TimeTicks> other_thread_pending_wakeups_; |
| 236 | 245 |
| 237 int work_batch_size_; | 246 int work_batch_size_; |
| 238 size_t task_count_; | 247 size_t task_count_; |
| 239 | 248 |
| 240 base::ObserverList<base::MessageLoop::TaskObserver> task_observers_; | 249 base::ObserverList<base::MessageLoop::TaskObserver> task_observers_; |
| 241 | 250 |
| 251 TaskTimeTracker* task_time_tracker_; // NOT OWNED |
| 252 |
| 242 const char* tracing_category_; | 253 const char* tracing_category_; |
| 243 const char* disabled_by_default_tracing_category_; | 254 const char* disabled_by_default_tracing_category_; |
| 244 const char* disabled_by_default_verbose_tracing_category_; | 255 const char* disabled_by_default_verbose_tracing_category_; |
| 245 | 256 |
| 246 internal::TaskQueueImpl* currently_executing_task_queue_; // NOT OWNED | 257 internal::TaskQueueImpl* currently_executing_task_queue_; // NOT OWNED |
| 247 | 258 |
| 248 Observer* observer_; // NOT OWNED | 259 Observer* observer_; // NOT OWNED |
| 249 scoped_refptr<DeletionSentinel> deletion_sentinel_; | 260 scoped_refptr<DeletionSentinel> deletion_sentinel_; |
| 250 base::WeakPtrFactory<TaskQueueManager> weak_factory_; | 261 base::WeakPtrFactory<TaskQueueManager> weak_factory_; |
| 251 | 262 |
| 252 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); | 263 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); |
| 253 }; | 264 }; |
| 254 | 265 |
| 255 } // namespace scheduler | 266 } // namespace scheduler |
| 256 | 267 |
| 257 #endif // CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_ | 268 #endif // CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_ |
| OLD | NEW |