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 #include "platform/scheduler/base/task_queue_impl.h" | 5 #include "platform/scheduler/base/task_queue_impl.h" |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/trace_event/blame_context.h" | 10 #include "base/trace_event/blame_context.h" |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 return true; | 269 return true; |
270 } | 270 } |
271 | 271 |
272 void TaskQueueImpl::PushOntoDelayedIncomingQueueFromMainThread( | 272 void TaskQueueImpl::PushOntoDelayedIncomingQueueFromMainThread( |
273 Task pending_task, base::TimeTicks now) { | 273 Task pending_task, base::TimeTicks now) { |
274 base::TimeTicks delayed_run_time = pending_task.delayed_run_time; | 274 base::TimeTicks delayed_run_time = pending_task.delayed_run_time; |
275 main_thread_only().task_queue_manager->DidQueueTask(pending_task); | 275 main_thread_only().task_queue_manager->DidQueueTask(pending_task); |
276 main_thread_only().delayed_incoming_queue.push(std::move(pending_task)); | 276 main_thread_only().delayed_incoming_queue.push(std::move(pending_task)); |
277 | 277 |
278 // If |pending_task| is at the head of the queue, then make sure a wakeup | 278 // If |pending_task| is at the head of the queue, then make sure a wakeup |
279 // is requested. | 279 // is requested if the queue is enabled. Note we still want to schedule a |
280 if (main_thread_only().delayed_incoming_queue.top().delayed_run_time == | 280 // wakeup even if blocked by a fence, because we'd break throttling logic |
281 delayed_run_time) { | 281 // otherwise. |
282 main_thread_only().time_domain->ScheduleDelayedWork( | 282 base::TimeTicks next_delayed_task = |
283 this, pending_task.delayed_run_time, now); | 283 main_thread_only().delayed_incoming_queue.top().delayed_run_time; |
| 284 if (next_delayed_task == delayed_run_time && IsQueueEnabled()) { |
| 285 LazyNow lazy_now(now); |
| 286 main_thread_only().time_domain->ScheduleDelayedWork(this, delayed_run_time, |
| 287 &lazy_now); |
284 } | 288 } |
285 | 289 |
286 TraceQueueSize(false); | 290 TraceQueueSize(false); |
287 } | 291 } |
288 | 292 |
289 void TaskQueueImpl::PushOntoDelayedIncomingQueueLocked(Task pending_task) { | 293 void TaskQueueImpl::PushOntoDelayedIncomingQueueLocked(Task pending_task) { |
290 any_thread().task_queue_manager->DidQueueTask(pending_task); | 294 any_thread().task_queue_manager->DidQueueTask(pending_task); |
291 | 295 |
292 int thread_hop_task_sequence_number = | 296 int thread_hop_task_sequence_number = |
293 any_thread().task_queue_manager->GetNextSequenceNumber(); | 297 any_thread().task_queue_manager->GetNextSequenceNumber(); |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 return; | 579 return; |
576 | 580 |
577 any_thread().time_domain = time_domain; | 581 any_thread().time_domain = time_domain; |
578 } | 582 } |
579 | 583 |
580 main_thread_only().time_domain->UnregisterQueue(this); | 584 main_thread_only().time_domain->UnregisterQueue(this); |
581 main_thread_only().time_domain = time_domain; | 585 main_thread_only().time_domain = time_domain; |
582 time_domain->RegisterQueue(this); | 586 time_domain->RegisterQueue(this); |
583 | 587 |
584 if (!main_thread_only().delayed_incoming_queue.empty()) { | 588 if (!main_thread_only().delayed_incoming_queue.empty()) { |
| 589 LazyNow lazy_now = time_domain->CreateLazyNow(); |
585 time_domain->ScheduleDelayedWork( | 590 time_domain->ScheduleDelayedWork( |
586 this, main_thread_only().delayed_incoming_queue.top().delayed_run_time, | 591 this, main_thread_only().delayed_incoming_queue.top().delayed_run_time, |
587 time_domain->Now()); | 592 &lazy_now); |
588 } | 593 } |
589 } | 594 } |
590 | 595 |
591 TimeDomain* TaskQueueImpl::GetTimeDomain() const { | 596 TimeDomain* TaskQueueImpl::GetTimeDomain() const { |
592 if (base::PlatformThread::CurrentId() == thread_id_) | 597 if (base::PlatformThread::CurrentId() == thread_id_) |
593 return main_thread_only().time_domain; | 598 return main_thread_only().time_domain; |
594 | 599 |
595 base::AutoLock lock(any_thread_lock_); | 600 base::AutoLock lock(any_thread_lock_); |
596 return any_thread().time_domain; | 601 return any_thread().time_domain; |
597 } | 602 } |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 bool is_enabled = IsQueueEnabled(); | 797 bool is_enabled = IsQueueEnabled(); |
793 if (was_enabled != is_enabled) | 798 if (was_enabled != is_enabled) |
794 EnableOrDisableWithSelector(is_enabled); | 799 EnableOrDisableWithSelector(is_enabled); |
795 } | 800 } |
796 | 801 |
797 void TaskQueueImpl::EnableOrDisableWithSelector(bool enable) { | 802 void TaskQueueImpl::EnableOrDisableWithSelector(bool enable) { |
798 if (!main_thread_only().task_queue_manager) | 803 if (!main_thread_only().task_queue_manager) |
799 return; | 804 return; |
800 | 805 |
801 if (enable) { | 806 if (enable) { |
| 807 if (!main_thread_only().delayed_incoming_queue.empty()) { |
| 808 LazyNow lazy_now = main_thread_only().time_domain->CreateLazyNow(); |
| 809 main_thread_only().time_domain->ScheduleDelayedWork( |
| 810 this, |
| 811 main_thread_only().delayed_incoming_queue.top().delayed_run_time, |
| 812 &lazy_now); |
| 813 } |
802 // Note the selector calls TaskQueueManager::OnTaskQueueEnabled which posts | 814 // Note the selector calls TaskQueueManager::OnTaskQueueEnabled which posts |
803 // a DoWork if needed. | 815 // a DoWork if needed. |
804 main_thread_only().task_queue_manager->selector_.EnableQueue(this); | 816 main_thread_only().task_queue_manager->selector_.EnableQueue(this); |
805 } else { | 817 } else { |
| 818 if (!main_thread_only().delayed_incoming_queue.empty()) |
| 819 main_thread_only().time_domain->CancelDelayedWork(this); |
806 main_thread_only().task_queue_manager->selector_.DisableQueue(this); | 820 main_thread_only().task_queue_manager->selector_.DisableQueue(this); |
807 } | 821 } |
808 } | 822 } |
809 | 823 |
810 std::unique_ptr<TaskQueueImpl::QueueEnabledVoter> | 824 std::unique_ptr<TaskQueueImpl::QueueEnabledVoter> |
811 TaskQueueImpl::CreateQueueEnabledVoter() { | 825 TaskQueueImpl::CreateQueueEnabledVoter() { |
812 main_thread_only().voter_refcount++; | 826 main_thread_only().voter_refcount++; |
813 main_thread_only().is_enabled_refcount++; | 827 main_thread_only().is_enabled_refcount++; |
814 return base::MakeUnique<QueueEnabledVoterImpl>(this); | 828 return base::MakeUnique<QueueEnabledVoterImpl>(this); |
815 } | 829 } |
(...skipping 15 matching lines...) Expand all Loading... |
831 main_thread_only().delayed_incoming_queue.pop(); | 845 main_thread_only().delayed_incoming_queue.pop(); |
832 } | 846 } |
833 | 847 |
834 main_thread_only().delayed_incoming_queue = std::move(remaining_tasks); | 848 main_thread_only().delayed_incoming_queue = std::move(remaining_tasks); |
835 | 849 |
836 // Re-schedule delayed call to WakeUpForDelayedWork if needed. | 850 // Re-schedule delayed call to WakeUpForDelayedWork if needed. |
837 if (main_thread_only().delayed_incoming_queue.empty()) { | 851 if (main_thread_only().delayed_incoming_queue.empty()) { |
838 main_thread_only().time_domain->CancelDelayedWork(this); | 852 main_thread_only().time_domain->CancelDelayedWork(this); |
839 } else if (first_task_runtime != | 853 } else if (first_task_runtime != |
840 main_thread_only().delayed_incoming_queue.top().delayed_run_time) { | 854 main_thread_only().delayed_incoming_queue.top().delayed_run_time) { |
| 855 LazyNow lazy_now(now); |
841 main_thread_only().time_domain->ScheduleDelayedWork( | 856 main_thread_only().time_domain->ScheduleDelayedWork( |
842 this, main_thread_only().delayed_incoming_queue.top().delayed_run_time, | 857 this, main_thread_only().delayed_incoming_queue.top().delayed_run_time, |
843 main_thread_only().time_domain->Now()); | 858 &lazy_now); |
844 } | 859 } |
845 } | 860 } |
846 | 861 |
847 void TaskQueueImpl::PushImmediateIncomingTaskForTest( | 862 void TaskQueueImpl::PushImmediateIncomingTaskForTest( |
848 TaskQueueImpl::Task&& task) { | 863 TaskQueueImpl::Task&& task) { |
849 base::AutoLock lock(any_thread_lock_); | 864 base::AutoLock lock(any_thread_lock_); |
850 any_thread().immediate_incoming_queue.push_back(std::move(task)); | 865 any_thread().immediate_incoming_queue.push_back(std::move(task)); |
851 } | 866 } |
852 | 867 |
853 } // namespace internal | 868 } // namespace internal |
854 } // namespace scheduler | 869 } // namespace scheduler |
855 } // namespace blink | 870 } // namespace blink |
OLD | NEW |