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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 main_thread_only().delayed_incoming_queue.push(std::move(pending_task)); | 283 main_thread_only().delayed_incoming_queue.push(std::move(pending_task)); |
| 284 | 284 |
| 285 // If |pending_task| is at the head of the queue, then make sure a wake-up | 285 // If |pending_task| is at the head of the queue, then make sure a wake-up |
| 286 // is requested if the queue is enabled. Note we still want to schedule a | 286 // is requested if the queue is enabled. Note we still want to schedule a |
| 287 // wake-up even if blocked by a fence, because we'd break throttling logic | 287 // wake-up even if blocked by a fence, because we'd break throttling logic |
| 288 // otherwise. | 288 // otherwise. |
| 289 DelayedWakeUp new_wake_up = | 289 DelayedWakeUp new_wake_up = |
| 290 main_thread_only().delayed_incoming_queue.top().delayed_wake_up(); | 290 main_thread_only().delayed_incoming_queue.top().delayed_wake_up(); |
| 291 if (wake_up.time == new_wake_up.time && | 291 if (wake_up.time == new_wake_up.time && |
| 292 wake_up.sequence_num == new_wake_up.sequence_num) { | 292 wake_up.sequence_num == new_wake_up.sequence_num) { |
| 293 ScheduleDelayedWorkInTimeDomain(now); | 293 ScheduleDelayedWorkInTimeDomain(now); |
|
alex clarke (OOO till 29th)
2017/05/09 11:51:28
Should we notify here?
altimin
2017/05/09 13:15:04
No, time domain will call ScheduleDelayedWorkInTim
| |
| 294 } | 294 } |
| 295 | 295 |
| 296 TraceQueueSize(); | 296 TraceQueueSize(); |
| 297 } | 297 } |
| 298 | 298 |
| 299 void TaskQueueImpl::PushOntoDelayedIncomingQueueLocked(Task pending_task) { | 299 void TaskQueueImpl::PushOntoDelayedIncomingQueueLocked(Task pending_task) { |
| 300 any_thread().task_queue_manager->DidQueueTask(pending_task); | 300 any_thread().task_queue_manager->DidQueueTask(pending_task); |
| 301 | 301 |
| 302 int thread_hop_task_sequence_number = | 302 int thread_hop_task_sequence_number = |
| 303 any_thread().task_queue_manager->GetNextSequenceNumber(); | 303 any_thread().task_queue_manager->GetNextSequenceNumber(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 size_t task_count = 0; | 395 size_t task_count = 0; |
| 396 task_count += main_thread_only().delayed_work_queue->Size(); | 396 task_count += main_thread_only().delayed_work_queue->Size(); |
| 397 task_count += main_thread_only().delayed_incoming_queue.size(); | 397 task_count += main_thread_only().delayed_incoming_queue.size(); |
| 398 task_count += main_thread_only().immediate_work_queue->Size(); | 398 task_count += main_thread_only().immediate_work_queue->Size(); |
| 399 | 399 |
| 400 base::AutoLock lock(immediate_incoming_queue_lock_); | 400 base::AutoLock lock(immediate_incoming_queue_lock_); |
| 401 task_count += immediate_incoming_queue().size(); | 401 task_count += immediate_incoming_queue().size(); |
| 402 return task_count; | 402 return task_count; |
| 403 } | 403 } |
| 404 | 404 |
| 405 bool TaskQueueImpl::HasPendingImmediateWork() const { | 405 bool TaskQueueImpl::HasTaskToRunImmediately() const { |
| 406 // Any work queue tasks count as immediate work. | 406 // Any work queue tasks count as immediate work. |
| 407 if (!main_thread_only().delayed_work_queue->Empty() || | 407 if (!main_thread_only().delayed_work_queue->Empty() || |
| 408 !main_thread_only().immediate_work_queue->Empty()) { | 408 !main_thread_only().immediate_work_queue->Empty()) { |
| 409 return true; | 409 return true; |
| 410 } | 410 } |
| 411 | 411 |
| 412 // Tasks on |delayed_incoming_queue| that could run now, count as | 412 // Tasks on |delayed_incoming_queue| that could run now, count as |
| 413 // immediate work. | 413 // immediate work. |
| 414 if (!main_thread_only().delayed_incoming_queue.empty() && | 414 if (!main_thread_only().delayed_incoming_queue.empty() && |
| 415 main_thread_only().delayed_incoming_queue.top().delayed_run_time <= | 415 main_thread_only().delayed_incoming_queue.top().delayed_run_time <= |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 814 bool is_enabled = IsQueueEnabled(); | 814 bool is_enabled = IsQueueEnabled(); |
| 815 if (was_enabled != is_enabled) | 815 if (was_enabled != is_enabled) |
| 816 EnableOrDisableWithSelector(is_enabled); | 816 EnableOrDisableWithSelector(is_enabled); |
| 817 } | 817 } |
| 818 | 818 |
| 819 void TaskQueueImpl::EnableOrDisableWithSelector(bool enable) { | 819 void TaskQueueImpl::EnableOrDisableWithSelector(bool enable) { |
| 820 if (!main_thread_only().task_queue_manager) | 820 if (!main_thread_only().task_queue_manager) |
| 821 return; | 821 return; |
| 822 | 822 |
| 823 if (enable) { | 823 if (enable) { |
| 824 if (HasPendingImmediateWork()) | 824 if (HasPendingImmediateWork() && main_thread_only().observer) { |
| 825 NotifyWakeUpChangedOnMainThread(base::TimeTicks()); | 825 // Delayed work notification will be issued via time domain. |
| 826 main_thread_only().observer->OnQueueNextWakeUpChanged(this, | |
| 827 base::TimeTicks()); | |
| 828 } | |
| 826 | 829 |
| 827 ScheduleDelayedWorkInTimeDomain(main_thread_only().time_domain->Now()); | 830 ScheduleDelayedWorkInTimeDomain(main_thread_only().time_domain->Now()); |
| 828 | 831 |
| 829 // Note the selector calls TaskQueueManager::OnTaskQueueEnabled which posts | 832 // Note the selector calls TaskQueueManager::OnTaskQueueEnabled which posts |
| 830 // a DoWork if needed. | 833 // a DoWork if needed. |
| 831 main_thread_only().task_queue_manager->selector_.EnableQueue(this); | 834 main_thread_only().task_queue_manager->selector_.EnableQueue(this); |
| 832 } else { | 835 } else { |
| 833 if (!main_thread_only().delayed_incoming_queue.empty()) | 836 if (!main_thread_only().delayed_incoming_queue.empty()) |
| 834 main_thread_only().time_domain->CancelDelayedWork(this); | 837 main_thread_only().time_domain->CancelDelayedWork(this); |
| 835 main_thread_only().task_queue_manager->selector_.DisableQueue(this); | 838 main_thread_only().task_queue_manager->selector_.DisableQueue(this); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 892 | 895 |
| 893 void TaskQueueImpl::ScheduleDelayedWorkInTimeDomain(base::TimeTicks now) { | 896 void TaskQueueImpl::ScheduleDelayedWorkInTimeDomain(base::TimeTicks now) { |
| 894 if (!IsQueueEnabled()) | 897 if (!IsQueueEnabled()) |
| 895 return; | 898 return; |
| 896 if (main_thread_only().delayed_incoming_queue.empty()) | 899 if (main_thread_only().delayed_incoming_queue.empty()) |
| 897 return; | 900 return; |
| 898 | 901 |
| 899 main_thread_only().time_domain->ScheduleDelayedWork( | 902 main_thread_only().time_domain->ScheduleDelayedWork( |
| 900 this, main_thread_only().delayed_incoming_queue.top().delayed_wake_up(), | 903 this, main_thread_only().delayed_incoming_queue.top().delayed_wake_up(), |
| 901 now); | 904 now); |
| 902 | |
| 903 NotifyWakeUpChangedOnMainThread( | |
|
alex clarke (OOO till 29th)
2017/05/09 12:50:50
For my education, was this a bug since it looks li
altimin
2017/05/09 13:15:04
Yes, but strictly speaking this wasn't a real bug
| |
| 904 main_thread_only().delayed_incoming_queue.top().delayed_run_time); | |
| 905 } | 905 } |
| 906 | 906 |
| 907 void TaskQueueImpl::NotifyWakeUpChangedOnMainThread(base::TimeTicks wake_up) { | 907 void TaskQueueImpl::SetScheduledTimeDomainWakeUp( |
| 908 if (main_thread_only().observer) | 908 base::Optional<base::TimeTicks> scheduled_time_domain_wake_up) { |
| 909 main_thread_only().observer->OnQueueNextWakeUpChanged(this, wake_up); | 909 main_thread_only().scheduled_time_domain_wake_up = |
| 910 scheduled_time_domain_wake_up; | |
| 911 | |
| 912 if (!scheduled_time_domain_wake_up) | |
|
alex clarke (OOO till 29th)
2017/05/09 12:50:50
nit: Stylistically we tend to collapse all these o
altimin
2017/05/09 13:15:03
I think that in this case the conditions are diffe
alex clarke (OOO till 29th)
2017/05/09 19:18:42
One of the style guide rules is to be consistent w
altimin
2017/05/10 10:42:25
Done.
| |
| 913 return; | |
| 914 if (!main_thread_only().observer) | |
| 915 return; | |
| 916 // If queue has immediate work an appropriate notification has already | |
| 917 // been issued. | |
| 918 if (HasPendingImmediateWork()) | |
| 919 return; | |
| 920 | |
| 921 main_thread_only().observer->OnQueueNextWakeUpChanged( | |
| 922 this, scheduled_time_domain_wake_up.value()); | |
| 923 } | |
| 924 | |
| 925 bool TaskQueueImpl::HasPendingImmediateWork() { | |
| 926 // Any work queue tasks count as immediate work. | |
| 927 if (!main_thread_only().delayed_work_queue->Empty() || | |
| 928 !main_thread_only().immediate_work_queue->Empty()) { | |
| 929 return true; | |
| 930 } | |
| 931 | |
| 932 // Finally tasks on |immediate_incoming_queue| count as immediate work. | |
| 933 base::AutoLock lock(immediate_incoming_queue_lock_); | |
| 934 return !immediate_incoming_queue().empty(); | |
| 910 } | 935 } |
| 911 | 936 |
| 912 } // namespace internal | 937 } // namespace internal |
| 913 } // namespace scheduler | 938 } // namespace scheduler |
| 914 } // namespace blink | 939 } // namespace blink |
| OLD | NEW |