Chromium Code Reviews| 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 main_thread_only().time_domain->ScheduleDelayedWork(this, delayed_run_time, | |
| 286 now); | |
| 284 } | 287 } |
| 285 | 288 |
| 286 TraceQueueSize(false); | 289 TraceQueueSize(false); |
| 287 } | 290 } |
| 288 | 291 |
| 289 void TaskQueueImpl::PushOntoDelayedIncomingQueueLocked(Task pending_task) { | 292 void TaskQueueImpl::PushOntoDelayedIncomingQueueLocked(Task pending_task) { |
| 290 any_thread().task_queue_manager->DidQueueTask(pending_task); | 293 any_thread().task_queue_manager->DidQueueTask(pending_task); |
| 291 | 294 |
| 292 int thread_hop_task_sequence_number = | 295 int thread_hop_task_sequence_number = |
| 293 any_thread().task_queue_manager->GetNextSequenceNumber(); | 296 any_thread().task_queue_manager->GetNextSequenceNumber(); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 397 main_thread_only().time_domain->CreateLazyNow().Now()) { | 400 main_thread_only().time_domain->CreateLazyNow().Now()) { |
| 398 return true; | 401 return true; |
| 399 } | 402 } |
| 400 | 403 |
| 401 // Finally tasks on |immediate_incoming_queue| count as immediate work. | 404 // Finally tasks on |immediate_incoming_queue| count as immediate work. |
| 402 base::AutoLock lock(any_thread_lock_); | 405 base::AutoLock lock(any_thread_lock_); |
| 403 return !any_thread().immediate_incoming_queue.empty(); | 406 return !any_thread().immediate_incoming_queue.empty(); |
| 404 } | 407 } |
| 405 | 408 |
| 406 base::Optional<base::TimeTicks> TaskQueueImpl::GetNextScheduledWakeUp() { | 409 base::Optional<base::TimeTicks> TaskQueueImpl::GetNextScheduledWakeUp() { |
| 407 if (main_thread_only().delayed_incoming_queue.empty()) | 410 if (main_thread_only().delayed_incoming_queue.empty() || !IsQueueEnabled()) |
|
Sami
2017/02/10 12:49:43
Should we do this at call site to avoid making thi
altimin
2017/02/10 13:05:32
I'm, for one, in favour of this approach: if the q
alex clarke (OOO till 29th)
2017/02/10 14:19:29
As discussed offline, this change is making the fu
| |
| 408 return base::nullopt; | 411 return base::nullopt; |
| 409 | 412 |
| 410 return main_thread_only().delayed_incoming_queue.top().delayed_run_time; | 413 return main_thread_only().delayed_incoming_queue.top().delayed_run_time; |
| 411 } | 414 } |
| 412 | 415 |
| 413 base::Optional<base::TimeTicks> TaskQueueImpl::WakeUpForDelayedWork( | 416 base::Optional<base::TimeTicks> TaskQueueImpl::WakeUpForDelayedWork( |
| 414 LazyNow* lazy_now) { | 417 LazyNow* lazy_now) { |
| 415 // Enqueue all delayed tasks that should be running now, skipping any that | 418 // Enqueue all delayed tasks that should be running now, skipping any that |
| 416 // have been canceled. | 419 // have been canceled. |
| 417 while (!main_thread_only().delayed_incoming_queue.empty()) { | 420 while (!main_thread_only().delayed_incoming_queue.empty()) { |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 792 bool is_enabled = IsQueueEnabled(); | 795 bool is_enabled = IsQueueEnabled(); |
| 793 if (was_enabled != is_enabled) | 796 if (was_enabled != is_enabled) |
| 794 EnableOrDisableWithSelector(is_enabled); | 797 EnableOrDisableWithSelector(is_enabled); |
| 795 } | 798 } |
| 796 | 799 |
| 797 void TaskQueueImpl::EnableOrDisableWithSelector(bool enable) { | 800 void TaskQueueImpl::EnableOrDisableWithSelector(bool enable) { |
| 798 if (!main_thread_only().task_queue_manager) | 801 if (!main_thread_only().task_queue_manager) |
| 799 return; | 802 return; |
| 800 | 803 |
| 801 if (enable) { | 804 if (enable) { |
| 805 if (!main_thread_only().delayed_incoming_queue.empty()) { | |
| 806 main_thread_only().time_domain->ScheduleDelayedWork( | |
| 807 this, | |
| 808 main_thread_only().delayed_incoming_queue.top().delayed_run_time, | |
| 809 main_thread_only().time_domain->Now()); | |
| 810 } | |
| 802 // Note the selector calls TaskQueueManager::OnTaskQueueEnabled which posts | 811 // Note the selector calls TaskQueueManager::OnTaskQueueEnabled which posts |
| 803 // a DoWork if needed. | 812 // a DoWork if needed. |
| 804 main_thread_only().task_queue_manager->selector_.EnableQueue(this); | 813 main_thread_only().task_queue_manager->selector_.EnableQueue(this); |
| 805 } else { | 814 } else { |
| 815 if (!main_thread_only().delayed_incoming_queue.empty()) | |
| 816 main_thread_only().time_domain->CancelDelayedWork(this); | |
| 806 main_thread_only().task_queue_manager->selector_.DisableQueue(this); | 817 main_thread_only().task_queue_manager->selector_.DisableQueue(this); |
| 807 } | 818 } |
| 808 } | 819 } |
| 809 | 820 |
| 810 std::unique_ptr<TaskQueueImpl::QueueEnabledVoter> | 821 std::unique_ptr<TaskQueueImpl::QueueEnabledVoter> |
| 811 TaskQueueImpl::CreateQueueEnabledVoter() { | 822 TaskQueueImpl::CreateQueueEnabledVoter() { |
| 812 main_thread_only().voter_refcount++; | 823 main_thread_only().voter_refcount++; |
| 813 main_thread_only().is_enabled_refcount++; | 824 main_thread_only().is_enabled_refcount++; |
| 814 return base::MakeUnique<QueueEnabledVoterImpl>(this); | 825 return base::MakeUnique<QueueEnabledVoterImpl>(this); |
| 815 } | 826 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 846 | 857 |
| 847 void TaskQueueImpl::PushImmediateIncomingTaskForTest( | 858 void TaskQueueImpl::PushImmediateIncomingTaskForTest( |
| 848 TaskQueueImpl::Task&& task) { | 859 TaskQueueImpl::Task&& task) { |
| 849 base::AutoLock lock(any_thread_lock_); | 860 base::AutoLock lock(any_thread_lock_); |
| 850 any_thread().immediate_incoming_queue.push_back(std::move(task)); | 861 any_thread().immediate_incoming_queue.push_back(std::move(task)); |
| 851 } | 862 } |
| 852 | 863 |
| 853 } // namespace internal | 864 } // namespace internal |
| 854 } // namespace scheduler | 865 } // namespace scheduler |
| 855 } // namespace blink | 866 } // namespace blink |
| OLD | NEW |