Chromium Code Reviews| 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_TASK_QUEUE_MANAGER_H_ | 5 #ifndef CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ |
| 6 #define CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ | 6 #define CONTENT_RENDERER_SCHEDULER_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 13 matching lines...) Expand all Loading... | |
| 24 | 24 |
| 25 namespace trace_event { | 25 namespace trace_event { |
| 26 class ConvertableToTraceFormat; | 26 class ConvertableToTraceFormat; |
| 27 class TracedValue; | 27 class TracedValue; |
| 28 } // namespace trace_event | 28 } // namespace trace_event |
| 29 } // namespace base | 29 } // namespace base |
| 30 | 30 |
| 31 namespace scheduler { | 31 namespace scheduler { |
| 32 namespace internal { | 32 namespace internal { |
| 33 class LazyNow; | 33 class LazyNow; |
| 34 struct SchedulerTask; | |
| 34 class TaskQueueImpl; | 35 class TaskQueueImpl; |
| 35 } // namespace internal | 36 } // namespace internal |
| 36 | 37 |
| 37 class NestableSingleThreadTaskRunner; | 38 class NestableSingleThreadTaskRunner; |
| 38 | 39 |
| 39 // The task queue manager provides N task queues and a selector interface for | 40 // The task queue manager provides N task queues and a selector interface for |
| 40 // choosing which task queue to service next. Each task queue consists of two | 41 // choosing which task queue to service next. Each task queue consists of two |
| 41 // sub queues: | 42 // sub queues: |
| 42 // | 43 // |
| 43 // 1. Incoming task queue. Tasks that are posted get immediately appended here. | 44 // 1. Incoming task queue. Tasks that are posted get immediately appended here. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 class DeletionSentinel : public base::RefCounted<DeletionSentinel> { | 97 class DeletionSentinel : public base::RefCounted<DeletionSentinel> { |
| 97 private: | 98 private: |
| 98 friend class base::RefCounted<DeletionSentinel>; | 99 friend class base::RefCounted<DeletionSentinel>; |
| 99 ~DeletionSentinel() {} | 100 ~DeletionSentinel() {} |
| 100 }; | 101 }; |
| 101 | 102 |
| 102 // TaskQueueSelector::Observer implementation: | 103 // TaskQueueSelector::Observer implementation: |
| 103 void OnTaskQueueEnabled() override; | 104 void OnTaskQueueEnabled() override; |
| 104 | 105 |
| 105 // Called by the task queue to register a new pending task. | 106 // Called by the task queue to register a new pending task. |
| 106 void DidQueueTask(const base::PendingTask& pending_task); | 107 void DidQueueTask(internal::SchedulerTask& pending_task); |
|
Sami
2015/08/05 11:27:34
The argument should be a pointer since we're modif
alex clarke (OOO till 29th)
2015/08/05 14:32:44
Done.
| |
| 107 | 108 |
| 108 // Post a task to call DoWork() on the main task runner. Only one pending | 109 // Post a task to call DoWork() on the main task runner. Only one pending |
| 109 // DoWork is allowed from the main thread, to prevent an explosion of pending | 110 // DoWork is allowed from the main thread, to prevent an explosion of pending |
| 110 // DoWorks. | 111 // DoWorks. |
| 111 void MaybePostDoWorkOnMainRunner(); | 112 void MaybePostDoWorkOnMainRunner(); |
| 112 | 113 |
| 113 // Use the selector to choose a pending task and run it. | 114 // Use the selector to choose a pending task and run it. |
| 114 void DoWork(bool posted_from_main_thread); | 115 void DoWork(bool posted_from_main_thread); |
| 115 | 116 |
| 116 // Delayed Tasks with run_times <= Now() are enqueued onto the work queue. | 117 // Delayed Tasks with run_times <= Now() are enqueued onto the work queue. |
| 117 // Reloads any empty work queues which have automatic pumping enabled and | 118 // Reloads any empty work queues which have automatic pumping enabled and |
| 118 // which are eligible to be auto pumped based on the |previous_task| which was | 119 // which are eligible to be auto pumped based on the |previous_task| which was |
| 119 // run and |should_trigger_wakeup|. Call with an empty |previous_task| if no | 120 // run and |should_trigger_wakeup|. Call with an empty |previous_task| if no |
| 120 // task was just run. | 121 // task was just run. |
| 121 void UpdateWorkQueues(bool should_trigger_wakeup, | 122 void UpdateWorkQueues(bool should_trigger_wakeup, |
| 122 const base::PendingTask* previous_task); | 123 const internal::SchedulerTask* previous_task); |
| 123 | 124 |
| 124 // Chooses the next work queue to service. Returns true if |out_queue| | 125 // Chooses the next work queue to service. Returns true if |out_queue| |
| 125 // indicates the queue from which the next task should be run, false to | 126 // indicates the queue from which the next task should be run, false to |
| 126 // avoid running any tasks. | 127 // avoid running any tasks. |
| 127 bool SelectQueueToService(internal::TaskQueueImpl** out_queue); | 128 bool SelectQueueToService(internal::TaskQueueImpl** out_queue); |
| 128 | 129 |
| 129 // Runs a single nestable task from the |queue|. On exit, |out_task| will | 130 // Runs a single nestable task from the |queue|. On exit, |out_task| will |
| 130 // contain the task which was executed. Non-nestable task are reposted on the | 131 // contain the task which was executed. Non-nestable task are reposted on the |
| 131 // run loop. The queue must not be empty. Returns true if the TaskQueueManager | 132 // run loop. The queue must not be empty. Returns true if the TaskQueueManager |
| 132 // got deleted, and false otherwise. | 133 // got deleted, and false otherwise. |
| 133 bool ProcessTaskFromWorkQueue(internal::TaskQueueImpl* queue, | 134 bool ProcessTaskFromWorkQueue(internal::TaskQueueImpl* queue, |
| 134 base::PendingTask* out_previous_task); | 135 internal::SchedulerTask* out_previous_task); |
| 135 | 136 |
| 136 bool RunsTasksOnCurrentThread() const; | 137 bool RunsTasksOnCurrentThread() const; |
| 137 bool PostDelayedTask(const tracked_objects::Location& from_here, | 138 bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 138 const base::Closure& task, | 139 const base::Closure& task, |
| 139 base::TimeDelta delay); | 140 base::TimeDelta delay); |
| 140 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, | 141 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, |
| 141 const base::Closure& task, | 142 const base::Closure& task, |
| 142 base::TimeDelta delay); | 143 base::TimeDelta delay); |
| 143 | 144 |
| 144 base::TimeTicks Now() const; | 145 base::TimeTicks Now() const; |
| 145 | 146 |
| 146 int GetNextSequenceNumber(); | 147 int GetNextSequenceNumber(); |
| 148 int GetNextAgeNumber(); | |
| 147 | 149 |
| 148 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 150 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
| 149 AsValueWithSelectorResult(bool should_run, | 151 AsValueWithSelectorResult(bool should_run, |
| 150 internal::TaskQueueImpl* selected_queue) const; | 152 internal::TaskQueueImpl* selected_queue) const; |
| 151 | 153 |
| 152 // Causes DoWork to start calling UpdateWorkQueue for |queue|. Can be called | 154 // Causes DoWork to start calling UpdateWorkQueue for |queue|. Can be called |
| 153 // from any thread. | 155 // from any thread. |
| 154 void RegisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue); | 156 void RegisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue); |
| 155 | 157 |
| 156 // Prevents DoWork from calling UpdateWorkQueue for |queue|. Must be called | 158 // Prevents DoWork from calling UpdateWorkQueue for |queue|. Must be called |
| 157 // from the thread the TaskQueueManager was created on. | 159 // from the thread the TaskQueueManager was created on. |
| 158 void UnregisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue); | 160 void UnregisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue); |
| 159 | 161 |
| 160 std::set<scoped_refptr<internal::TaskQueueImpl>> queues_; | 162 std::set<scoped_refptr<internal::TaskQueueImpl>> queues_; |
| 161 | 163 |
| 162 // This lock guards only |newly_updatable_|. It's not expected to be heavily | 164 // This lock guards only |newly_updatable_|. It's not expected to be heavily |
| 163 // contended. | 165 // contended. |
| 164 base::Lock newly_updatable_lock_; | 166 base::Lock newly_updatable_lock_; |
| 165 std::vector<internal::TaskQueueImpl*> newly_updatable_; | 167 std::vector<internal::TaskQueueImpl*> newly_updatable_; |
| 166 | 168 |
| 167 // Set of task queues with avaliable work on the incoming queue. This should | 169 // Set of task queues with avaliable work on the incoming queue. This should |
| 168 // only be accessed from the main thread. | 170 // only be accessed from the main thread. |
| 169 std::set<internal::TaskQueueImpl*> updatable_queue_set_; | 171 std::set<internal::TaskQueueImpl*> updatable_queue_set_; |
| 170 | 172 |
| 171 base::AtomicSequenceNumber task_sequence_num_; | 173 base::AtomicSequenceNumber task_sequence_num_; |
| 174 base::AtomicSequenceNumber task_age_num_; | |
| 172 base::debug::TaskAnnotator task_annotator_; | 175 base::debug::TaskAnnotator task_annotator_; |
| 173 | 176 |
| 174 base::ThreadChecker main_thread_checker_; | 177 base::ThreadChecker main_thread_checker_; |
| 175 scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner_; | 178 scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner_; |
| 176 internal::TaskQueueSelector selector_; | 179 internal::TaskQueueSelector selector_; |
| 177 | 180 |
| 178 base::Closure do_work_from_main_thread_closure_; | 181 base::Closure do_work_from_main_thread_closure_; |
| 179 base::Closure do_work_from_other_thread_closure_; | 182 base::Closure do_work_from_other_thread_closure_; |
| 180 | 183 |
| 181 bool task_was_run_on_quiescence_monitored_queue_; | 184 bool task_was_run_on_quiescence_monitored_queue_; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 195 | 198 |
| 196 scoped_refptr<DeletionSentinel> deletion_sentinel_; | 199 scoped_refptr<DeletionSentinel> deletion_sentinel_; |
| 197 base::WeakPtrFactory<TaskQueueManager> weak_factory_; | 200 base::WeakPtrFactory<TaskQueueManager> weak_factory_; |
| 198 | 201 |
| 199 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); | 202 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); |
| 200 }; | 203 }; |
| 201 | 204 |
| 202 } // namespace scheduler | 205 } // namespace scheduler |
| 203 | 206 |
| 204 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ | 207 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ |
| OLD | NEW |