OLD | NEW |
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 CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ |
6 #define CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ | 6 #define CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/pending_task.h" | 10 #include "base/pending_task.h" |
11 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
13 #include "base/trace_event/trace_event_argument.h" | 13 #include "base/trace_event/trace_event_argument.h" |
14 #include "components/scheduler/base/task_queue.h" | 14 #include "components/scheduler/base/task_queue.h" |
15 #include "components/scheduler/scheduler_export.h" | 15 #include "components/scheduler/scheduler_export.h" |
16 | 16 |
17 namespace scheduler { | 17 namespace scheduler { |
18 class LazyNow; | 18 class LazyNow; |
19 class TimeDomain; | 19 class TimeDomain; |
20 class TaskQueueManager; | 20 class TaskQueueManager; |
21 | 21 |
22 namespace internal { | 22 namespace internal { |
23 class SCHEDULER_EXPORT TaskQueueImpl final : public TaskQueue { | 23 class SCHEDULER_EXPORT TaskQueueImpl final : public TaskQueue { |
24 public: | 24 public: |
25 TaskQueueImpl(TaskQueueManager* task_queue_manager, | 25 TaskQueueImpl(TaskQueueManager* task_queue_manager, |
26 TimeDomain* time_domain, | 26 const scoped_refptr<TimeDomain>& time_domain, |
27 const Spec& spec, | 27 const Spec& spec, |
28 const char* disabled_by_default_tracing_category, | 28 const char* disabled_by_default_tracing_category, |
29 const char* disabled_by_default_verbose_tracing_category); | 29 const char* disabled_by_default_verbose_tracing_category); |
30 | 30 |
31 class SCHEDULER_EXPORT Task : public base::PendingTask { | 31 class SCHEDULER_EXPORT Task : public base::PendingTask { |
32 public: | 32 public: |
33 Task(); | 33 Task(); |
34 Task(const tracked_objects::Location& posted_from, | 34 Task(const tracked_objects::Location& posted_from, |
35 const base::Closure& task, | 35 const base::Closure& task, |
36 int sequence_number, | 36 int sequence_number, |
(...skipping 26 matching lines...) Expand all Loading... |
63 | 63 |
64 // TaskQueue implementation. | 64 // TaskQueue implementation. |
65 void UnregisterTaskQueue() override; | 65 void UnregisterTaskQueue() override; |
66 bool RunsTasksOnCurrentThread() const override; | 66 bool RunsTasksOnCurrentThread() const override; |
67 bool PostDelayedTask(const tracked_objects::Location& from_here, | 67 bool PostDelayedTask(const tracked_objects::Location& from_here, |
68 const base::Closure& task, | 68 const base::Closure& task, |
69 base::TimeDelta delay) override; | 69 base::TimeDelta delay) override; |
70 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, | 70 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, |
71 const base::Closure& task, | 71 const base::Closure& task, |
72 base::TimeDelta delay) override; | 72 base::TimeDelta delay) override; |
| 73 bool PostDelayedTaskAt(const tracked_objects::Location& from_here, |
| 74 const base::Closure& task, |
| 75 base::TimeTicks desired_run_time) override; |
73 | 76 |
74 bool IsQueueEnabled() const override; | 77 bool IsQueueEnabled() const override; |
75 QueueState GetQueueState() const override; | 78 QueueState GetQueueState() const override; |
76 void SetQueuePriority(QueuePriority priority) override; | 79 void SetQueuePriority(QueuePriority priority) override; |
77 void PumpQueue() override; | 80 void PumpQueue() override; |
78 void SetPumpPolicy(PumpPolicy pump_policy) override; | 81 void SetPumpPolicy(PumpPolicy pump_policy) override; |
79 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override; | 82 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override; |
80 void RemoveTaskObserver( | 83 void RemoveTaskObserver( |
81 base::MessageLoop::TaskObserver* task_observer) override; | 84 base::MessageLoop::TaskObserver* task_observer) override; |
82 void SetTimeDomain(TimeDomain* time_domain) override; | 85 void SetTimeDomain(const scoped_refptr<TimeDomain>& time_domain) override; |
83 | 86 |
84 void UpdateWorkQueue(LazyNow* lazy_now, | 87 void UpdateWorkQueue(LazyNow* lazy_now, |
85 bool should_trigger_wakeup, | 88 bool should_trigger_wakeup, |
86 const Task* previous_task); | 89 const Task* previous_task); |
87 Task TakeTaskFromWorkQueue(); | 90 Task TakeTaskFromWorkQueue(); |
88 | 91 |
89 std::queue<Task>& work_queue() { return main_thread_only().work_queue; } | 92 std::queue<Task>& work_queue() { return main_thread_only().work_queue; } |
90 | 93 |
91 WakeupPolicy wakeup_policy() const { | 94 WakeupPolicy wakeup_policy() const { |
92 DCHECK(main_thread_checker_.CalledOnValidThread()); | 95 DCHECK(main_thread_checker_.CalledOnValidThread()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 147 |
145 private: | 148 private: |
146 enum class TaskType { | 149 enum class TaskType { |
147 NORMAL, | 150 NORMAL, |
148 NON_NESTABLE, | 151 NON_NESTABLE, |
149 }; | 152 }; |
150 | 153 |
151 struct AnyThread { | 154 struct AnyThread { |
152 AnyThread(TaskQueueManager* task_queue_manager, | 155 AnyThread(TaskQueueManager* task_queue_manager, |
153 PumpPolicy pump_policy, | 156 PumpPolicy pump_policy, |
154 TimeDomain* time_domain); | 157 const scoped_refptr<TimeDomain>& time_domain); |
155 ~AnyThread(); | 158 ~AnyThread(); |
156 | 159 |
157 // TaskQueueManager is maintained in two copies: inside AnyThread and inside | 160 // TaskQueueManager is maintained in two copies: inside AnyThread and inside |
158 // MainThreadOnly. It can be changed only from main thread, so it should be | 161 // MainThreadOnly. It can be changed only from main thread, so it should be |
159 // locked before accessing from other threads. | 162 // locked before accessing from other threads. |
160 TaskQueueManager* task_queue_manager; | 163 TaskQueueManager* task_queue_manager; |
161 | 164 |
162 std::queue<Task> incoming_queue; | 165 std::queue<Task> incoming_queue; |
163 PumpPolicy pump_policy; | 166 PumpPolicy pump_policy; |
164 std::priority_queue<Task> delayed_task_queue; | 167 std::priority_queue<Task> delayed_task_queue; |
165 TimeDomain* time_domain; | 168 scoped_refptr<TimeDomain> time_domain; |
166 }; | 169 }; |
167 | 170 |
168 struct MainThreadOnly { | 171 struct MainThreadOnly { |
169 MainThreadOnly(TaskQueueManager* task_queue_manager); | 172 MainThreadOnly(TaskQueueManager* task_queue_manager); |
170 ~MainThreadOnly(); | 173 ~MainThreadOnly(); |
171 | 174 |
172 // Another copy of TaskQueueManager for lock-free access from the main | 175 // Another copy of TaskQueueManager for lock-free access from the main |
173 // thread. See description inside struct AnyThread for details. | 176 // thread. See description inside struct AnyThread for details. |
174 TaskQueueManager* task_queue_manager; | 177 TaskQueueManager* task_queue_manager; |
175 | 178 |
176 std::queue<Task> work_queue; | 179 std::queue<Task> work_queue; |
177 base::ObserverList<base::MessageLoop::TaskObserver> task_observers; | 180 base::ObserverList<base::MessageLoop::TaskObserver> task_observers; |
178 size_t set_index; | 181 size_t set_index; |
179 }; | 182 }; |
180 | 183 |
181 ~TaskQueueImpl() override; | 184 ~TaskQueueImpl() override; |
182 | 185 |
183 bool PostDelayedTaskImpl(const tracked_objects::Location& from_here, | 186 bool PostDelayedTaskImpl(const tracked_objects::Location& from_here, |
184 const base::Closure& task, | 187 const base::Closure& task, |
185 base::TimeDelta delay, | 188 base::TimeDelta delay, |
186 TaskType task_type); | 189 TaskType task_type); |
187 bool PostDelayedTaskLocked(LazyNow* lazy_now, | 190 bool PostDelayedTaskLocked(LazyNow* lazy_now, |
188 const tracked_objects::Location& from_here, | 191 const tracked_objects::Location& from_here, |
189 const base::Closure& task, | 192 const base::Closure& task, |
190 base::TimeTicks desired_run_time, | 193 base::TimeTicks desired_run_time, |
191 TaskType task_type); | 194 TaskType task_type); |
192 void ScheduleDelayedWorkTask(TimeDomain* time_domain, | 195 void ScheduleDelayedWorkTask(const scoped_refptr<TimeDomain> time_domain, |
193 base::TimeTicks desired_run_time); | 196 base::TimeTicks desired_run_time); |
194 | 197 |
195 // Enqueues any delayed tasks which should be run now on the incoming_queue_. | 198 // Enqueues any delayed tasks which should be run now on the incoming_queue_. |
196 // Must be called with |any_thread_lock_| locked. | 199 // Must be called with |any_thread_lock_| locked. |
197 void MoveReadyDelayedTasksToIncomingQueueLocked(LazyNow* lazy_now); | 200 void MoveReadyDelayedTasksToIncomingQueueLocked(LazyNow* lazy_now); |
198 | 201 |
199 void PumpQueueLocked(); | 202 void PumpQueueLocked(); |
200 bool TaskIsOlderThanQueuedTasks(const Task* task); | 203 bool TaskIsOlderThanQueuedTasks(const Task* task); |
201 bool ShouldAutoPumpQueueLocked(bool should_trigger_wakeup, | 204 bool ShouldAutoPumpQueueLocked(bool should_trigger_wakeup, |
202 const Task* previous_task); | 205 const Task* previous_task); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 const bool should_monitor_quiescence_; | 253 const bool should_monitor_quiescence_; |
251 const bool should_notify_observers_; | 254 const bool should_notify_observers_; |
252 | 255 |
253 DISALLOW_COPY_AND_ASSIGN(TaskQueueImpl); | 256 DISALLOW_COPY_AND_ASSIGN(TaskQueueImpl); |
254 }; | 257 }; |
255 | 258 |
256 } // namespace internal | 259 } // namespace internal |
257 } // namespace scheduler | 260 } // namespace scheduler |
258 | 261 |
259 #endif // CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ | 262 #endif // CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ |
OLD | NEW |