| 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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 507       !main_thread_only().immediate_work_queue->Empty()) { | 507       !main_thread_only().immediate_work_queue->Empty()) { | 
| 508     return false; | 508     return false; | 
| 509   } | 509   } | 
| 510 | 510 | 
| 511   base::AutoLock lock(any_thread_lock_); | 511   base::AutoLock lock(any_thread_lock_); | 
| 512   return any_thread().immediate_incoming_queue.empty() && | 512   return any_thread().immediate_incoming_queue.empty() && | 
| 513          main_thread_only().delayed_incoming_queue.empty(); | 513          main_thread_only().delayed_incoming_queue.empty(); | 
| 514 } | 514 } | 
| 515 | 515 | 
| 516 bool TaskQueueImpl::HasPendingImmediateWork() const { | 516 bool TaskQueueImpl::HasPendingImmediateWork() const { | 
|  | 517   LazyNow lazy_now = main_thread_only().time_domain->CreateLazyNow(); | 
|  | 518   return HasPendingImmediateWork(&lazy_now); | 
|  | 519 } | 
|  | 520 | 
|  | 521 bool TaskQueueImpl::HasPendingImmediateWork(LazyNow* lazy_now) const { | 
| 517   // Any work queue tasks count as immediate work. | 522   // Any work queue tasks count as immediate work. | 
| 518   if (!main_thread_only().delayed_work_queue->Empty() || | 523   if (!main_thread_only().delayed_work_queue->Empty() || | 
| 519       !main_thread_only().immediate_work_queue->Empty()) { | 524       !main_thread_only().immediate_work_queue->Empty()) { | 
| 520     return true; | 525     return true; | 
| 521   } | 526   } | 
| 522 | 527 | 
| 523   // Tasks on |delayed_incoming_queue| that could run now, count as | 528   // Tasks on |delayed_incoming_queue| that could run now, count as | 
| 524   // immediate work. | 529   // immediate work. | 
| 525   if (!main_thread_only().delayed_incoming_queue.empty() && | 530   if (!main_thread_only().delayed_incoming_queue.empty() && | 
| 526       main_thread_only().delayed_incoming_queue.begin()->delayed_run_time <= | 531       main_thread_only().delayed_incoming_queue.begin()->delayed_run_time <= | 
| 527           main_thread_only().time_domain->CreateLazyNow().Now()) { | 532           lazy_now->Now()) { | 
| 528     return true; | 533     return true; | 
| 529   } | 534   } | 
| 530 | 535 | 
| 531   // Finally tasks on |immediate_incoming_queue| count as immediate work. | 536   // Finally tasks on |immediate_incoming_queue| count as immediate work. | 
| 532   base::AutoLock lock(any_thread_lock_); | 537   base::AutoLock lock(any_thread_lock_); | 
| 533   return !any_thread().immediate_incoming_queue.empty(); | 538   return !any_thread().immediate_incoming_queue.empty(); | 
| 534 } | 539 } | 
| 535 | 540 | 
|  | 541 base::Optional<base::TimeTicks> TaskQueueImpl::GetNextScheduledWakeUp() { | 
|  | 542   LazyNow lazy_now = main_thread_only().time_domain->CreateLazyNow(); | 
|  | 543   MoveReadyDelayedTasksToDelayedWorkQueue(&lazy_now); | 
|  | 544 | 
|  | 545   if (main_thread_only().delayed_incoming_queue.empty()) | 
|  | 546     return base::nullopt; | 
|  | 547 | 
|  | 548   return main_thread_only().delayed_incoming_queue.begin()->delayed_run_time; | 
|  | 549 } | 
|  | 550 | 
|  | 551 base::Optional<base::TimeTicks> TaskQueueImpl::GetNextTaskRunTime() { | 
|  | 552   LazyNow lazy_now = main_thread_only().time_domain->CreateLazyNow(); | 
|  | 553   MoveReadyDelayedTasksToDelayedWorkQueue(&lazy_now); | 
|  | 554 | 
|  | 555   if (HasPendingImmediateWork()) | 
|  | 556     return lazy_now.Now(); | 
|  | 557 | 
|  | 558   return GetNextScheduledWakeUp(); | 
|  | 559 } | 
|  | 560 | 
| 536 void TaskQueueImpl::MoveReadyDelayedTasksToDelayedWorkQueue(LazyNow* lazy_now) { | 561 void TaskQueueImpl::MoveReadyDelayedTasksToDelayedWorkQueue(LazyNow* lazy_now) { | 
| 537   // Enqueue all delayed tasks that should be running now. | 562   // Enqueue all delayed tasks that should be running now. | 
| 538   while (!main_thread_only().delayed_incoming_queue.empty()) { | 563   while (!main_thread_only().delayed_incoming_queue.empty()) { | 
| 539     DelayedRunTimeQueue::iterator next_task = | 564     DelayedRunTimeQueue::iterator next_task = | 
| 540         main_thread_only().delayed_incoming_queue.begin(); | 565         main_thread_only().delayed_incoming_queue.begin(); | 
| 541     if (next_task->delayed_run_time > lazy_now->Now()) | 566     if (next_task->delayed_run_time > lazy_now->Now()) | 
| 542       break; | 567       break; | 
| 543     // TODO(alexclarke): Use extract() when C++17 is allowed. | 568     // TODO(alexclarke): Use extract() when C++17 is allowed. | 
| 544     Task& task = const_cast<Task&>(*next_task); | 569     Task& task = const_cast<Task&>(*next_task); | 
| 545     task.set_enqueue_order( | 570     task.set_enqueue_order( | 
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 857   state->SetBoolean("is_high_res", task.is_high_res); | 882   state->SetBoolean("is_high_res", task.is_high_res); | 
| 858   state->SetDouble( | 883   state->SetDouble( | 
| 859       "delayed_run_time", | 884       "delayed_run_time", | 
| 860       (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L); | 885       (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L); | 
| 861   state->EndDictionary(); | 886   state->EndDictionary(); | 
| 862 } | 887 } | 
| 863 | 888 | 
| 864 }  // namespace internal | 889 }  // namespace internal | 
| 865 }  // namespace scheduler | 890 }  // namespace scheduler | 
| 866 }  // namespace blink | 891 }  // namespace blink | 
| OLD | NEW | 
|---|