Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Side by Side Diff: third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.h

Issue 2786083005: scheduler: Maintain a constant enqueue order for every task (Closed)
Patch Set: Update VirtualTimeTest Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 // delayed_work_queue 42 // delayed_work_queue
43 // 43 //
44 // The immediate_incoming_queue can be accessed from any thread, the other 44 // The immediate_incoming_queue can be accessed from any thread, the other
45 // queues are main-thread only. To reduce the overhead of locking, 45 // queues are main-thread only. To reduce the overhead of locking,
46 // immediate_work_queue is swapped with immediate_incoming_queue when 46 // immediate_work_queue is swapped with immediate_incoming_queue when
47 // immediate_work_queue becomes empty. 47 // immediate_work_queue becomes empty.
48 // 48 //
49 // Delayed tasks are initially posted to delayed_incoming_queue and a wake-up 49 // Delayed tasks are initially posted to delayed_incoming_queue and a wake-up
50 // is scheduled with the TimeDomain. When the delay has elapsed, the TimeDomain 50 // is scheduled with the TimeDomain. When the delay has elapsed, the TimeDomain
51 // calls UpdateDelayedWorkQueue and ready delayed tasks are moved into the 51 // calls UpdateDelayedWorkQueue and ready delayed tasks are moved into the
52 // delayed_work_queue. Note the EnqueueOrder (used for ordering) for a delayed 52 // delayed_work_queue.
53 // task is not set until it's moved into the delayed_work_queue.
54 // 53 //
55 // TaskQueueImpl uses the WorkQueueSets and the TaskQueueSelector to implement 54 // TaskQueueImpl uses the WorkQueueSets and the TaskQueueSelector to implement
56 // prioritization. Task selection is done by the TaskQueueSelector and when a 55 // prioritization. Task selection is done by the TaskQueueSelector and when a
57 // queue is selected, it round-robins between the immediate_work_queue and 56 // queue is selected, it round-robins between the immediate_work_queue and
58 // delayed_work_queue. The reason for this is we want to make sure delayed 57 // delayed_work_queue. The reason for this is we want to make sure delayed
59 // tasks (normally the most common type) don't starve out immediate work. 58 // tasks (normally the most common type) don't starve out immediate work.
60 class BLINK_PLATFORM_EXPORT TaskQueueImpl final : public TaskQueue { 59 class BLINK_PLATFORM_EXPORT TaskQueueImpl final : public TaskQueue {
61 public: 60 public:
62 TaskQueueImpl(TaskQueueManager* task_queue_manager, 61 TaskQueueImpl(TaskQueueManager* task_queue_manager,
63 TimeDomain* time_domain, 62 TimeDomain* time_domain,
(...skipping 14 matching lines...) Expand all
78 } 77 }
79 return time < other.time; 78 return time < other.time;
80 } 79 }
81 }; 80 };
82 81
83 class BLINK_PLATFORM_EXPORT Task : public base::PendingTask { 82 class BLINK_PLATFORM_EXPORT Task : public base::PendingTask {
84 public: 83 public:
85 Task(); 84 Task();
86 Task(const tracked_objects::Location& posted_from, 85 Task(const tracked_objects::Location& posted_from,
87 base::OnceClosure task, 86 base::OnceClosure task,
88 base::TimeTicks desired_run_time, 87 EnqueueOrder enqueue_order,
89 EnqueueOrder sequence_number,
90 bool nestable); 88 bool nestable);
91 89
92 Task(const tracked_objects::Location& posted_from, 90 Task(const tracked_objects::Location& posted_from,
93 base::OnceClosure task, 91 base::OnceClosure task,
94 base::TimeTicks desired_run_time, 92 base::TimeTicks desired_run_time,
95 EnqueueOrder sequence_number, 93 EnqueueOrder sequence_number,
96 bool nestable, 94 bool nestable,
97 EnqueueOrder enqueue_order); 95 EnqueueOrder enqueue_order);
98 96
99 DelayedWakeUp delayed_wake_up() const { 97 DelayedWakeUp delayed_wake_up() const {
100 return DelayedWakeUp{delayed_run_time, sequence_num}; 98 return DelayedWakeUp{delayed_run_time, sequence_num};
101 } 99 }
102 100
103 EnqueueOrder enqueue_order() const { 101 EnqueueOrder enqueue_order() const {
104 #ifndef NDEBUG
105 DCHECK(enqueue_order_set_);
106 #endif
107 return enqueue_order_; 102 return enqueue_order_;
108 } 103 }
109 104
110 void set_enqueue_order(EnqueueOrder enqueue_order) {
111 #ifndef NDEBUG
112 DCHECK(!enqueue_order_set_);
113 enqueue_order_set_ = true;
114 #endif
115 enqueue_order_ = enqueue_order;
116 }
117
118 #ifndef NDEBUG
119 bool enqueue_order_set() const { return enqueue_order_set_; }
120 #endif
121
122 private: 105 private:
123 #ifndef NDEBUG
124 bool enqueue_order_set_;
125 #endif
126 // Similar to sequence number, but ultimately the |enqueue_order_| is what 106 // Similar to sequence number, but ultimately the |enqueue_order_| is what
127 // the scheduler uses for task ordering. For immediate tasks |enqueue_order| 107 // the scheduler uses for task ordering. For immediate tasks |enqueue_order|
128 // is set when posted, but for delayed tasks it's not defined until they are 108 // is set when posted, but for delayed tasks it's not defined until they are
129 // enqueued on the |delayed_work_queue_|. This is because otherwise delayed 109 // enqueued on the |delayed_work_queue_|. This is because otherwise delayed
130 // tasks could run before an immediate task posted after the delayed task. 110 // tasks could run before an immediate task posted after the delayed task.
131 EnqueueOrder enqueue_order_; 111 EnqueueOrder enqueue_order_;
132 }; 112 };
133 113
134 // TaskQueue implementation. 114 // TaskQueue implementation.
135 void UnregisterTaskQueue() override; 115 void UnregisterTaskQueue() override;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 scheduled_time_domain_wake_up; 192 scheduled_time_domain_wake_up;
213 } 193 }
214 194
215 HeapHandle heap_handle() const { return main_thread_only().heap_handle; } 195 HeapHandle heap_handle() const { return main_thread_only().heap_handle; }
216 196
217 void set_heap_handle(HeapHandle heap_handle) { 197 void set_heap_handle(HeapHandle heap_handle) {
218 main_thread_only().heap_handle = heap_handle; 198 main_thread_only().heap_handle = heap_handle;
219 } 199 }
220 200
221 void PushImmediateIncomingTaskForTest(TaskQueueImpl::Task&& task); 201 void PushImmediateIncomingTaskForTest(TaskQueueImpl::Task&& task);
222 EnqueueOrder GetFenceForTest() const; 202 uint64_t GetFenceForTest() const;
223 203
224 class QueueEnabledVoterImpl : public QueueEnabledVoter { 204 class QueueEnabledVoterImpl : public QueueEnabledVoter {
225 public: 205 public:
226 explicit QueueEnabledVoterImpl(TaskQueueImpl* task_queue); 206 explicit QueueEnabledVoterImpl(TaskQueueImpl* task_queue);
227 ~QueueEnabledVoterImpl() override; 207 ~QueueEnabledVoterImpl() override;
228 208
229 // QueueEnabledVoter implementation. 209 // QueueEnabledVoter implementation.
230 void SetQueueEnabled(bool enabled) override; 210 void SetQueueEnabled(bool enabled) override;
231 211
232 TaskQueueImpl* GetTaskQueueForTest() const { return task_queue_.get(); } 212 TaskQueueImpl* GetTaskQueueForTest() const { return task_queue_.get(); }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 257
278 std::unique_ptr<WorkQueue> delayed_work_queue; 258 std::unique_ptr<WorkQueue> delayed_work_queue;
279 std::unique_ptr<WorkQueue> immediate_work_queue; 259 std::unique_ptr<WorkQueue> immediate_work_queue;
280 std::priority_queue<Task> delayed_incoming_queue; 260 std::priority_queue<Task> delayed_incoming_queue;
281 base::ObserverList<base::MessageLoop::TaskObserver> task_observers; 261 base::ObserverList<base::MessageLoop::TaskObserver> task_observers;
282 size_t set_index; 262 size_t set_index;
283 HeapHandle heap_handle; 263 HeapHandle heap_handle;
284 int is_enabled_refcount; 264 int is_enabled_refcount;
285 int voter_refcount; 265 int voter_refcount;
286 base::trace_event::BlameContext* blame_context; // Not owned. 266 base::trace_event::BlameContext* blame_context; // Not owned.
287 EnqueueOrder current_fence; 267 uint64_t current_fence;
288 base::TimeTicks scheduled_time_domain_wake_up; 268 base::TimeTicks scheduled_time_domain_wake_up;
289 }; 269 };
290 270
291 ~TaskQueueImpl() override; 271 ~TaskQueueImpl() override;
292 272
293 bool PostImmediateTaskImpl(const tracked_objects::Location& from_here, 273 bool PostImmediateTaskImpl(const tracked_objects::Location& from_here,
294 base::OnceClosure task, 274 base::OnceClosure task,
295 TaskType task_type); 275 TaskType task_type);
296 bool PostDelayedTaskImpl(const tracked_objects::Location& from_here, 276 bool PostDelayedTaskImpl(const tracked_objects::Location& from_here,
297 base::OnceClosure task, 277 base::OnceClosure task,
(...skipping 12 matching lines...) Expand all
310 void ScheduleDelayedWorkTask(Task pending_task); 290 void ScheduleDelayedWorkTask(Task pending_task);
311 291
312 void MoveReadyImmediateTasksToImmediateWorkQueueLocked(); 292 void MoveReadyImmediateTasksToImmediateWorkQueueLocked();
313 293
314 // Push the task onto the |immediate_incoming_queue| and for auto pumped 294 // Push the task onto the |immediate_incoming_queue| and for auto pumped
315 // queues it calls MaybePostDoWorkOnMainRunner if the Incoming queue was 295 // queues it calls MaybePostDoWorkOnMainRunner if the Incoming queue was
316 // empty. 296 // empty.
317 void PushOntoImmediateIncomingQueueLocked( 297 void PushOntoImmediateIncomingQueueLocked(
318 const tracked_objects::Location& posted_from, 298 const tracked_objects::Location& posted_from,
319 base::OnceClosure task, 299 base::OnceClosure task,
320 base::TimeTicks desired_run_time, 300 EnqueueOrder enqueue_order,
321 EnqueueOrder sequence_number,
322 bool nestable); 301 bool nestable);
323 302
324 // Extracts all the tasks from the immediate incoming queue and clears it. 303 // Extracts all the tasks from the immediate incoming queue and clears it.
325 // Can be called from any thread. 304 // Can be called from any thread.
326 WTF::Deque<TaskQueueImpl::Task> TakeImmediateIncomingQueue(); 305 WTF::Deque<TaskQueueImpl::Task> TakeImmediateIncomingQueue();
327 306
328 void TraceQueueSize() const; 307 void TraceQueueSize() const;
329 static void QueueAsValueInto(const WTF::Deque<Task>& queue, 308 static void QueueAsValueInto(const WTF::Deque<Task>& queue,
330 base::trace_event::TracedValue* state); 309 base::trace_event::TracedValue* state);
331 static void QueueAsValueInto(const std::priority_queue<Task>& queue, 310 static void QueueAsValueInto(const std::priority_queue<Task>& queue,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 const bool should_report_when_execution_blocked_; 366 const bool should_report_when_execution_blocked_;
388 367
389 DISALLOW_COPY_AND_ASSIGN(TaskQueueImpl); 368 DISALLOW_COPY_AND_ASSIGN(TaskQueueImpl);
390 }; 369 };
391 370
392 } // namespace internal 371 } // namespace internal
393 } // namespace scheduler 372 } // namespace scheduler
394 } // namespace blink 373 } // namespace blink
395 374
396 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ 375 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698