| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 bool PostDelayedTask(const tracked_objects::Location& from_here, | 135 bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 136 base::OnceClosure task, | 136 base::OnceClosure task, |
| 137 base::TimeDelta delay) override; | 137 base::TimeDelta delay) override; |
| 138 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, | 138 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, |
| 139 base::OnceClosure task, | 139 base::OnceClosure task, |
| 140 base::TimeDelta delay) override; | 140 base::TimeDelta delay) override; |
| 141 std::unique_ptr<QueueEnabledVoter> CreateQueueEnabledVoter() override; | 141 std::unique_ptr<QueueEnabledVoter> CreateQueueEnabledVoter() override; |
| 142 bool IsQueueEnabled() const override; | 142 bool IsQueueEnabled() const override; |
| 143 bool IsEmpty() const override; | 143 bool IsEmpty() const override; |
| 144 size_t GetNumberOfPendingTasks() const override; | 144 size_t GetNumberOfPendingTasks() const override; |
| 145 bool HasPendingImmediateWork() const override; | 145 bool HasTaskToRunImmediately() const override; |
| 146 base::Optional<base::TimeTicks> GetNextScheduledWakeUp() override; | 146 base::Optional<base::TimeTicks> GetNextScheduledWakeUp() override; |
| 147 void SetQueuePriority(QueuePriority priority) override; | 147 void SetQueuePriority(QueuePriority priority) override; |
| 148 QueuePriority GetQueuePriority() const override; | 148 QueuePriority GetQueuePriority() const override; |
| 149 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override; | 149 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override; |
| 150 void RemoveTaskObserver( | 150 void RemoveTaskObserver( |
| 151 base::MessageLoop::TaskObserver* task_observer) override; | 151 base::MessageLoop::TaskObserver* task_observer) override; |
| 152 void SetTimeDomain(TimeDomain* time_domain) override; | 152 void SetTimeDomain(TimeDomain* time_domain) override; |
| 153 TimeDomain* GetTimeDomain() const override; | 153 TimeDomain* GetTimeDomain() const override; |
| 154 void SetBlameContext(base::trace_event::BlameContext* blame_context) override; | 154 void SetBlameContext(base::trace_event::BlameContext* blame_context) override; |
| 155 void InsertFence(InsertFencePosition position) override; | 155 void InsertFence(InsertFencePosition position) override; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 170 | 170 |
| 171 void AsValueInto(base::TimeTicks now, | 171 void AsValueInto(base::TimeTicks now, |
| 172 base::trace_event::TracedValue* state) const; | 172 base::trace_event::TracedValue* state) const; |
| 173 | 173 |
| 174 bool GetQuiescenceMonitored() const { return should_monitor_quiescence_; } | 174 bool GetQuiescenceMonitored() const { return should_monitor_quiescence_; } |
| 175 bool GetShouldNotifyObservers() const { return should_notify_observers_; } | 175 bool GetShouldNotifyObservers() const { return should_notify_observers_; } |
| 176 | 176 |
| 177 void NotifyWillProcessTask(const base::PendingTask& pending_task); | 177 void NotifyWillProcessTask(const base::PendingTask& pending_task); |
| 178 void NotifyDidProcessTask(const base::PendingTask& pending_task); | 178 void NotifyDidProcessTask(const base::PendingTask& pending_task); |
| 179 | 179 |
| 180 // Called by TimeDomain when the wake-up for this queue has changed. |
| 181 // There is only one wake-up, new wake-up cancels any previous wake-ups. |
| 182 // If |scheduled_time_domain_wake_up| is base::nullopt then the wake-up |
| 183 // has been cancelled. |
| 184 // Must be called from the main thread. |
| 185 void SetScheduledTimeDomainWakeUp( |
| 186 base::Optional<base::TimeTicks> scheduled_time_domain_wake_up); |
| 187 |
| 188 // Check for available tasks in immediate work queues. |
| 189 // Used to check if we need to generate notifications about delayed work. |
| 190 bool HasPendingImmediateWork(); |
| 191 |
| 180 WorkQueue* delayed_work_queue() { | 192 WorkQueue* delayed_work_queue() { |
| 181 return main_thread_only().delayed_work_queue.get(); | 193 return main_thread_only().delayed_work_queue.get(); |
| 182 } | 194 } |
| 183 | 195 |
| 184 const WorkQueue* delayed_work_queue() const { | 196 const WorkQueue* delayed_work_queue() const { |
| 185 return main_thread_only().delayed_work_queue.get(); | 197 return main_thread_only().delayed_work_queue.get(); |
| 186 } | 198 } |
| 187 | 199 |
| 188 WorkQueue* immediate_work_queue() { | 200 WorkQueue* immediate_work_queue() { |
| 189 return main_thread_only().immediate_work_queue.get(); | 201 return main_thread_only().immediate_work_queue.get(); |
| 190 } | 202 } |
| 191 | 203 |
| 192 const WorkQueue* immediate_work_queue() const { | 204 const WorkQueue* immediate_work_queue() const { |
| 193 return main_thread_only().immediate_work_queue.get(); | 205 return main_thread_only().immediate_work_queue.get(); |
| 194 } | 206 } |
| 195 | 207 |
| 196 bool should_report_when_execution_blocked() const { | 208 bool should_report_when_execution_blocked() const { |
| 197 return should_report_when_execution_blocked_; | 209 return should_report_when_execution_blocked_; |
| 198 } | 210 } |
| 199 | 211 |
| 200 // Enqueues any delayed tasks which should be run now on the | 212 // Enqueues any delayed tasks which should be run now on the |
| 201 // |delayed_work_queue|. Returns the subsequent wake-up that is required, if | 213 // |delayed_work_queue|. Returns the subsequent wake-up that is required, if |
| 202 // any. Must be called from the main thread. | 214 // any. Must be called from the main thread. |
| 203 base::Optional<DelayedWakeUp> WakeUpForDelayedWork(LazyNow* lazy_now); | 215 base::Optional<DelayedWakeUp> WakeUpForDelayedWork(LazyNow* lazy_now); |
| 204 | 216 |
| 205 base::TimeTicks scheduled_time_domain_wake_up() const { | 217 base::Optional<base::TimeTicks> scheduled_time_domain_wake_up() const { |
| 206 return main_thread_only().scheduled_time_domain_wake_up; | 218 return main_thread_only().scheduled_time_domain_wake_up; |
| 207 } | 219 } |
| 208 | 220 |
| 209 void set_scheduled_time_domain_wake_up( | |
| 210 base::TimeTicks scheduled_time_domain_wake_up) { | |
| 211 main_thread_only().scheduled_time_domain_wake_up = | |
| 212 scheduled_time_domain_wake_up; | |
| 213 } | |
| 214 | |
| 215 HeapHandle heap_handle() const { return main_thread_only().heap_handle; } | 221 HeapHandle heap_handle() const { return main_thread_only().heap_handle; } |
| 216 | 222 |
| 217 void set_heap_handle(HeapHandle heap_handle) { | 223 void set_heap_handle(HeapHandle heap_handle) { |
| 218 main_thread_only().heap_handle = heap_handle; | 224 main_thread_only().heap_handle = heap_handle; |
| 219 } | 225 } |
| 220 | 226 |
| 221 void PushImmediateIncomingTaskForTest(TaskQueueImpl::Task&& task); | 227 void PushImmediateIncomingTaskForTest(TaskQueueImpl::Task&& task); |
| 222 EnqueueOrder GetFenceForTest() const; | 228 EnqueueOrder GetFenceForTest() const; |
| 223 | 229 |
| 224 class QueueEnabledVoterImpl : public QueueEnabledVoter { | 230 class QueueEnabledVoterImpl : public QueueEnabledVoter { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 std::unique_ptr<WorkQueue> delayed_work_queue; | 284 std::unique_ptr<WorkQueue> delayed_work_queue; |
| 279 std::unique_ptr<WorkQueue> immediate_work_queue; | 285 std::unique_ptr<WorkQueue> immediate_work_queue; |
| 280 std::priority_queue<Task> delayed_incoming_queue; | 286 std::priority_queue<Task> delayed_incoming_queue; |
| 281 base::ObserverList<base::MessageLoop::TaskObserver> task_observers; | 287 base::ObserverList<base::MessageLoop::TaskObserver> task_observers; |
| 282 size_t set_index; | 288 size_t set_index; |
| 283 HeapHandle heap_handle; | 289 HeapHandle heap_handle; |
| 284 int is_enabled_refcount; | 290 int is_enabled_refcount; |
| 285 int voter_refcount; | 291 int voter_refcount; |
| 286 base::trace_event::BlameContext* blame_context; // Not owned. | 292 base::trace_event::BlameContext* blame_context; // Not owned. |
| 287 EnqueueOrder current_fence; | 293 EnqueueOrder current_fence; |
| 288 base::TimeTicks scheduled_time_domain_wake_up; | 294 base::Optional<base::TimeTicks> scheduled_time_domain_wake_up; |
| 289 }; | 295 }; |
| 290 | 296 |
| 291 ~TaskQueueImpl() override; | 297 ~TaskQueueImpl() override; |
| 292 | 298 |
| 293 bool PostImmediateTaskImpl(const tracked_objects::Location& from_here, | 299 bool PostImmediateTaskImpl(const tracked_objects::Location& from_here, |
| 294 base::OnceClosure task, | 300 base::OnceClosure task, |
| 295 TaskType task_type); | 301 TaskType task_type); |
| 296 bool PostDelayedTaskImpl(const tracked_objects::Location& from_here, | 302 bool PostDelayedTaskImpl(const tracked_objects::Location& from_here, |
| 297 base::OnceClosure task, | 303 base::OnceClosure task, |
| 298 base::TimeDelta delay, | 304 base::TimeDelta delay, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 base::TimeTicks now, | 346 base::TimeTicks now, |
| 341 base::trace_event::TracedValue* state); | 347 base::trace_event::TracedValue* state); |
| 342 | 348 |
| 343 void RemoveQueueEnabledVoter(const QueueEnabledVoterImpl* voter); | 349 void RemoveQueueEnabledVoter(const QueueEnabledVoterImpl* voter); |
| 344 void OnQueueEnabledVoteChanged(bool enabled); | 350 void OnQueueEnabledVoteChanged(bool enabled); |
| 345 void EnableOrDisableWithSelector(bool enable); | 351 void EnableOrDisableWithSelector(bool enable); |
| 346 | 352 |
| 347 // Schedules delayed work on time domain and calls the observer. | 353 // Schedules delayed work on time domain and calls the observer. |
| 348 void ScheduleDelayedWorkInTimeDomain(base::TimeTicks now); | 354 void ScheduleDelayedWorkInTimeDomain(base::TimeTicks now); |
| 349 | 355 |
| 350 void NotifyWakeUpChangedOnMainThread(base::TimeTicks wake_up); | |
| 351 | |
| 352 const base::PlatformThreadId thread_id_; | 356 const base::PlatformThreadId thread_id_; |
| 353 | 357 |
| 354 mutable base::Lock any_thread_lock_; | 358 mutable base::Lock any_thread_lock_; |
| 355 AnyThread any_thread_; | 359 AnyThread any_thread_; |
| 356 struct AnyThread& any_thread() { | 360 struct AnyThread& any_thread() { |
| 357 any_thread_lock_.AssertAcquired(); | 361 any_thread_lock_.AssertAcquired(); |
| 358 return any_thread_; | 362 return any_thread_; |
| 359 } | 363 } |
| 360 const struct AnyThread& any_thread() const { | 364 const struct AnyThread& any_thread() const { |
| 361 any_thread_lock_.AssertAcquired(); | 365 any_thread_lock_.AssertAcquired(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 392 const bool should_report_when_execution_blocked_; | 396 const bool should_report_when_execution_blocked_; |
| 393 | 397 |
| 394 DISALLOW_COPY_AND_ASSIGN(TaskQueueImpl); | 398 DISALLOW_COPY_AND_ASSIGN(TaskQueueImpl); |
| 395 }; | 399 }; |
| 396 | 400 |
| 397 } // namespace internal | 401 } // namespace internal |
| 398 } // namespace scheduler | 402 } // namespace scheduler |
| 399 } // namespace blink | 403 } // namespace blink |
| 400 | 404 |
| 401 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ | 405 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ |
| OLD | NEW |