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

Side by Side Diff: components/scheduler/base/task_queue_impl.cc

Issue 2155143002: Fix a bug that could occasionaly cause setInterval to stop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed ThrottledTimeDomain to be based on RealTimeDomain Created 4 years, 5 months 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 "components/scheduler/base/task_queue_impl.h" 5 #include "components/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 "components/scheduler/base/task_queue_manager.h" 8 #include "components/scheduler/base/task_queue_manager.h"
9 #include "components/scheduler/base/task_queue_manager_delegate.h" 9 #include "components/scheduler/base/task_queue_manager_delegate.h"
10 #include "components/scheduler/base/time_domain.h" 10 #include "components/scheduler/base/time_domain.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 DCHECK_GT(delay, base::TimeDelta()); 182 DCHECK_GT(delay, base::TimeDelta());
183 if (base::PlatformThread::CurrentId() == thread_id_) { 183 if (base::PlatformThread::CurrentId() == thread_id_) {
184 // Lock-free fast path for delayed tasks posted from the main thread. 184 // Lock-free fast path for delayed tasks posted from the main thread.
185 if (!main_thread_only().task_queue_manager) 185 if (!main_thread_only().task_queue_manager)
186 return false; 186 return false;
187 187
188 EnqueueOrder sequence_number = 188 EnqueueOrder sequence_number =
189 main_thread_only().task_queue_manager->GetNextSequenceNumber(); 189 main_thread_only().task_queue_manager->GetNextSequenceNumber();
190 190
191 base::TimeTicks time_domain_now = main_thread_only().time_domain->Now(); 191 base::TimeTicks time_domain_now = main_thread_only().time_domain->Now();
192 base::TimeTicks time_domain_delayed_run_time = 192 base::TimeTicks time_domain_delayed_run_time = time_domain_now + delay;
193 main_thread_only().time_domain->ComputeDelayedRunTime(time_domain_now,
194 delay);
195 PushOntoDelayedIncomingQueueFromMainThread( 193 PushOntoDelayedIncomingQueueFromMainThread(
196 Task(from_here, task, time_domain_delayed_run_time, sequence_number, 194 Task(from_here, task, time_domain_delayed_run_time, sequence_number,
197 task_type != TaskType::NON_NESTABLE), 195 task_type != TaskType::NON_NESTABLE),
198 time_domain_now); 196 time_domain_now);
199 } else { 197 } else {
200 // NOTE posting a delayed task from a different thread is not expected to 198 // NOTE posting a delayed task from a different thread is not expected to
201 // be common. This pathway is less optimal than perhaps it could be 199 // be common. This pathway is less optimal than perhaps it could be
202 // because it causes two main thread tasks to be run. Should this 200 // because it causes two main thread tasks to be run. Should this
203 // assumption prove to be false in future, we may need to revisit this. 201 // assumption prove to be false in future, we may need to revisit this.
204 base::AutoLock lock(any_thread_lock_); 202 base::AutoLock lock(any_thread_lock_);
205 if (!any_thread().task_queue_manager) 203 if (!any_thread().task_queue_manager)
206 return false; 204 return false;
207 205
208 EnqueueOrder sequence_number = 206 EnqueueOrder sequence_number =
209 any_thread().task_queue_manager->GetNextSequenceNumber(); 207 any_thread().task_queue_manager->GetNextSequenceNumber();
210 208
211 base::TimeTicks time_domain_now = any_thread().time_domain->Now(); 209 base::TimeTicks time_domain_now = any_thread().time_domain->Now();
212 base::TimeTicks time_domain_delayed_run_time = 210 base::TimeTicks time_domain_delayed_run_time = time_domain_now + delay;
213 any_thread().time_domain->ComputeDelayedRunTime(time_domain_now, delay);
214 PushOntoDelayedIncomingQueueLocked( 211 PushOntoDelayedIncomingQueueLocked(
215 Task(from_here, task, time_domain_delayed_run_time, sequence_number, 212 Task(from_here, task, time_domain_delayed_run_time, sequence_number,
216 task_type != TaskType::NON_NESTABLE)); 213 task_type != TaskType::NON_NESTABLE));
217 } 214 }
218 return true; 215 return true;
219 } 216 }
220 217
221 void TaskQueueImpl::PushOntoDelayedIncomingQueueFromMainThread( 218 void TaskQueueImpl::PushOntoDelayedIncomingQueueFromMainThread(
222 Task pending_task, 219 Task pending_task,
223 base::TimeTicks now) { 220 base::TimeTicks now) {
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 main_thread_only().delayed_work_queue->Size() + 440 main_thread_only().delayed_work_queue->Size() +
444 main_thread_only().delayed_incoming_queue.size()); 441 main_thread_only().delayed_incoming_queue.size());
445 if (!is_locked) 442 if (!is_locked)
446 any_thread_lock_.Release(); 443 any_thread_lock_.Release();
447 } 444 }
448 445
449 void TaskQueueImpl::SetPumpPolicy(PumpPolicy pump_policy) { 446 void TaskQueueImpl::SetPumpPolicy(PumpPolicy pump_policy) {
450 base::AutoLock lock(any_thread_lock_); 447 base::AutoLock lock(any_thread_lock_);
451 if (pump_policy == PumpPolicy::AUTO && 448 if (pump_policy == PumpPolicy::AUTO &&
452 any_thread().pump_policy != PumpPolicy::AUTO) { 449 any_thread().pump_policy != PumpPolicy::AUTO) {
453 PumpQueueLocked(true); 450 LazyNow lazy_now(main_thread_only().time_domain->CreateLazyNow());
rmcilroy 2016/07/18 15:22:57 Just out of interest, wondering why this LazyNow c
alex clarke (OOO till 29th) 2016/07/18 15:35:52 There could be many throttled task queues, and Thr
rmcilroy 2016/07/18 16:01:42 I see, makes sense, thanks.
451 PumpQueueLocked(&lazy_now, true);
454 } 452 }
455 any_thread().pump_policy = pump_policy; 453 any_thread().pump_policy = pump_policy;
456 main_thread_only().pump_policy = pump_policy; 454 main_thread_only().pump_policy = pump_policy;
457 } 455 }
458 456
459 TaskQueue::PumpPolicy TaskQueueImpl::GetPumpPolicy() const { 457 TaskQueue::PumpPolicy TaskQueueImpl::GetPumpPolicy() const {
460 return main_thread_only().pump_policy; 458 return main_thread_only().pump_policy;
461 } 459 }
462 460
463 void TaskQueueImpl::PumpQueueLocked(bool may_post_dowork) { 461 void TaskQueueImpl::PumpQueueLocked(LazyNow* lazy_now, bool may_post_dowork) {
464 TRACE_EVENT1(disabled_by_default_tracing_category_, 462 TRACE_EVENT1(disabled_by_default_tracing_category_,
465 "TaskQueueImpl::PumpQueueLocked", "queue", name_); 463 "TaskQueueImpl::PumpQueueLocked", "queue", name_);
466 TaskQueueManager* task_queue_manager = any_thread().task_queue_manager; 464 TaskQueueManager* task_queue_manager = any_thread().task_queue_manager;
467 if (!task_queue_manager) 465 if (!task_queue_manager)
468 return; 466 return;
469 467
470 LazyNow lazy_now(main_thread_only().time_domain->CreateLazyNow()); 468 MoveReadyDelayedTasksToDelayedWorkQueue(lazy_now);
471 MoveReadyDelayedTasksToDelayedWorkQueue(&lazy_now);
472 469
473 while (!any_thread().immediate_incoming_queue.empty()) { 470 while (!any_thread().immediate_incoming_queue.empty()) {
474 main_thread_only().immediate_work_queue->Push( 471 main_thread_only().immediate_work_queue->Push(
475 std::move(any_thread().immediate_incoming_queue.front())); 472 std::move(any_thread().immediate_incoming_queue.front()));
476 any_thread().immediate_incoming_queue.pop(); 473 any_thread().immediate_incoming_queue.pop();
477 } 474 }
478 475
479 // |immediate_incoming_queue| is now empty so TimeDomain::UpdateQueues no 476 // |immediate_incoming_queue| is now empty so TimeDomain::UpdateQueues no
480 // longer needs to consider this queue for reloading. 477 // longer needs to consider this queue for reloading.
481 main_thread_only().time_domain->UnregisterAsUpdatableTaskQueue(this); 478 main_thread_only().time_domain->UnregisterAsUpdatableTaskQueue(this);
482 479
483 if (main_thread_only().immediate_work_queue->Empty() && 480 if (main_thread_only().immediate_work_queue->Empty() &&
484 main_thread_only().delayed_work_queue->Empty()) { 481 main_thread_only().delayed_work_queue->Empty()) {
485 return; 482 return;
486 } 483 }
487 484
488 if (may_post_dowork) 485 if (may_post_dowork)
489 task_queue_manager->MaybeScheduleImmediateWork(FROM_HERE); 486 task_queue_manager->MaybeScheduleImmediateWork(FROM_HERE);
490 } 487 }
491 488
492 void TaskQueueImpl::PumpQueue(bool may_post_dowork) { 489 void TaskQueueImpl::PumpQueue(LazyNow* lazy_now, bool may_post_dowork) {
493 base::AutoLock lock(any_thread_lock_); 490 base::AutoLock lock(any_thread_lock_);
494 PumpQueueLocked(may_post_dowork); 491 PumpQueueLocked(lazy_now, may_post_dowork);
495 } 492 }
496 493
497 const char* TaskQueueImpl::GetName() const { 494 const char* TaskQueueImpl::GetName() const {
498 return name_; 495 return name_;
499 } 496 }
500 497
501 void TaskQueueImpl::SetQueuePriority(QueuePriority priority) { 498 void TaskQueueImpl::SetQueuePriority(QueuePriority priority) {
502 if (!main_thread_only().task_queue_manager || priority == GetQueuePriority()) 499 if (!main_thread_only().task_queue_manager || priority == GetQueuePriority())
503 return; 500 return;
504 main_thread_only().task_queue_manager->selector_.SetQueuePriority(this, 501 main_thread_only().task_queue_manager->selector_.SetQueuePriority(this,
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 state->SetBoolean("nestable", task.nestable); 708 state->SetBoolean("nestable", task.nestable);
712 state->SetBoolean("is_high_res", task.is_high_res); 709 state->SetBoolean("is_high_res", task.is_high_res);
713 state->SetDouble( 710 state->SetDouble(
714 "delayed_run_time", 711 "delayed_run_time",
715 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L); 712 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L);
716 state->EndDictionary(); 713 state->EndDictionary();
717 } 714 }
718 715
719 } // namespace internal 716 } // namespace internal
720 } // namespace scheduler 717 } // namespace scheduler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698