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

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

Issue 2546423002: [Try # 3] Scheduler refactoring to virtually eliminate redundant DoWorks (Closed)
Patch Set: Add an extra dcheck Created 3 years, 11 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 base::MessageLoop::TaskObserver* task_observer) override; 133 base::MessageLoop::TaskObserver* task_observer) override;
134 void SetTimeDomain(TimeDomain* time_domain) override; 134 void SetTimeDomain(TimeDomain* time_domain) override;
135 TimeDomain* GetTimeDomain() const override; 135 TimeDomain* GetTimeDomain() const override;
136 void SetBlameContext(base::trace_event::BlameContext* blame_context) override; 136 void SetBlameContext(base::trace_event::BlameContext* blame_context) override;
137 void InsertFence(InsertFencePosition position) override; 137 void InsertFence(InsertFencePosition position) override;
138 void RemoveFence() override; 138 void RemoveFence() override;
139 bool BlockedByFence() const override; 139 bool BlockedByFence() const override;
140 const char* GetName() const override; 140 const char* GetName() const override;
141 QueueType GetQueueType() const override; 141 QueueType GetQueueType() const override;
142 142
143 // If this returns false then future updates for this queue are not needed 143 // Returns true if a posted immediate task could run (i.e. the queue is
144 // unless requested. 144 // enabled and not blocked by a fence). Must only be called from the thread
145 bool MaybeUpdateImmediateWorkQueues(); 145 // this task queue was created on
146 bool ImmediateTaskCouldRun() const;
147
148 // Returns the current queue of immediate incoming tasks.
149 WTF::Deque<TaskQueueImpl::Task> TakeImmediateIncomingQueue();
150
151 // Must only be called from the thread this task queue was created on.
152 void ReloadImmediateWorkQueueIfEmpty();
146 153
147 void AsValueInto(base::trace_event::TracedValue* state) const; 154 void AsValueInto(base::trace_event::TracedValue* state) const;
148 155
149 bool GetQuiescenceMonitored() const { return should_monitor_quiescence_; } 156 bool GetQuiescenceMonitored() const { return should_monitor_quiescence_; }
150 bool GetShouldNotifyObservers() const { return should_notify_observers_; } 157 bool GetShouldNotifyObservers() const { return should_notify_observers_; }
151 158
152 void NotifyWillProcessTask(const base::PendingTask& pending_task); 159 void NotifyWillProcessTask(const base::PendingTask& pending_task);
153 void NotifyDidProcessTask(const base::PendingTask& pending_task); 160 void NotifyDidProcessTask(const base::PendingTask& pending_task);
154 161
155 WorkQueue* delayed_work_queue() { 162 WorkQueue* delayed_work_queue() {
(...skipping 10 matching lines...) Expand all
166 173
167 const WorkQueue* immediate_work_queue() const { 174 const WorkQueue* immediate_work_queue() const {
168 return main_thread_only().immediate_work_queue.get(); 175 return main_thread_only().immediate_work_queue.get();
169 } 176 }
170 177
171 bool should_report_when_execution_blocked() const { 178 bool should_report_when_execution_blocked() const {
172 return should_report_when_execution_blocked_; 179 return should_report_when_execution_blocked_;
173 } 180 }
174 181
175 // Enqueues any delayed tasks which should be run now on the 182 // Enqueues any delayed tasks which should be run now on the
176 // |delayed_work_queue|. It also schedules the next wake up with the 183 // |delayed_work_queue|. Returns the deadline if a subsequent wakeup is
177 // TimeDomain. Must be called from the main thread. 184 // required. Must be called from the main thread.
178 void WakeUpForDelayedWork(LazyNow* lazy_now); 185 base::Optional<base::TimeTicks> WakeUpForDelayedWork(LazyNow* lazy_now);
179 186
180 base::TimeTicks scheduled_time_domain_wakeup() const { 187 base::TimeTicks scheduled_time_domain_wakeup() const {
181 return main_thread_only().scheduled_time_domain_wakeup; 188 return main_thread_only().scheduled_time_domain_wakeup;
182 } 189 }
183 190
184 void set_scheduled_time_domain_wakeup( 191 void set_scheduled_time_domain_wakeup(
185 base::TimeTicks scheduled_time_domain_wakeup) { 192 base::TimeTicks scheduled_time_domain_wakeup) {
186 main_thread_only().scheduled_time_domain_wakeup = 193 main_thread_only().scheduled_time_domain_wakeup =
187 scheduled_time_domain_wakeup; 194 scheduled_time_domain_wakeup;
188 } 195 }
189 196
190 HeapHandle heap_handle() const { return main_thread_only().heap_handle; } 197 HeapHandle heap_handle() const { return main_thread_only().heap_handle; }
191 198
192 void set_heap_handle(HeapHandle heap_handle) { 199 void set_heap_handle(HeapHandle heap_handle) {
193 main_thread_only().heap_handle = heap_handle; 200 main_thread_only().heap_handle = heap_handle;
194 } 201 }
195 202
203 void PushImmediateIncomingTaskForTest(TaskQueueImpl::Task&& task);
196 EnqueueOrder GetFenceForTest() const; 204 EnqueueOrder GetFenceForTest() const;
197 205
198 class QueueEnabledVoterImpl : public QueueEnabledVoter { 206 class QueueEnabledVoterImpl : public QueueEnabledVoter {
199 public: 207 public:
200 explicit QueueEnabledVoterImpl(TaskQueueImpl* task_queue); 208 explicit QueueEnabledVoterImpl(TaskQueueImpl* task_queue);
201 ~QueueEnabledVoterImpl() override; 209 ~QueueEnabledVoterImpl() override;
202 210
203 // QueueEnabledVoter implementation. 211 // QueueEnabledVoter implementation.
204 void SetQueueEnabled(bool enabled) override; 212 void SetQueueEnabled(bool enabled) override;
205 213
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // Push the task onto the |immediate_incoming_queue| and for auto pumped 295 // Push the task onto the |immediate_incoming_queue| and for auto pumped
288 // queues it calls MaybePostDoWorkOnMainRunner if the Incoming queue was 296 // queues it calls MaybePostDoWorkOnMainRunner if the Incoming queue was
289 // empty. 297 // empty.
290 void PushOntoImmediateIncomingQueueLocked( 298 void PushOntoImmediateIncomingQueueLocked(
291 const tracked_objects::Location& posted_from, 299 const tracked_objects::Location& posted_from,
292 const base::Closure& task, 300 const base::Closure& task,
293 base::TimeTicks desired_run_time, 301 base::TimeTicks desired_run_time,
294 EnqueueOrder sequence_number, 302 EnqueueOrder sequence_number,
295 bool nestable); 303 bool nestable);
296 304
297 // As BlockedByFence but safe to be called while locked.
298 bool BlockedByFenceLocked() const;
299
300 void TraceQueueSize(bool is_locked) const; 305 void TraceQueueSize(bool is_locked) const;
301 static void QueueAsValueInto(const WTF::Deque<Task>& queue, 306 static void QueueAsValueInto(const WTF::Deque<Task>& queue,
302 base::trace_event::TracedValue* state); 307 base::trace_event::TracedValue* state);
303 static void QueueAsValueInto(const std::priority_queue<Task>& queue, 308 static void QueueAsValueInto(const std::priority_queue<Task>& queue,
304 base::trace_event::TracedValue* state); 309 base::trace_event::TracedValue* state);
305 static void TaskAsValueInto(const Task& task, 310 static void TaskAsValueInto(const Task& task,
306 base::trace_event::TracedValue* state); 311 base::trace_event::TracedValue* state);
307 312
308 void RemoveQueueEnabledVoter(const QueueEnabledVoterImpl* voter); 313 void RemoveQueueEnabledVoter(const QueueEnabledVoterImpl* voter);
309 void OnQueueEnabledVoteChanged(bool enabled); 314 void OnQueueEnabledVoteChanged(bool enabled);
310 void EnableOrDisableWithSelector(bool enable); 315 void EnableOrDisableWithSelector(bool enable);
311 316
312 const base::PlatformThreadId thread_id_; 317 const base::PlatformThreadId thread_id_;
313 318
314 mutable base::Lock any_thread_lock_; 319 mutable base::Lock any_thread_lock_;
315 AnyThread any_thread_; 320 AnyThread any_thread_;
316 struct AnyThread& any_thread() { 321 struct AnyThread& any_thread() {
317 any_thread_lock_.AssertAcquired(); 322 any_thread_lock_.AssertAcquired();
318 return any_thread_; 323 return any_thread_;
319 } 324 }
320 const struct AnyThread& any_thread() const { 325 const struct AnyThread& any_thread() const {
321 any_thread_lock_.AssertAcquired(); 326 any_thread_lock_.AssertAcquired();
322 return any_thread_; 327 return any_thread_;
323 } 328 }
324 329
325 const QueueType type_; 330 const QueueType type_;
326 const char* name_; 331 const char* const name_;
327 const char* disabled_by_default_tracing_category_; 332 const char* const disabled_by_default_tracing_category_;
328 const char* disabled_by_default_verbose_tracing_category_; 333 const char* const disabled_by_default_verbose_tracing_category_;
329 334
330 base::ThreadChecker main_thread_checker_; 335 base::ThreadChecker main_thread_checker_;
331 MainThreadOnly main_thread_only_; 336 MainThreadOnly main_thread_only_;
332 MainThreadOnly& main_thread_only() { 337 MainThreadOnly& main_thread_only() {
333 DCHECK(main_thread_checker_.CalledOnValidThread()); 338 DCHECK(main_thread_checker_.CalledOnValidThread());
334 return main_thread_only_; 339 return main_thread_only_;
335 } 340 }
336 const MainThreadOnly& main_thread_only() const { 341 const MainThreadOnly& main_thread_only() const {
337 DCHECK(main_thread_checker_.CalledOnValidThread()); 342 DCHECK(main_thread_checker_.CalledOnValidThread());
338 return main_thread_only_; 343 return main_thread_only_;
339 } 344 }
340 345
341 const bool should_monitor_quiescence_; 346 const bool should_monitor_quiescence_;
342 const bool should_notify_observers_; 347 const bool should_notify_observers_;
343 const bool should_report_when_execution_blocked_; 348 const bool should_report_when_execution_blocked_;
344 349
345 DISALLOW_COPY_AND_ASSIGN(TaskQueueImpl); 350 DISALLOW_COPY_AND_ASSIGN(TaskQueueImpl);
346 }; 351 };
347 352
348 } // namespace internal 353 } // namespace internal
349 } // namespace scheduler 354 } // namespace scheduler
350 } // namespace blink 355 } // namespace blink
351 356
352 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ 357 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698