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 "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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 } | 320 } |
| 321 TraceQueueSize(false); | 321 TraceQueueSize(false); |
| 322 } | 322 } |
| 323 | 323 |
| 324 void TaskQueueImpl::PushOntoImmediateIncomingQueueLocked( | 324 void TaskQueueImpl::PushOntoImmediateIncomingQueueLocked( |
| 325 const tracked_objects::Location& posted_from, | 325 const tracked_objects::Location& posted_from, |
| 326 const base::Closure& task, | 326 const base::Closure& task, |
| 327 base::TimeTicks desired_run_time, | 327 base::TimeTicks desired_run_time, |
| 328 EnqueueOrder sequence_number, | 328 EnqueueOrder sequence_number, |
| 329 bool nestable) { | 329 bool nestable) { |
| 330 if (any_thread().immediate_incoming_queue.empty()) | |
| 331 any_thread().time_domain->OnQueueHasIncomingImmediateWork(this); | |
| 332 // If the |immediate_incoming_queue| is empty we need a DoWork posted to make | 330 // If the |immediate_incoming_queue| is empty we need a DoWork posted to make |
| 333 // it run. | 331 // it run. |
| 334 if (any_thread().immediate_incoming_queue.empty()) { | 332 if (any_thread().immediate_incoming_queue.empty()) { |
| 335 // There's no point posting a DoWork for a disabled queue, however we can | 333 // However there's no point posting a DoWork for a disabled queue. NB we can |
| 336 // only tell if it's disabled from the main thread. | 334 // only tell if it's disabled from the main thread. |
| 337 if (base::PlatformThread::CurrentId() == thread_id_) { | 335 bool ensure_do_work_posted = |
|
Sami
2017/01/24 14:52:40
To separate the concerns a bit, how about calling
alex clarke (OOO till 29th)
2017/01/24 15:28:14
I suppose task_currently_blocked?
| |
| 338 if (IsQueueEnabled() && !BlockedByFenceLocked()) | 336 !RunsTasksOnCurrentThread() || |
| 339 any_thread().task_queue_manager->MaybeScheduleImmediateWork(FROM_HERE); | 337 (IsQueueEnabled() && !main_thread_only().current_fence); |
| 340 } else { | 338 any_thread().task_queue_manager->OnQueueHasIncomingImmediateWork( |
| 341 any_thread().task_queue_manager->MaybeScheduleImmediateWork(FROM_HERE); | 339 this, ensure_do_work_posted); |
| 342 } | 340 any_thread().time_domain->OnQueueHasImmediateWork(this); |
| 343 } | 341 } |
| 344 any_thread().immediate_incoming_queue.emplace_back( | 342 any_thread().immediate_incoming_queue.emplace_back( |
| 345 posted_from, task, desired_run_time, sequence_number, nestable, | 343 posted_from, task, desired_run_time, sequence_number, nestable, |
| 346 sequence_number); | 344 sequence_number); |
| 347 any_thread().task_queue_manager->DidQueueTask( | 345 any_thread().task_queue_manager->DidQueueTask( |
| 348 any_thread().immediate_incoming_queue.back()); | 346 any_thread().immediate_incoming_queue.back()); |
| 349 TraceQueueSize(true); | 347 TraceQueueSize(true); |
| 350 } | 348 } |
| 351 | 349 |
| 352 void TaskQueueImpl::ReloadImmediateWorkQueueIfEmpty() { | 350 void TaskQueueImpl::ReloadImmediateWorkQueueIfEmpty() { |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 667 } | 665 } |
| 668 | 666 |
| 669 base::AutoLock lock(any_thread_lock_); | 667 base::AutoLock lock(any_thread_lock_); |
| 670 if (any_thread().immediate_incoming_queue.empty()) | 668 if (any_thread().immediate_incoming_queue.empty()) |
| 671 return true; | 669 return true; |
| 672 | 670 |
| 673 return any_thread().immediate_incoming_queue.front().enqueue_order() > | 671 return any_thread().immediate_incoming_queue.front().enqueue_order() > |
| 674 main_thread_only().current_fence; | 672 main_thread_only().current_fence; |
| 675 } | 673 } |
| 676 | 674 |
| 677 bool TaskQueueImpl::BlockedByFenceLocked() const { | 675 bool TaskQueueImpl::ImmediateTaskCouldRun() const { |
| 678 if (!main_thread_only().current_fence) | 676 if (!IsQueueEnabled()) |
| 679 return false; | 677 return false; |
| 680 | 678 |
| 681 if (!main_thread_only().immediate_work_queue->BlockedByFence() || | 679 if (!main_thread_only().current_fence) |
| 682 !main_thread_only().delayed_work_queue->BlockedByFence()) { | |
| 683 return false; | |
| 684 } | |
| 685 | |
| 686 if (any_thread().immediate_incoming_queue.empty()) | |
| 687 return true; | 680 return true; |
| 688 | 681 |
| 689 return any_thread().immediate_incoming_queue.front().enqueue_order() > | 682 if (!main_thread_only().immediate_work_queue->Empty()) |
| 683 return !main_thread_only().immediate_work_queue->BlockedByFence(); | |
| 684 | |
| 685 base::AutoLock lock(any_thread_lock_); | |
| 686 // If |immediate_incoming_queue| and |immediate_work_queue| are empty then any | |
| 687 // task posted is guaranteed to be blocked by the fence. | |
| 688 if (any_thread().immediate_incoming_queue.empty()) | |
| 689 return false; | |
| 690 | |
| 691 return any_thread().immediate_incoming_queue.front().enqueue_order() < | |
| 690 main_thread_only().current_fence; | 692 main_thread_only().current_fence; |
| 691 } | 693 } |
| 692 | 694 |
| 693 EnqueueOrder TaskQueueImpl::GetFenceForTest() const { | 695 EnqueueOrder TaskQueueImpl::GetFenceForTest() const { |
| 694 return main_thread_only().current_fence; | 696 return main_thread_only().current_fence; |
| 695 } | 697 } |
| 696 | 698 |
| 697 // static | 699 // static |
| 698 void TaskQueueImpl::QueueAsValueInto(const WTF::Deque<Task>& queue, | 700 void TaskQueueImpl::QueueAsValueInto(const WTF::Deque<Task>& queue, |
| 699 base::trace_event::TracedValue* state) { | 701 base::trace_event::TracedValue* state) { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 848 | 850 |
| 849 void TaskQueueImpl::PushImmediateIncomingTaskForTest( | 851 void TaskQueueImpl::PushImmediateIncomingTaskForTest( |
| 850 TaskQueueImpl::Task&& task) { | 852 TaskQueueImpl::Task&& task) { |
| 851 base::AutoLock lock(any_thread_lock_); | 853 base::AutoLock lock(any_thread_lock_); |
| 852 any_thread().immediate_incoming_queue.push_back(std::move(task)); | 854 any_thread().immediate_incoming_queue.push_back(std::move(task)); |
| 853 } | 855 } |
| 854 | 856 |
| 855 } // namespace internal | 857 } // namespace internal |
| 856 } // namespace scheduler | 858 } // namespace scheduler |
| 857 } // namespace blink | 859 } // namespace blink |
| OLD | NEW |