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 THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ | 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ |
6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ | 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <set> | 11 #include <set> |
12 | 12 |
| 13 #include "base/callback.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/pending_task.h" | 15 #include "base/pending_task.h" |
15 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
16 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
17 #include "base/trace_event/trace_event_argument.h" | 18 #include "base/trace_event/trace_event_argument.h" |
18 #include "platform/scheduler/base/enqueue_order.h" | 19 #include "platform/scheduler/base/enqueue_order.h" |
19 #include "platform/scheduler/base/intrusive_heap.h" | 20 #include "platform/scheduler/base/intrusive_heap.h" |
20 #include "public/platform/scheduler/base/task_queue.h" | 21 #include "public/platform/scheduler/base/task_queue.h" |
21 #include "wtf/Deque.h" | 22 #include "wtf/Deque.h" |
22 | 23 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 TaskQueueImpl(TaskQueueManager* task_queue_manager, | 62 TaskQueueImpl(TaskQueueManager* task_queue_manager, |
62 TimeDomain* time_domain, | 63 TimeDomain* time_domain, |
63 const Spec& spec, | 64 const Spec& spec, |
64 const char* disabled_by_default_tracing_category, | 65 const char* disabled_by_default_tracing_category, |
65 const char* disabled_by_default_verbose_tracing_category); | 66 const char* disabled_by_default_verbose_tracing_category); |
66 | 67 |
67 class BLINK_PLATFORM_EXPORT Task : public base::PendingTask { | 68 class BLINK_PLATFORM_EXPORT Task : public base::PendingTask { |
68 public: | 69 public: |
69 Task(); | 70 Task(); |
70 Task(const tracked_objects::Location& posted_from, | 71 Task(const tracked_objects::Location& posted_from, |
71 const base::Closure& task, | 72 base::Closure task, |
72 base::TimeTicks desired_run_time, | 73 base::TimeTicks desired_run_time, |
73 EnqueueOrder sequence_number, | 74 EnqueueOrder sequence_number, |
74 bool nestable); | 75 bool nestable); |
75 | 76 |
76 Task(const tracked_objects::Location& posted_from, | 77 Task(const tracked_objects::Location& posted_from, |
77 const base::Closure& task, | 78 base::Closure task, |
78 base::TimeTicks desired_run_time, | 79 base::TimeTicks desired_run_time, |
79 EnqueueOrder sequence_number, | 80 EnqueueOrder sequence_number, |
80 bool nestable, | 81 bool nestable, |
81 EnqueueOrder enqueue_order); | 82 EnqueueOrder enqueue_order); |
82 | 83 |
83 EnqueueOrder enqueue_order() const { | 84 EnqueueOrder enqueue_order() const { |
84 #ifndef NDEBUG | 85 #ifndef NDEBUG |
85 DCHECK(enqueue_order_set_); | 86 DCHECK(enqueue_order_set_); |
86 #endif | 87 #endif |
87 return enqueue_order_; | 88 return enqueue_order_; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 return (sequence_num - other.sequence_num) < 0; | 124 return (sequence_num - other.sequence_num) < 0; |
124 } | 125 } |
125 return time < other.time; | 126 return time < other.time; |
126 } | 127 } |
127 }; | 128 }; |
128 | 129 |
129 // TaskQueue implementation. | 130 // TaskQueue implementation. |
130 void UnregisterTaskQueue() override; | 131 void UnregisterTaskQueue() override; |
131 bool RunsTasksOnCurrentThread() const override; | 132 bool RunsTasksOnCurrentThread() const override; |
132 bool PostDelayedTask(const tracked_objects::Location& from_here, | 133 bool PostDelayedTask(const tracked_objects::Location& from_here, |
133 const base::Closure& task, | 134 base::Closure task, |
134 base::TimeDelta delay) override; | 135 base::TimeDelta delay) override; |
135 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, | 136 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, |
136 const base::Closure& task, | 137 base::Closure task, |
137 base::TimeDelta delay) override; | 138 base::TimeDelta delay) override; |
138 std::unique_ptr<QueueEnabledVoter> CreateQueueEnabledVoter() override; | 139 std::unique_ptr<QueueEnabledVoter> CreateQueueEnabledVoter() override; |
139 bool IsQueueEnabled() const override; | 140 bool IsQueueEnabled() const override; |
140 bool IsEmpty() const override; | 141 bool IsEmpty() const override; |
141 size_t GetNumberOfPendingTasks() const override; | 142 size_t GetNumberOfPendingTasks() const override; |
142 bool HasPendingImmediateWork() const override; | 143 bool HasPendingImmediateWork() const override; |
143 base::Optional<base::TimeTicks> GetNextScheduledWakeUp() override; | 144 base::Optional<base::TimeTicks> GetNextScheduledWakeUp() override; |
144 void SetQueuePriority(QueuePriority priority) override; | 145 void SetQueuePriority(QueuePriority priority) override; |
145 QueuePriority GetQueuePriority() const override; | 146 QueuePriority GetQueuePriority() const override; |
146 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override; | 147 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 int is_enabled_refcount; | 278 int is_enabled_refcount; |
278 int voter_refcount; | 279 int voter_refcount; |
279 base::trace_event::BlameContext* blame_context; // Not owned. | 280 base::trace_event::BlameContext* blame_context; // Not owned. |
280 EnqueueOrder current_fence; | 281 EnqueueOrder current_fence; |
281 base::TimeTicks scheduled_time_domain_wakeup; | 282 base::TimeTicks scheduled_time_domain_wakeup; |
282 }; | 283 }; |
283 | 284 |
284 ~TaskQueueImpl() override; | 285 ~TaskQueueImpl() override; |
285 | 286 |
286 bool PostImmediateTaskImpl(const tracked_objects::Location& from_here, | 287 bool PostImmediateTaskImpl(const tracked_objects::Location& from_here, |
287 const base::Closure& task, | 288 base::Closure task, |
288 TaskType task_type); | 289 TaskType task_type); |
289 bool PostDelayedTaskImpl(const tracked_objects::Location& from_here, | 290 bool PostDelayedTaskImpl(const tracked_objects::Location& from_here, |
290 const base::Closure& task, | 291 base::Closure task, |
291 base::TimeDelta delay, | 292 base::TimeDelta delay, |
292 TaskType task_type); | 293 TaskType task_type); |
293 | 294 |
294 // Push the task onto the |delayed_incoming_queue|. Lock-free main thread | 295 // Push the task onto the |delayed_incoming_queue|. Lock-free main thread |
295 // only fast path. | 296 // only fast path. |
296 void PushOntoDelayedIncomingQueueFromMainThread(Task pending_task, | 297 void PushOntoDelayedIncomingQueueFromMainThread(Task pending_task, |
297 base::TimeTicks now); | 298 base::TimeTicks now); |
298 | 299 |
299 // Push the task onto the |delayed_incoming_queue|. Slow path from other | 300 // Push the task onto the |delayed_incoming_queue|. Slow path from other |
300 // threads. | 301 // threads. |
301 void PushOntoDelayedIncomingQueueLocked(Task pending_task); | 302 void PushOntoDelayedIncomingQueueLocked(Task pending_task); |
302 | 303 |
303 void ScheduleDelayedWorkTask(Task pending_task); | 304 void ScheduleDelayedWorkTask(Task pending_task); |
304 | 305 |
305 void MoveReadyImmediateTasksToImmediateWorkQueueLocked(); | 306 void MoveReadyImmediateTasksToImmediateWorkQueueLocked(); |
306 | 307 |
307 // Push the task onto the |immediate_incoming_queue| and for auto pumped | 308 // Push the task onto the |immediate_incoming_queue| and for auto pumped |
308 // queues it calls MaybePostDoWorkOnMainRunner if the Incoming queue was | 309 // queues it calls MaybePostDoWorkOnMainRunner if the Incoming queue was |
309 // empty. | 310 // empty. |
310 void PushOntoImmediateIncomingQueueLocked( | 311 void PushOntoImmediateIncomingQueueLocked( |
311 const tracked_objects::Location& posted_from, | 312 const tracked_objects::Location& posted_from, |
312 const base::Closure& task, | 313 base::Closure task, |
313 base::TimeTicks desired_run_time, | 314 base::TimeTicks desired_run_time, |
314 EnqueueOrder sequence_number, | 315 EnqueueOrder sequence_number, |
315 bool nestable); | 316 bool nestable); |
316 | 317 |
317 // Extracts all the tasks from the immediate incoming queue and clears it. | 318 // Extracts all the tasks from the immediate incoming queue and clears it. |
318 // Can be called from any thread. | 319 // Can be called from any thread. |
319 WTF::Deque<TaskQueueImpl::Task> TakeImmediateIncomingQueue(); | 320 WTF::Deque<TaskQueueImpl::Task> TakeImmediateIncomingQueue(); |
320 | 321 |
321 void TraceQueueSize(bool is_locked) const; | 322 void TraceQueueSize(bool is_locked) const; |
322 static void QueueAsValueInto(const WTF::Deque<Task>& queue, | 323 static void QueueAsValueInto(const WTF::Deque<Task>& queue, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 const bool should_report_when_execution_blocked_; | 365 const bool should_report_when_execution_blocked_; |
365 | 366 |
366 DISALLOW_COPY_AND_ASSIGN(TaskQueueImpl); | 367 DISALLOW_COPY_AND_ASSIGN(TaskQueueImpl); |
367 }; | 368 }; |
368 | 369 |
369 } // namespace internal | 370 } // namespace internal |
370 } // namespace scheduler | 371 } // namespace scheduler |
371 } // namespace blink | 372 } // namespace blink |
372 | 373 |
373 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ | 374 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ |
OLD | NEW |