| 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 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 bool is_enabled = IsQueueEnabled(); | 796 bool is_enabled = IsQueueEnabled(); |
| 797 if (was_enabled != is_enabled) | 797 if (was_enabled != is_enabled) |
| 798 EnableOrDisableWithSelector(is_enabled); | 798 EnableOrDisableWithSelector(is_enabled); |
| 799 } | 799 } |
| 800 | 800 |
| 801 void TaskQueueImpl::EnableOrDisableWithSelector(bool enable) { | 801 void TaskQueueImpl::EnableOrDisableWithSelector(bool enable) { |
| 802 if (!main_thread_only().task_queue_manager) | 802 if (!main_thread_only().task_queue_manager) |
| 803 return; | 803 return; |
| 804 | 804 |
| 805 if (enable) { | 805 if (enable) { |
| 806 // Check if there's any immediate work on either queue. |
| 807 bool immediate_queues_empty = |
| 808 main_thread_only().immediate_work_queue->Empty(); |
| 809 if (immediate_queues_empty) { |
| 810 base::AutoLock lock(any_thread_lock_); |
| 811 immediate_queues_empty = any_thread().immediate_incoming_queue.empty(); |
| 812 } |
| 813 // Avoid holding the lock while we fire the notification. |
| 814 if (!immediate_queues_empty) |
| 815 main_thread_only().time_domain->OnQueueHasImmediateWork(this); |
| 816 |
| 806 if (!main_thread_only().delayed_incoming_queue.empty()) { | 817 if (!main_thread_only().delayed_incoming_queue.empty()) { |
| 807 main_thread_only().time_domain->ScheduleDelayedWork( | 818 main_thread_only().time_domain->ScheduleDelayedWork( |
| 808 this, | 819 this, |
| 809 main_thread_only().delayed_incoming_queue.top().delayed_run_time, | 820 main_thread_only().delayed_incoming_queue.top().delayed_run_time, |
| 810 main_thread_only().time_domain->Now()); | 821 main_thread_only().time_domain->Now()); |
| 811 } | 822 } |
| 812 // Note the selector calls TaskQueueManager::OnTaskQueueEnabled which posts | 823 // Note the selector calls TaskQueueManager::OnTaskQueueEnabled which posts |
| 813 // a DoWork if needed. | 824 // a DoWork if needed. |
| 814 main_thread_only().task_queue_manager->selector_.EnableQueue(this); | 825 main_thread_only().task_queue_manager->selector_.EnableQueue(this); |
| 815 } else { | 826 } else { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 | 872 |
| 862 void TaskQueueImpl::PushImmediateIncomingTaskForTest( | 873 void TaskQueueImpl::PushImmediateIncomingTaskForTest( |
| 863 TaskQueueImpl::Task&& task) { | 874 TaskQueueImpl::Task&& task) { |
| 864 base::AutoLock lock(any_thread_lock_); | 875 base::AutoLock lock(any_thread_lock_); |
| 865 any_thread().immediate_incoming_queue.push_back(std::move(task)); | 876 any_thread().immediate_incoming_queue.push_back(std::move(task)); |
| 866 } | 877 } |
| 867 | 878 |
| 868 } // namespace internal | 879 } // namespace internal |
| 869 } // namespace scheduler | 880 } // namespace scheduler |
| 870 } // namespace blink | 881 } // namespace blink |
| OLD | NEW |