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

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

Issue 2540663002: Add the concept of QueueEnabledVoters to blink scheduler TaskQueue (Closed)
Patch Set: Added a couple of extra tests Created 4 years 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 // TaskQueue implementation. 113 // TaskQueue implementation.
114 void UnregisterTaskQueue() override; 114 void UnregisterTaskQueue() override;
115 bool RunsTasksOnCurrentThread() const override; 115 bool RunsTasksOnCurrentThread() const override;
116 bool PostDelayedTask(const tracked_objects::Location& from_here, 116 bool PostDelayedTask(const tracked_objects::Location& from_here,
117 const base::Closure& task, 117 const base::Closure& task,
118 base::TimeDelta delay) override; 118 base::TimeDelta delay) override;
119 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 119 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
120 const base::Closure& task, 120 const base::Closure& task,
121 base::TimeDelta delay) override; 121 base::TimeDelta delay) override;
122 void SetQueueEnabled(bool enabled) override; 122 std::unique_ptr<QueueEnabledVoter> GetQueueEnabledVoter() override;
Sami 2016/11/29 14:45:17 s/Get/Create/ to make this a bit more obvious.
alex clarke (OOO till 29th) 2016/11/29 16:49:11 Done.
123 bool IsQueueEnabled() const override; 123 bool IsQueueEnabled() const override;
124 bool IsEmpty() const override; 124 bool IsEmpty() const override;
125 size_t GetNumberOfPendingTasks() const override; 125 size_t GetNumberOfPendingTasks() const override;
126 bool HasPendingImmediateWork() const override; 126 bool HasPendingImmediateWork() const override;
127 base::Optional<base::TimeTicks> GetNextScheduledWakeUp() override; 127 base::Optional<base::TimeTicks> GetNextScheduledWakeUp() override;
128 void SetQueuePriority(QueuePriority priority) override; 128 void SetQueuePriority(QueuePriority priority) override;
129 QueuePriority GetQueuePriority() const override; 129 QueuePriority GetQueuePriority() const override;
130 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override; 130 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override;
131 void RemoveTaskObserver( 131 void RemoveTaskObserver(
132 base::MessageLoop::TaskObserver* task_observer) override; 132 base::MessageLoop::TaskObserver* task_observer) override;
133 void SetTimeDomain(TimeDomain* time_domain) override; 133 void SetTimeDomain(TimeDomain* time_domain) override;
134 TimeDomain* GetTimeDomain() const override; 134 TimeDomain* GetTimeDomain() const override;
135 void SetBlameContext(base::trace_event::BlameContext* blame_context) override; 135 void SetBlameContext(base::trace_event::BlameContext* blame_context) override;
136 void InsertFence(InsertFencePosition position) override; 136 void InsertFence(InsertFencePosition position) override;
137 void RemoveFence() override; 137 void RemoveFence() override;
138 bool BlockedByFence() const override; 138 bool BlockedByFence() const override;
139 const char* GetName() const override;
140 QueueType GetQueueType() const override;
139 141
140 // If this returns false then future updates for this queue are not needed 142 // If this returns false then future updates for this queue are not needed
141 // unless requested. 143 // unless requested.
142 bool MaybeUpdateImmediateWorkQueues(); 144 bool MaybeUpdateImmediateWorkQueues();
143 145
144 const char* GetName() const override;
145 QueueType GetQueueType() const override;
146
147 void AsValueInto(base::trace_event::TracedValue* state) const; 146 void AsValueInto(base::trace_event::TracedValue* state) const;
148 147
149 bool GetQuiescenceMonitored() const { return should_monitor_quiescence_; } 148 bool GetQuiescenceMonitored() const { return should_monitor_quiescence_; }
150 bool GetShouldNotifyObservers() const { return should_notify_observers_; } 149 bool GetShouldNotifyObservers() const { return should_notify_observers_; }
151 150
152 void NotifyWillProcessTask(const base::PendingTask& pending_task); 151 void NotifyWillProcessTask(const base::PendingTask& pending_task);
153 void NotifyDidProcessTask(const base::PendingTask& pending_task); 152 void NotifyDidProcessTask(const base::PendingTask& pending_task);
154 153
155 WorkQueue* delayed_work_queue() { 154 WorkQueue* delayed_work_queue() {
156 return main_thread_only().delayed_work_queue.get(); 155 return main_thread_only().delayed_work_queue.get();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 // the main thread. See description inside struct AnyThread for details. 226 // the main thread. See description inside struct AnyThread for details.
228 TaskQueueManager* task_queue_manager; 227 TaskQueueManager* task_queue_manager;
229 TimeDomain* time_domain; 228 TimeDomain* time_domain;
230 229
231 std::unique_ptr<WorkQueue> delayed_work_queue; 230 std::unique_ptr<WorkQueue> delayed_work_queue;
232 std::unique_ptr<WorkQueue> immediate_work_queue; 231 std::unique_ptr<WorkQueue> immediate_work_queue;
233 std::priority_queue<Task> delayed_incoming_queue; 232 std::priority_queue<Task> delayed_incoming_queue;
234 base::ObserverList<base::MessageLoop::TaskObserver> task_observers; 233 base::ObserverList<base::MessageLoop::TaskObserver> task_observers;
235 size_t set_index; 234 size_t set_index;
236 HeapHandle heap_handle; 235 HeapHandle heap_handle;
237 bool is_enabled; 236 int is_enabled_refcount;
237 int voter_refcount;
238 base::trace_event::BlameContext* blame_context; // Not owned. 238 base::trace_event::BlameContext* blame_context; // Not owned.
239 EnqueueOrder current_fence; 239 EnqueueOrder current_fence;
240 base::TimeTicks scheduled_time_domain_wakeup; 240 base::TimeTicks scheduled_time_domain_wakeup;
241 }; 241 };
242 242
243 class QueueEnabledVoterImpl : public QueueEnabledVoter {
244 public:
245 explicit QueueEnabledVoterImpl(TaskQueueImpl* task_queue);
246 ~QueueEnabledVoterImpl() override;
247
248 // QueueEnabledVoter implementation.
249 void SetQueueEnabled(bool enabled) override;
250 TaskQueue* GetTaskQueue() const override;
251
252 private:
253 friend class TaskQueueImpl;
254
255 scoped_refptr<TaskQueueImpl> task_queue_;
256 bool enabled_;
257 };
258
243 ~TaskQueueImpl() override; 259 ~TaskQueueImpl() override;
244 260
245 bool PostImmediateTaskImpl(const tracked_objects::Location& from_here, 261 bool PostImmediateTaskImpl(const tracked_objects::Location& from_here,
246 const base::Closure& task, 262 const base::Closure& task,
247 TaskType task_type); 263 TaskType task_type);
248 bool PostDelayedTaskImpl(const tracked_objects::Location& from_here, 264 bool PostDelayedTaskImpl(const tracked_objects::Location& from_here,
249 const base::Closure& task, 265 const base::Closure& task,
250 base::TimeDelta delay, 266 base::TimeDelta delay,
251 TaskType task_type); 267 TaskType task_type);
252 268
(...skipping 24 matching lines...) Expand all
277 bool BlockedByFenceLocked() const; 293 bool BlockedByFenceLocked() const;
278 294
279 void TraceQueueSize(bool is_locked) const; 295 void TraceQueueSize(bool is_locked) const;
280 static void QueueAsValueInto(const std::queue<Task>& queue, 296 static void QueueAsValueInto(const std::queue<Task>& queue,
281 base::trace_event::TracedValue* state); 297 base::trace_event::TracedValue* state);
282 static void QueueAsValueInto(const std::priority_queue<Task>& queue, 298 static void QueueAsValueInto(const std::priority_queue<Task>& queue,
283 base::trace_event::TracedValue* state); 299 base::trace_event::TracedValue* state);
284 static void TaskAsValueInto(const Task& task, 300 static void TaskAsValueInto(const Task& task,
285 base::trace_event::TracedValue* state); 301 base::trace_event::TracedValue* state);
286 302
303 void RemoveQueueEnabledVoter(const QueueEnabledVoterImpl* voter);
304 void QueueEnabledVoteChanged(bool enabled);
Sami 2016/11/29 14:45:16 nit: OnQueueEnabledVoteChanged?
alex clarke (OOO till 29th) 2016/11/29 16:49:11 Done.
305 void EnableOrDisableWithSelector(bool enable);
306
287 const base::PlatformThreadId thread_id_; 307 const base::PlatformThreadId thread_id_;
288 308
289 mutable base::Lock any_thread_lock_; 309 mutable base::Lock any_thread_lock_;
290 AnyThread any_thread_; 310 AnyThread any_thread_;
291 struct AnyThread& any_thread() { 311 struct AnyThread& any_thread() {
292 any_thread_lock_.AssertAcquired(); 312 any_thread_lock_.AssertAcquired();
293 return any_thread_; 313 return any_thread_;
294 } 314 }
295 const struct AnyThread& any_thread() const { 315 const struct AnyThread& any_thread() const {
296 any_thread_lock_.AssertAcquired(); 316 any_thread_lock_.AssertAcquired();
(...skipping 21 matching lines...) Expand all
318 const bool should_report_when_execution_blocked_; 338 const bool should_report_when_execution_blocked_;
319 339
320 DISALLOW_COPY_AND_ASSIGN(TaskQueueImpl); 340 DISALLOW_COPY_AND_ASSIGN(TaskQueueImpl);
321 }; 341 };
322 342
323 } // namespace internal 343 } // namespace internal
324 } // namespace scheduler 344 } // namespace scheduler
325 } // namespace blink 345 } // namespace blink
326 346
327 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ 347 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698