| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 main_thread_only().time_domain->UnregisterQueue(this); | 170 main_thread_only().time_domain->UnregisterQueue(this); |
| 171 if (!any_thread().task_queue_manager) | 171 if (!any_thread().task_queue_manager) |
| 172 return; | 172 return; |
| 173 any_thread().time_domain = nullptr; | 173 any_thread().time_domain = nullptr; |
| 174 main_thread_only().time_domain = nullptr; | 174 main_thread_only().time_domain = nullptr; |
| 175 any_thread().task_queue_manager->UnregisterTaskQueue(this); | 175 any_thread().task_queue_manager->UnregisterTaskQueue(this); |
| 176 | 176 |
| 177 any_thread().task_queue_manager = nullptr; | 177 any_thread().task_queue_manager = nullptr; |
| 178 main_thread_only().task_queue_manager = nullptr; | 178 main_thread_only().task_queue_manager = nullptr; |
| 179 main_thread_only().delayed_incoming_queue = std::priority_queue<Task>(); | 179 main_thread_only().delayed_incoming_queue = std::priority_queue<Task>(); |
| 180 any_thread().immediate_incoming_queue = std::queue<Task>(); | 180 any_thread().immediate_incoming_queue.clear(); |
| 181 main_thread_only().immediate_work_queue.reset(); | 181 main_thread_only().immediate_work_queue.reset(); |
| 182 main_thread_only().delayed_work_queue.reset(); | 182 main_thread_only().delayed_work_queue.reset(); |
| 183 } | 183 } |
| 184 | 184 |
| 185 bool TaskQueueImpl::RunsTasksOnCurrentThread() const { | 185 bool TaskQueueImpl::RunsTasksOnCurrentThread() const { |
| 186 base::AutoLock lock(any_thread_lock_); | 186 base::AutoLock lock(any_thread_lock_); |
| 187 return base::PlatformThread::CurrentId() == thread_id_; | 187 return base::PlatformThread::CurrentId() == thread_id_; |
| 188 } | 188 } |
| 189 | 189 |
| 190 bool TaskQueueImpl::PostDelayedTask(const tracked_objects::Location& from_here, | 190 bool TaskQueueImpl::PostDelayedTask(const tracked_objects::Location& from_here, |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 if (any_thread().immediate_incoming_queue.empty()) { | 332 if (any_thread().immediate_incoming_queue.empty()) { |
| 333 // There's no point posting a DoWork for a disabled queue, however we can | 333 // There's no point posting a DoWork for a disabled queue, however we can |
| 334 // only tell if it's disabled from the main thread. | 334 // only tell if it's disabled from the main thread. |
| 335 if (base::PlatformThread::CurrentId() == thread_id_) { | 335 if (base::PlatformThread::CurrentId() == thread_id_) { |
| 336 if (IsQueueEnabled() && !BlockedByFenceLocked()) | 336 if (IsQueueEnabled() && !BlockedByFenceLocked()) |
| 337 any_thread().task_queue_manager->MaybeScheduleImmediateWork(FROM_HERE); | 337 any_thread().task_queue_manager->MaybeScheduleImmediateWork(FROM_HERE); |
| 338 } else { | 338 } else { |
| 339 any_thread().task_queue_manager->MaybeScheduleImmediateWork(FROM_HERE); | 339 any_thread().task_queue_manager->MaybeScheduleImmediateWork(FROM_HERE); |
| 340 } | 340 } |
| 341 } | 341 } |
| 342 any_thread().immediate_incoming_queue.emplace( | 342 any_thread().immediate_incoming_queue.emplace_back( |
| 343 posted_from, task, desired_run_time, sequence_number, nestable, sequence_n
umber); | 343 posted_from, task, desired_run_time, sequence_number, nestable, |
| 344 any_thread().task_queue_manager->DidQueueTask( any_thread().immediate_incoming
_queue.back()); | 344 sequence_number); |
| 345 any_thread().task_queue_manager->DidQueueTask( |
| 346 any_thread().immediate_incoming_queue.back()); |
| 345 TraceQueueSize(true); | 347 TraceQueueSize(true); |
| 346 } | 348 } |
| 347 | 349 |
| 348 bool TaskQueueImpl::IsEmpty() const { | 350 bool TaskQueueImpl::IsEmpty() const { |
| 349 if (!main_thread_only().delayed_work_queue->Empty() || | 351 if (!main_thread_only().delayed_work_queue->Empty() || |
| 350 !main_thread_only().delayed_incoming_queue.empty() || | 352 !main_thread_only().delayed_incoming_queue.empty() || |
| 351 !main_thread_only().immediate_work_queue->Empty()) { | 353 !main_thread_only().immediate_work_queue->Empty()) { |
| 352 return false; | 354 return false; |
| 353 } | 355 } |
| 354 | 356 |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 | 686 |
| 685 return any_thread().immediate_incoming_queue.front().enqueue_order() > | 687 return any_thread().immediate_incoming_queue.front().enqueue_order() > |
| 686 main_thread_only().current_fence; | 688 main_thread_only().current_fence; |
| 687 } | 689 } |
| 688 | 690 |
| 689 EnqueueOrder TaskQueueImpl::GetFenceForTest() const { | 691 EnqueueOrder TaskQueueImpl::GetFenceForTest() const { |
| 690 return main_thread_only().current_fence; | 692 return main_thread_only().current_fence; |
| 691 } | 693 } |
| 692 | 694 |
| 693 // static | 695 // static |
| 694 void TaskQueueImpl::QueueAsValueInto(const std::queue<Task>& queue, | 696 void TaskQueueImpl::QueueAsValueInto(const WTF::Deque<Task>& queue, |
| 695 base::trace_event::TracedValue* state) { | 697 base::trace_event::TracedValue* state) { |
| 696 // Remove const to search |queue| in the destructive manner. Restore the | 698 for (const Task& task : queue) { |
| 697 // content from |visited| later. | 699 TaskAsValueInto(task, state); |
| 698 std::queue<Task>* mutable_queue = const_cast<std::queue<Task>*>(&queue); | |
| 699 std::queue<Task> visited; | |
| 700 while (!mutable_queue->empty()) { | |
| 701 TaskAsValueInto(mutable_queue->front(), state); | |
| 702 visited.push(std::move(mutable_queue->front())); | |
| 703 mutable_queue->pop(); | |
| 704 } | 700 } |
| 705 *mutable_queue = std::move(visited); | |
| 706 } | 701 } |
| 707 | 702 |
| 708 // static | 703 // static |
| 709 void TaskQueueImpl::QueueAsValueInto(const std::priority_queue<Task>& queue, | 704 void TaskQueueImpl::QueueAsValueInto(const std::priority_queue<Task>& queue, |
| 710 base::trace_event::TracedValue* state) { | 705 base::trace_event::TracedValue* state) { |
| 711 // Remove const to search |queue| in the destructive manner. Restore the | 706 // Remove const to search |queue| in the destructive manner. Restore the |
| 712 // content from |visited| later. | 707 // content from |visited| later. |
| 713 std::priority_queue<Task>* mutable_queue = | 708 std::priority_queue<Task>* mutable_queue = |
| 714 const_cast<std::priority_queue<Task>*>(&queue); | 709 const_cast<std::priority_queue<Task>*>(&queue); |
| 715 std::priority_queue<Task> visited; | 710 std::priority_queue<Task> visited; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 std::unique_ptr<TaskQueueImpl::QueueEnabledVoter> | 810 std::unique_ptr<TaskQueueImpl::QueueEnabledVoter> |
| 816 TaskQueueImpl::CreateQueueEnabledVoter() { | 811 TaskQueueImpl::CreateQueueEnabledVoter() { |
| 817 main_thread_only().voter_refcount++; | 812 main_thread_only().voter_refcount++; |
| 818 main_thread_only().is_enabled_refcount++; | 813 main_thread_only().is_enabled_refcount++; |
| 819 return base::MakeUnique<QueueEnabledVoterImpl>(this); | 814 return base::MakeUnique<QueueEnabledVoterImpl>(this); |
| 820 } | 815 } |
| 821 | 816 |
| 822 } // namespace internal | 817 } // namespace internal |
| 823 } // namespace scheduler | 818 } // namespace scheduler |
| 824 } // namespace blink | 819 } // namespace blink |
| OLD | NEW |