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" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/pending_task.h" | 13 #include "base/pending_task.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
17 #include "components/scheduler/child/task_queue_selector.h" | 17 #include "components/scheduler/child/task_queue_selector.h" |
18 #include "components/scheduler/child/time_source.h" | |
19 #include "components/scheduler/scheduler_export.h" | 18 #include "components/scheduler/scheduler_export.h" |
20 | 19 |
21 namespace base { | 20 namespace base { |
22 namespace trace_event { | 21 namespace trace_event { |
23 class ConvertableToTraceFormat; | 22 class ConvertableToTraceFormat; |
24 class TracedValue; | 23 class TracedValue; |
25 } | 24 } |
| 25 class TickClock; |
26 } | 26 } |
27 | 27 |
28 namespace scheduler { | 28 namespace scheduler { |
29 namespace internal { | 29 namespace internal { |
30 class LazyNow; | 30 class LazyNow; |
31 class TaskQueue; | 31 class TaskQueue; |
32 } | 32 } |
33 class NestableSingleThreadTaskRunner; | 33 class NestableSingleThreadTaskRunner; |
34 class TaskQueueSelector; | 34 class TaskQueueSelector; |
35 class TimeSource; | |
36 | 35 |
37 // The task queue manager provides N task queues and a selector interface for | 36 // The task queue manager provides N task queues and a selector interface for |
38 // choosing which task queue to service next. Each task queue consists of two | 37 // choosing which task queue to service next. Each task queue consists of two |
39 // sub queues: | 38 // sub queues: |
40 // | 39 // |
41 // 1. Incoming task queue. Tasks that are posted get immediately appended here. | 40 // 1. Incoming task queue. Tasks that are posted get immediately appended here. |
42 // When a task is appended into an empty incoming queue, the task manager | 41 // When a task is appended into an empty incoming queue, the task manager |
43 // work function (DoWork) is scheduled to run on the main task runner. | 42 // work function (DoWork) is scheduled to run on the main task runner. |
44 // | 43 // |
45 // 2. Work queue. If a work queue is empty when DoWork() is entered, tasks from | 44 // 2. Work queue. If a work queue is empty when DoWork() is entered, tasks from |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 // manager. Increasing the batch size can reduce the overhead of yielding | 150 // manager. Increasing the batch size can reduce the overhead of yielding |
152 // back to the main message loop -- at the cost of potentially delaying other | 151 // back to the main message loop -- at the cost of potentially delaying other |
153 // tasks posted to the main loop. The batch size is 1 by default. | 152 // tasks posted to the main loop. The batch size is 1 by default. |
154 void SetWorkBatchSize(int work_batch_size); | 153 void SetWorkBatchSize(int work_batch_size); |
155 | 154 |
156 // These functions can only be called on the same thread that the task queue | 155 // These functions can only be called on the same thread that the task queue |
157 // manager executes its tasks on. | 156 // manager executes its tasks on. |
158 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer); | 157 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer); |
159 void RemoveTaskObserver(base::MessageLoop::TaskObserver* task_observer); | 158 void RemoveTaskObserver(base::MessageLoop::TaskObserver* task_observer); |
160 | 159 |
161 void SetTimeSourceForTesting(scoped_ptr<TimeSource> time_source); | 160 void SetTimeSourceForTesting(scoped_ptr<base::TickClock> time_source); |
162 | 161 |
163 // Returns a bitmap where a bit is set iff a task on the corresponding queue | 162 // Returns a bitmap where a bit is set iff a task on the corresponding queue |
164 // was run since the last call to GetAndClearTaskWasRunOnQueueBitmap. | 163 // was run since the last call to GetAndClearTaskWasRunOnQueueBitmap. |
165 uint64 GetAndClearTaskWasRunOnQueueBitmap(); | 164 uint64 GetAndClearTaskWasRunOnQueueBitmap(); |
166 | 165 |
167 private: | 166 private: |
168 // TaskQueueSelector::Observer implementation: | 167 // TaskQueueSelector::Observer implementation: |
169 void OnTaskQueueEnabled() override; | 168 void OnTaskQueueEnabled() override; |
170 | 169 |
171 friend class internal::LazyNow; | 170 friend class internal::LazyNow; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 base::Closure do_work_from_other_thread_closure_; | 240 base::Closure do_work_from_other_thread_closure_; |
242 | 241 |
243 uint64 task_was_run_bitmap_; | 242 uint64 task_was_run_bitmap_; |
244 | 243 |
245 // The pending_dowork_count_ is only tracked on the main thread since that's | 244 // The pending_dowork_count_ is only tracked on the main thread since that's |
246 // where re-entrant problems happen. | 245 // where re-entrant problems happen. |
247 int pending_dowork_count_; | 246 int pending_dowork_count_; |
248 | 247 |
249 int work_batch_size_; | 248 int work_batch_size_; |
250 | 249 |
251 scoped_ptr<TimeSource> time_source_; | 250 scoped_ptr<base::TickClock> time_source_; |
252 | 251 |
253 base::ObserverList<base::MessageLoop::TaskObserver> task_observers_; | 252 base::ObserverList<base::MessageLoop::TaskObserver> task_observers_; |
254 | 253 |
255 const char* disabled_by_default_tracing_category_; | 254 const char* disabled_by_default_tracing_category_; |
256 | 255 |
257 scoped_refptr<DeletionSentinel> deletion_sentinel_; | 256 scoped_refptr<DeletionSentinel> deletion_sentinel_; |
258 base::WeakPtrFactory<TaskQueueManager> weak_factory_; | 257 base::WeakPtrFactory<TaskQueueManager> weak_factory_; |
259 | 258 |
260 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); | 259 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); |
261 }; | 260 }; |
262 | 261 |
263 } // namespace scheduler | 262 } // namespace scheduler |
264 | 263 |
265 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ | 264 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ |
OLD | NEW |