| 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/trace_event/blame_context.h" | 7 #include "base/trace_event/blame_context.h" |
| 8 #include "platform/scheduler/base/task_queue_manager.h" | 8 #include "platform/scheduler/base/task_queue_manager.h" |
| 9 #include "platform/scheduler/base/task_queue_manager_delegate.h" | 9 #include "platform/scheduler/base/task_queue_manager_delegate.h" |
| 10 #include "platform/scheduler/base/time_domain.h" | 10 #include "platform/scheduler/base/time_domain.h" |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 | 598 |
| 599 base::AutoLock lock(any_thread_lock_); | 599 base::AutoLock lock(any_thread_lock_); |
| 600 return any_thread().time_domain; | 600 return any_thread().time_domain; |
| 601 } | 601 } |
| 602 | 602 |
| 603 void TaskQueueImpl::SetBlameContext( | 603 void TaskQueueImpl::SetBlameContext( |
| 604 base::trace_event::BlameContext* blame_context) { | 604 base::trace_event::BlameContext* blame_context) { |
| 605 main_thread_only().blame_context = blame_context; | 605 main_thread_only().blame_context = blame_context; |
| 606 } | 606 } |
| 607 | 607 |
| 608 void TaskQueueImpl::InsertFence() { | 608 void TaskQueueImpl::InsertFence(TaskQueue::InsertFencePosition position) { |
| 609 if (!main_thread_only().task_queue_manager) | 609 if (!main_thread_only().task_queue_manager) |
| 610 return; | 610 return; |
| 611 | 611 |
| 612 EnqueueOrder previous_fence = main_thread_only().current_fence; | 612 EnqueueOrder previous_fence = main_thread_only().current_fence; |
| 613 main_thread_only().current_fence = | 613 main_thread_only().current_fence = |
| 614 main_thread_only().task_queue_manager->GetNextSequenceNumber(); | 614 position == TaskQueue::InsertFencePosition::NOW |
| 615 ? main_thread_only().task_queue_manager->GetNextSequenceNumber() |
| 616 : static_cast<EnqueueOrder>(EnqueueOrderValues::BLOCKING_FENCE); |
| 615 | 617 |
| 616 // Tasks posted after this point will have a strictly higher enqueue order | 618 // Tasks posted after this point will have a strictly higher enqueue order |
| 617 // and will be blocked from running. | 619 // and will be blocked from running. |
| 618 bool task_unblocked = main_thread_only().immediate_work_queue->InsertFence( | 620 bool task_unblocked = main_thread_only().immediate_work_queue->InsertFence( |
| 619 main_thread_only().current_fence); | 621 main_thread_only().current_fence); |
| 620 task_unblocked |= main_thread_only().delayed_work_queue->InsertFence( | 622 task_unblocked |= main_thread_only().delayed_work_queue->InsertFence( |
| 621 main_thread_only().current_fence); | 623 main_thread_only().current_fence); |
| 622 | 624 |
| 623 if (!task_unblocked && previous_fence) { | 625 if (!task_unblocked && previous_fence && |
| 626 previous_fence < main_thread_only().current_fence) { |
| 624 base::AutoLock lock(any_thread_lock_); | 627 base::AutoLock lock(any_thread_lock_); |
| 625 if (!any_thread().immediate_incoming_queue.empty() && | 628 if (!any_thread().immediate_incoming_queue.empty() && |
| 626 any_thread().immediate_incoming_queue.front().enqueue_order() > | 629 any_thread().immediate_incoming_queue.front().enqueue_order() > |
| 627 previous_fence && | 630 previous_fence && |
| 628 any_thread().immediate_incoming_queue.front().enqueue_order() < | 631 any_thread().immediate_incoming_queue.front().enqueue_order() < |
| 629 main_thread_only().current_fence) { | 632 main_thread_only().current_fence) { |
| 630 task_unblocked = true; | 633 task_unblocked = true; |
| 631 } | 634 } |
| 632 } | 635 } |
| 633 | 636 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 return false; | 691 return false; |
| 689 } | 692 } |
| 690 | 693 |
| 691 if (any_thread().immediate_incoming_queue.empty()) | 694 if (any_thread().immediate_incoming_queue.empty()) |
| 692 return true; | 695 return true; |
| 693 | 696 |
| 694 return any_thread().immediate_incoming_queue.front().enqueue_order() > | 697 return any_thread().immediate_incoming_queue.front().enqueue_order() > |
| 695 main_thread_only().current_fence; | 698 main_thread_only().current_fence; |
| 696 } | 699 } |
| 697 | 700 |
| 701 EnqueueOrder TaskQueueImpl::GetFenceForTest() const { |
| 702 return main_thread_only().current_fence; |
| 703 } |
| 704 |
| 698 // static | 705 // static |
| 699 void TaskQueueImpl::QueueAsValueInto(const std::queue<Task>& queue, | 706 void TaskQueueImpl::QueueAsValueInto(const std::queue<Task>& queue, |
| 700 base::trace_event::TracedValue* state) { | 707 base::trace_event::TracedValue* state) { |
| 701 // Remove const to search |queue| in the destructive manner. Restore the | 708 // Remove const to search |queue| in the destructive manner. Restore the |
| 702 // content from |visited| later. | 709 // content from |visited| later. |
| 703 std::queue<Task>* mutable_queue = const_cast<std::queue<Task>*>(&queue); | 710 std::queue<Task>* mutable_queue = const_cast<std::queue<Task>*>(&queue); |
| 704 std::queue<Task> visited; | 711 std::queue<Task> visited; |
| 705 while (!mutable_queue->empty()) { | 712 while (!mutable_queue->empty()) { |
| 706 TaskAsValueInto(mutable_queue->front(), state); | 713 TaskAsValueInto(mutable_queue->front(), state); |
| 707 visited.push(std::move(mutable_queue->front())); | 714 visited.push(std::move(mutable_queue->front())); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 state->SetBoolean("is_cancelled", task.task.IsCancelled()); | 750 state->SetBoolean("is_cancelled", task.task.IsCancelled()); |
| 744 state->SetDouble( | 751 state->SetDouble( |
| 745 "delayed_run_time", | 752 "delayed_run_time", |
| 746 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L); | 753 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L); |
| 747 state->EndDictionary(); | 754 state->EndDictionary(); |
| 748 } | 755 } |
| 749 | 756 |
| 750 } // namespace internal | 757 } // namespace internal |
| 751 } // namespace scheduler | 758 } // namespace scheduler |
| 752 } // namespace blink | 759 } // namespace blink |
| OLD | NEW |