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

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

Issue 2189573002: Fix TimeDomain::MigrateQueue with incoming immediate tasks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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/time_domain.h" 5 #include "components/scheduler/base/time_domain.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "components/scheduler/base/task_queue_impl.h" 9 #include "components/scheduler/base/task_queue_impl.h"
10 #include "components/scheduler/base/task_queue_manager_delegate.h" 10 #include "components/scheduler/base/task_queue_manager_delegate.h"
(...skipping 29 matching lines...) Expand all
40 iter++; 40 iter++;
41 } 41 }
42 } 42 }
43 } 43 }
44 44
45 void TimeDomain::MigrateQueue(internal::TaskQueueImpl* queue, 45 void TimeDomain::MigrateQueue(internal::TaskQueueImpl* queue,
46 TimeDomain* destination_time_domain) { 46 TimeDomain* destination_time_domain) {
47 DCHECK(main_thread_checker_.CalledOnValidThread()); 47 DCHECK(main_thread_checker_.CalledOnValidThread());
48 DCHECK_EQ(queue->GetTimeDomain(), this); 48 DCHECK_EQ(queue->GetTimeDomain(), this);
49 DCHECK(destination_time_domain); 49 DCHECK(destination_time_domain);
50 UnregisterAsUpdatableTaskQueue(queue); 50
51 // Make sure we remember to update |queue| if it's got incomming immediate
Sami 2016/07/27 09:57:56 s/incomming/incoming/
alex clarke (OOO till 29th) 2016/07/27 10:14:56 Done.
52 // work.
53 if (UnregisterAsUpdatableTaskQueue(queue))
54 destination_time_domain->updatable_queue_set_.insert(queue);
51 55
52 base::TimeTicks destination_now = destination_time_domain->Now(); 56 base::TimeTicks destination_now = destination_time_domain->Now();
53 // We need to remove |task_queue| from delayed_wakeup_multimap_ which is a 57 // We need to remove |task_queue| from delayed_wakeup_multimap_ which is a
54 // little awkward since it's keyed by time. O(n) running time. 58 // little awkward since it's keyed by time. O(n) running time.
55 for (DelayedWakeupMultimap::iterator iter = delayed_wakeup_multimap_.begin(); 59 for (DelayedWakeupMultimap::iterator iter = delayed_wakeup_multimap_.begin();
56 iter != delayed_wakeup_multimap_.end();) { 60 iter != delayed_wakeup_multimap_.end();) {
57 if (iter->second == queue) { 61 if (iter->second == queue) {
58 destination_time_domain->ScheduleDelayedWork(queue, iter->first, 62 destination_time_domain->ScheduleDelayedWork(queue, iter->first,
59 destination_now); 63 destination_now);
60 // O(1) amortized. 64 // O(1) amortized.
(...skipping 21 matching lines...) Expand all
82 86
83 void TimeDomain::RegisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue) { 87 void TimeDomain::RegisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue) {
84 { 88 {
85 base::AutoLock lock(newly_updatable_lock_); 89 base::AutoLock lock(newly_updatable_lock_);
86 newly_updatable_.push_back(queue); 90 newly_updatable_.push_back(queue);
87 } 91 }
88 if (observer_) 92 if (observer_)
89 observer_->OnTimeDomainHasImmediateWork(); 93 observer_->OnTimeDomainHasImmediateWork();
90 } 94 }
91 95
92 void TimeDomain::UnregisterAsUpdatableTaskQueue( 96 bool TimeDomain::UnregisterAsUpdatableTaskQueue(
93 internal::TaskQueueImpl* queue) { 97 internal::TaskQueueImpl* queue) {
94 DCHECK(main_thread_checker_.CalledOnValidThread()); 98 DCHECK(main_thread_checker_.CalledOnValidThread());
95 99
96 updatable_queue_set_.erase(queue); 100 bool was_updatable = updatable_queue_set_.erase(queue) != 0;
97 101
98 base::AutoLock lock(newly_updatable_lock_); 102 base::AutoLock lock(newly_updatable_lock_);
99 // Remove all copies of |queue| from |newly_updatable_|. 103 // Remove all copies of |queue| from |newly_updatable_|.
100 for (size_t i = 0; i < newly_updatable_.size();) { 104 for (size_t i = 0; i < newly_updatable_.size();) {
101 if (newly_updatable_[i] == queue) { 105 if (newly_updatable_[i] == queue) {
102 // Move last element into slot #i and then compact. 106 // Move last element into slot #i and then compact.
103 newly_updatable_[i] = newly_updatable_.back(); 107 newly_updatable_[i] = newly_updatable_.back();
104 newly_updatable_.pop_back(); 108 newly_updatable_.pop_back();
109 was_updatable = true;
105 } else { 110 } else {
106 i++; 111 i++;
107 } 112 }
108 } 113 }
114 return was_updatable;
109 } 115 }
110 116
111 void TimeDomain::UpdateWorkQueues( 117 void TimeDomain::UpdateWorkQueues(
112 bool should_trigger_wakeup, 118 bool should_trigger_wakeup,
113 const internal::TaskQueueImpl::Task* previous_task, 119 const internal::TaskQueueImpl::Task* previous_task,
114 LazyNow lazy_now) { 120 LazyNow lazy_now) {
115 DCHECK(main_thread_checker_.CalledOnValidThread()); 121 DCHECK(main_thread_checker_.CalledOnValidThread());
116 122
117 // Move any ready delayed tasks into the Incoming queues. 123 // Move any ready delayed tasks into the Incoming queues.
118 WakeupReadyDelayedQueues(&lazy_now, should_trigger_wakeup, previous_task); 124 WakeupReadyDelayedQueues(&lazy_now, should_trigger_wakeup, previous_task);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 state->SetInteger("registered_delay_count", delayed_wakeup_multimap_.size()); 212 state->SetInteger("registered_delay_count", delayed_wakeup_multimap_.size());
207 if (!delayed_wakeup_multimap_.empty()) { 213 if (!delayed_wakeup_multimap_.empty()) {
208 base::TimeDelta delay = delayed_wakeup_multimap_.begin()->first - Now(); 214 base::TimeDelta delay = delayed_wakeup_multimap_.begin()->first - Now();
209 state->SetDouble("next_delay_ms", delay.InMillisecondsF()); 215 state->SetDouble("next_delay_ms", delay.InMillisecondsF());
210 } 216 }
211 AsValueIntoInternal(state); 217 AsValueIntoInternal(state);
212 state->EndDictionary(); 218 state->EndDictionary();
213 } 219 }
214 220
215 } // namespace scheduler 221 } // namespace scheduler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698