| 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> |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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> CreateQueueEnabledVoter() override; |
| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 } | 187 } |
| 189 | 188 |
| 190 HeapHandle heap_handle() const { return main_thread_only().heap_handle; } | 189 HeapHandle heap_handle() const { return main_thread_only().heap_handle; } |
| 191 | 190 |
| 192 void set_heap_handle(HeapHandle heap_handle) { | 191 void set_heap_handle(HeapHandle heap_handle) { |
| 193 main_thread_only().heap_handle = heap_handle; | 192 main_thread_only().heap_handle = heap_handle; |
| 194 } | 193 } |
| 195 | 194 |
| 196 EnqueueOrder GetFenceForTest() const; | 195 EnqueueOrder GetFenceForTest() const; |
| 197 | 196 |
| 197 class QueueEnabledVoterImpl : public QueueEnabledVoter { |
| 198 public: |
| 199 explicit QueueEnabledVoterImpl(TaskQueueImpl* task_queue); |
| 200 ~QueueEnabledVoterImpl() override; |
| 201 |
| 202 // QueueEnabledVoter implementation. |
| 203 void SetQueueEnabled(bool enabled) override; |
| 204 |
| 205 TaskQueueImpl* GetTaskQueueForTest() const { return task_queue_.get(); } |
| 206 |
| 207 private: |
| 208 friend class TaskQueueImpl; |
| 209 |
| 210 scoped_refptr<TaskQueueImpl> task_queue_; |
| 211 bool enabled_; |
| 212 }; |
| 213 |
| 198 private: | 214 private: |
| 199 friend class WorkQueue; | 215 friend class WorkQueue; |
| 200 friend class WorkQueueTest; | 216 friend class WorkQueueTest; |
| 201 | 217 |
| 202 enum class TaskType { | 218 enum class TaskType { |
| 203 NORMAL, | 219 NORMAL, |
| 204 NON_NESTABLE, | 220 NON_NESTABLE, |
| 205 }; | 221 }; |
| 206 | 222 |
| 207 struct AnyThread { | 223 struct AnyThread { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 227 // the main thread. See description inside struct AnyThread for details. | 243 // the main thread. See description inside struct AnyThread for details. |
| 228 TaskQueueManager* task_queue_manager; | 244 TaskQueueManager* task_queue_manager; |
| 229 TimeDomain* time_domain; | 245 TimeDomain* time_domain; |
| 230 | 246 |
| 231 std::unique_ptr<WorkQueue> delayed_work_queue; | 247 std::unique_ptr<WorkQueue> delayed_work_queue; |
| 232 std::unique_ptr<WorkQueue> immediate_work_queue; | 248 std::unique_ptr<WorkQueue> immediate_work_queue; |
| 233 std::priority_queue<Task> delayed_incoming_queue; | 249 std::priority_queue<Task> delayed_incoming_queue; |
| 234 base::ObserverList<base::MessageLoop::TaskObserver> task_observers; | 250 base::ObserverList<base::MessageLoop::TaskObserver> task_observers; |
| 235 size_t set_index; | 251 size_t set_index; |
| 236 HeapHandle heap_handle; | 252 HeapHandle heap_handle; |
| 237 bool is_enabled; | 253 int is_enabled_refcount; |
| 254 int voter_refcount; |
| 238 base::trace_event::BlameContext* blame_context; // Not owned. | 255 base::trace_event::BlameContext* blame_context; // Not owned. |
| 239 EnqueueOrder current_fence; | 256 EnqueueOrder current_fence; |
| 240 base::TimeTicks scheduled_time_domain_wakeup; | 257 base::TimeTicks scheduled_time_domain_wakeup; |
| 241 }; | 258 }; |
| 242 | 259 |
| 243 ~TaskQueueImpl() override; | 260 ~TaskQueueImpl() override; |
| 244 | 261 |
| 245 bool PostImmediateTaskImpl(const tracked_objects::Location& from_here, | 262 bool PostImmediateTaskImpl(const tracked_objects::Location& from_here, |
| 246 const base::Closure& task, | 263 const base::Closure& task, |
| 247 TaskType task_type); | 264 TaskType task_type); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 277 bool BlockedByFenceLocked() const; | 294 bool BlockedByFenceLocked() const; |
| 278 | 295 |
| 279 void TraceQueueSize(bool is_locked) const; | 296 void TraceQueueSize(bool is_locked) const; |
| 280 static void QueueAsValueInto(const std::queue<Task>& queue, | 297 static void QueueAsValueInto(const std::queue<Task>& queue, |
| 281 base::trace_event::TracedValue* state); | 298 base::trace_event::TracedValue* state); |
| 282 static void QueueAsValueInto(const std::priority_queue<Task>& queue, | 299 static void QueueAsValueInto(const std::priority_queue<Task>& queue, |
| 283 base::trace_event::TracedValue* state); | 300 base::trace_event::TracedValue* state); |
| 284 static void TaskAsValueInto(const Task& task, | 301 static void TaskAsValueInto(const Task& task, |
| 285 base::trace_event::TracedValue* state); | 302 base::trace_event::TracedValue* state); |
| 286 | 303 |
| 304 void RemoveQueueEnabledVoter(const QueueEnabledVoterImpl* voter); |
| 305 void OnQueueEnabledVoteChanged(bool enabled); |
| 306 void EnableOrDisableWithSelector(bool enable); |
| 307 |
| 287 const base::PlatformThreadId thread_id_; | 308 const base::PlatformThreadId thread_id_; |
| 288 | 309 |
| 289 mutable base::Lock any_thread_lock_; | 310 mutable base::Lock any_thread_lock_; |
| 290 AnyThread any_thread_; | 311 AnyThread any_thread_; |
| 291 struct AnyThread& any_thread() { | 312 struct AnyThread& any_thread() { |
| 292 any_thread_lock_.AssertAcquired(); | 313 any_thread_lock_.AssertAcquired(); |
| 293 return any_thread_; | 314 return any_thread_; |
| 294 } | 315 } |
| 295 const struct AnyThread& any_thread() const { | 316 const struct AnyThread& any_thread() const { |
| 296 any_thread_lock_.AssertAcquired(); | 317 any_thread_lock_.AssertAcquired(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 318 const bool should_report_when_execution_blocked_; | 339 const bool should_report_when_execution_blocked_; |
| 319 | 340 |
| 320 DISALLOW_COPY_AND_ASSIGN(TaskQueueImpl); | 341 DISALLOW_COPY_AND_ASSIGN(TaskQueueImpl); |
| 321 }; | 342 }; |
| 322 | 343 |
| 323 } // namespace internal | 344 } // namespace internal |
| 324 } // namespace scheduler | 345 } // namespace scheduler |
| 325 } // namespace blink | 346 } // namespace blink |
| 326 | 347 |
| 327 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ | 348 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ |
| OLD | NEW |