Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Side by Side Diff: third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.cc

Issue 2533603002: [scheduler] Add options to TaskQueue::InsertFence (Closed)
Patch Set: More nits Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/trace_event/blame_context.h" 9 #include "base/trace_event/blame_context.h"
10 #include "platform/scheduler/base/task_queue_manager.h" 10 #include "platform/scheduler/base/task_queue_manager.h"
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 604
605 base::AutoLock lock(any_thread_lock_); 605 base::AutoLock lock(any_thread_lock_);
606 return any_thread().time_domain; 606 return any_thread().time_domain;
607 } 607 }
608 608
609 void TaskQueueImpl::SetBlameContext( 609 void TaskQueueImpl::SetBlameContext(
610 base::trace_event::BlameContext* blame_context) { 610 base::trace_event::BlameContext* blame_context) {
611 main_thread_only().blame_context = blame_context; 611 main_thread_only().blame_context = blame_context;
612 } 612 }
613 613
614 void TaskQueueImpl::InsertFence() { 614 void TaskQueueImpl::InsertFence(TaskQueue::InsertFencePosition position) {
615 if (!main_thread_only().task_queue_manager) 615 if (!main_thread_only().task_queue_manager)
616 return; 616 return;
617 617
618 EnqueueOrder previous_fence = main_thread_only().current_fence; 618 EnqueueOrder previous_fence = main_thread_only().current_fence;
619 main_thread_only().current_fence = 619 main_thread_only().current_fence =
620 main_thread_only().task_queue_manager->GetNextSequenceNumber(); 620 position == TaskQueue::InsertFencePosition::NOW
621 ? main_thread_only().task_queue_manager->GetNextSequenceNumber()
622 : static_cast<EnqueueOrder>(EnqueueOrderValues::BLOCKING_FENCE);
621 623
622 // Tasks posted after this point will have a strictly higher enqueue order 624 // Tasks posted after this point will have a strictly higher enqueue order
623 // and will be blocked from running. 625 // and will be blocked from running.
624 bool task_unblocked = main_thread_only().immediate_work_queue->InsertFence( 626 bool task_unblocked = main_thread_only().immediate_work_queue->InsertFence(
625 main_thread_only().current_fence); 627 main_thread_only().current_fence);
626 task_unblocked |= main_thread_only().delayed_work_queue->InsertFence( 628 task_unblocked |= main_thread_only().delayed_work_queue->InsertFence(
627 main_thread_only().current_fence); 629 main_thread_only().current_fence);
628 630
629 if (!task_unblocked && previous_fence) { 631 if (!task_unblocked && previous_fence &&
632 previous_fence < main_thread_only().current_fence) {
630 base::AutoLock lock(any_thread_lock_); 633 base::AutoLock lock(any_thread_lock_);
631 if (!any_thread().immediate_incoming_queue.empty() && 634 if (!any_thread().immediate_incoming_queue.empty() &&
632 any_thread().immediate_incoming_queue.front().enqueue_order() > 635 any_thread().immediate_incoming_queue.front().enqueue_order() >
633 previous_fence && 636 previous_fence &&
634 any_thread().immediate_incoming_queue.front().enqueue_order() < 637 any_thread().immediate_incoming_queue.front().enqueue_order() <
635 main_thread_only().current_fence) { 638 main_thread_only().current_fence) {
636 task_unblocked = true; 639 task_unblocked = true;
637 } 640 }
638 } 641 }
639 642
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 return false; 697 return false;
695 } 698 }
696 699
697 if (any_thread().immediate_incoming_queue.empty()) 700 if (any_thread().immediate_incoming_queue.empty())
698 return true; 701 return true;
699 702
700 return any_thread().immediate_incoming_queue.front().enqueue_order() > 703 return any_thread().immediate_incoming_queue.front().enqueue_order() >
701 main_thread_only().current_fence; 704 main_thread_only().current_fence;
702 } 705 }
703 706
707 EnqueueOrder TaskQueueImpl::GetFenceForTest() const {
708 return main_thread_only().current_fence;
709 }
710
704 // static 711 // static
705 void TaskQueueImpl::QueueAsValueInto(const std::queue<Task>& queue, 712 void TaskQueueImpl::QueueAsValueInto(const std::queue<Task>& queue,
706 base::trace_event::TracedValue* state) { 713 base::trace_event::TracedValue* state) {
707 // Remove const to search |queue| in the destructive manner. Restore the 714 // Remove const to search |queue| in the destructive manner. Restore the
708 // content from |visited| later. 715 // content from |visited| later.
709 std::queue<Task>* mutable_queue = const_cast<std::queue<Task>*>(&queue); 716 std::queue<Task>* mutable_queue = const_cast<std::queue<Task>*>(&queue);
710 std::queue<Task> visited; 717 std::queue<Task> visited;
711 while (!mutable_queue->empty()) { 718 while (!mutable_queue->empty()) {
712 TaskAsValueInto(mutable_queue->front(), state); 719 TaskAsValueInto(mutable_queue->front(), state);
713 visited.push(std::move(mutable_queue->front())); 720 visited.push(std::move(mutable_queue->front()));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 state->SetBoolean("is_cancelled", task.task.IsCancelled()); 756 state->SetBoolean("is_cancelled", task.task.IsCancelled());
750 state->SetDouble( 757 state->SetDouble(
751 "delayed_run_time", 758 "delayed_run_time",
752 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L); 759 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L);
753 state->EndDictionary(); 760 state->EndDictionary();
754 } 761 }
755 762
756 } // namespace internal 763 } // namespace internal
757 } // namespace scheduler 764 } // namespace scheduler
758 } // namespace blink 765 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698