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 "base/atomic_sequence_num.h" | 8 #include "base/atomic_sequence_num.h" |
9 #include "base/debug/task_annotator.h" | 9 #include "base/debug/task_annotator.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 namespace cc { | 26 namespace cc { |
27 class TestNowSource; | 27 class TestNowSource; |
28 } | 28 } |
29 | 29 |
30 namespace content { | 30 namespace content { |
31 namespace internal { | 31 namespace internal { |
32 class TaskQueue; | 32 class TaskQueue; |
33 } | 33 } |
34 class TaskQueueSelector; | 34 class TaskQueueSelector; |
| 35 class NestableSingleThreadTaskRunner; |
35 | 36 |
36 // The task queue manager provides N task queues and a selector interface for | 37 // The task queue manager provides N task queues and a selector interface for |
37 // choosing which task queue to service next. Each task queue consists of two | 38 // choosing which task queue to service next. Each task queue consists of two |
38 // sub queues: | 39 // sub queues: |
39 // | 40 // |
40 // 1. Incoming task queue. Tasks that are posted get immediately appended here. | 41 // 1. Incoming task queue. Tasks that are posted get immediately appended here. |
41 // When a task is appended into an empty incoming queue, the task manager | 42 // When a task is appended into an empty incoming queue, the task manager |
42 // work function (DoWork) is scheduled to run on the main task runner. | 43 // work function (DoWork) is scheduled to run on the main task runner. |
43 // | 44 // |
44 // 2. Work queue. If a work queue is empty when DoWork() is entered, tasks from | 45 // 2. Work queue. If a work queue is empty when DoWork() is entered, tasks from |
(...skipping 16 matching lines...) Expand all Loading... |
61 // automatically scheduled for execution or transferred to the work queue. | 62 // automatically scheduled for execution or transferred to the work queue. |
62 // Instead, the selector should call PumpQueue() when necessary to bring | 63 // Instead, the selector should call PumpQueue() when necessary to bring |
63 // in new tasks for execution. | 64 // in new tasks for execution. |
64 MANUAL | 65 MANUAL |
65 }; | 66 }; |
66 | 67 |
67 // Create a task queue manager with |task_queue_count| task queues. | 68 // Create a task queue manager with |task_queue_count| task queues. |
68 // |main_task_runner| identifies the thread on which where the tasks are | 69 // |main_task_runner| identifies the thread on which where the tasks are |
69 // eventually run. |selector| is used to choose which task queue to service. | 70 // eventually run. |selector| is used to choose which task queue to service. |
70 // It should outlive this class. | 71 // It should outlive this class. |
71 TaskQueueManager(size_t task_queue_count, | 72 TaskQueueManager( |
72 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 73 size_t task_queue_count, |
73 TaskQueueSelector* selector); | 74 scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner, |
| 75 TaskQueueSelector* selector); |
74 ~TaskQueueManager(); | 76 ~TaskQueueManager(); |
75 | 77 |
76 // Returns the task runner which targets the queue selected by |queue_index|. | 78 // Returns the task runner which targets the queue selected by |queue_index|. |
77 scoped_refptr<base::SingleThreadTaskRunner> TaskRunnerForQueue( | 79 scoped_refptr<base::SingleThreadTaskRunner> TaskRunnerForQueue( |
78 size_t queue_index) const; | 80 size_t queue_index) const; |
79 | 81 |
80 // Sets the pump policy for the |queue_index| to |pump_policy|. By | 82 // Sets the pump policy for the |queue_index| to |pump_policy|. By |
81 // default queues are created with AUTO_PUMP_POLICY. | 83 // default queues are created with AUTO_PUMP_POLICY. |
82 void SetPumpPolicy(size_t queue_index, PumpPolicy pump_policy); | 84 void SetPumpPolicy(size_t queue_index, PumpPolicy pump_policy); |
83 | 85 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 base::TimeTicks Now() const; | 164 base::TimeTicks Now() const; |
163 | 165 |
164 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 166 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
165 AsValueWithSelectorResult(bool should_run, size_t selected_queue) const; | 167 AsValueWithSelectorResult(bool should_run, size_t selected_queue) const; |
166 | 168 |
167 std::vector<scoped_refptr<internal::TaskQueue>> queues_; | 169 std::vector<scoped_refptr<internal::TaskQueue>> queues_; |
168 base::AtomicSequenceNumber task_sequence_num_; | 170 base::AtomicSequenceNumber task_sequence_num_; |
169 base::debug::TaskAnnotator task_annotator_; | 171 base::debug::TaskAnnotator task_annotator_; |
170 | 172 |
171 base::ThreadChecker main_thread_checker_; | 173 base::ThreadChecker main_thread_checker_; |
172 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 174 scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner_; |
173 TaskQueueSelector* selector_; | 175 TaskQueueSelector* selector_; |
174 | 176 |
175 base::WeakPtr<TaskQueueManager> task_queue_manager_weak_ptr_; | 177 base::WeakPtr<TaskQueueManager> task_queue_manager_weak_ptr_; |
176 | 178 |
177 // The pending_dowork_count_ is only tracked on the main thread since that's | 179 // The pending_dowork_count_ is only tracked on the main thread since that's |
178 // where re-entrant problems happen. | 180 // where re-entrant problems happen. |
179 int pending_dowork_count_; | 181 int pending_dowork_count_; |
180 | 182 |
181 int work_batch_size_; | 183 int work_batch_size_; |
182 | 184 |
183 scoped_refptr<cc::TestNowSource> time_source_; | 185 scoped_refptr<cc::TestNowSource> time_source_; |
184 | 186 |
185 ObserverList<base::MessageLoop::TaskObserver> task_observers_; | 187 ObserverList<base::MessageLoop::TaskObserver> task_observers_; |
186 | 188 |
187 base::WeakPtrFactory<TaskQueueManager> weak_factory_; | 189 base::WeakPtrFactory<TaskQueueManager> weak_factory_; |
188 | 190 |
189 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); | 191 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); |
190 }; | 192 }; |
191 | 193 |
192 } // namespace content | 194 } // namespace content |
193 | 195 |
194 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ | 196 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ |
OLD | NEW |