OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_manager.h" | 5 #include "platform/scheduler/base/task_queue_manager.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 if (time_domain == real_time_domain_.get()) { | 166 if (time_domain == real_time_domain_.get()) { |
167 time_domain->WakeUpReadyDelayedQueues(lazy_now); | 167 time_domain->WakeUpReadyDelayedQueues(lazy_now); |
168 } else { | 168 } else { |
169 LazyNow time_domain_lazy_now = time_domain->CreateLazyNow(); | 169 LazyNow time_domain_lazy_now = time_domain->CreateLazyNow(); |
170 time_domain->WakeUpReadyDelayedQueues(&time_domain_lazy_now); | 170 time_domain->WakeUpReadyDelayedQueues(&time_domain_lazy_now); |
171 } | 171 } |
172 } | 172 } |
173 } | 173 } |
174 | 174 |
175 void TaskQueueManager::OnBeginNestedRunLoop() { | 175 void TaskQueueManager::OnBeginNestedRunLoop() { |
176 // We just entered a nested message loop, make sure there's a DoWork posted or | 176 // We just entered a nested run loop, make sure there's a DoWork posted or |
177 // the system will grind to a halt. | 177 // the system will grind to a halt. |
178 { | 178 { |
179 base::AutoLock lock(any_thread_lock_); | 179 base::AutoLock lock(any_thread_lock_); |
180 any_thread().immediate_do_work_posted_count++; | 180 any_thread().immediate_do_work_posted_count++; |
181 any_thread().is_nested = true; | 181 any_thread().is_nested = true; |
182 } | 182 } |
183 | 183 |
184 // When a nested message loop starts, task time observers may want to ignore | 184 // When a nested run loop starts, task time observers may want to ignore |
185 // the current task. | 185 // the current task. |
186 for (auto& observer : task_time_observers_) | 186 for (auto& observer : task_time_observers_) |
187 observer.OnBeginNestedRunLoop(); | 187 observer.OnBeginNestedRunLoop(); |
188 | 188 |
189 delegate_->PostTask(FROM_HERE, immediate_do_work_closure_); | 189 delegate_->PostTask(FROM_HERE, immediate_do_work_closure_); |
190 } | 190 } |
191 | 191 |
192 void TaskQueueManager::OnQueueHasIncomingImmediateWork( | 192 void TaskQueueManager::OnQueueHasIncomingImmediateWork( |
193 internal::TaskQueueImpl* queue, | 193 internal::TaskQueueImpl* queue, |
194 internal::EnqueueOrder enqueue_order, | 194 internal::EnqueueOrder enqueue_order, |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 DCHECK(main_thread_checker_.CalledOnValidThread()); | 281 DCHECK(main_thread_checker_.CalledOnValidThread()); |
282 TRACE_EVENT1("renderer.scheduler", "TaskQueueManager::DoWork", "delayed", | 282 TRACE_EVENT1("renderer.scheduler", "TaskQueueManager::DoWork", "delayed", |
283 delayed); | 283 delayed); |
284 | 284 |
285 LazyNow lazy_now(real_time_domain()->CreateLazyNow()); | 285 LazyNow lazy_now(real_time_domain()->CreateLazyNow()); |
286 bool is_nested = delegate_->IsNested(); | 286 bool is_nested = delegate_->IsNested(); |
287 if (!is_nested) | 287 if (!is_nested) |
288 queues_to_delete_.clear(); | 288 queues_to_delete_.clear(); |
289 | 289 |
290 // This must be done before running any tasks because they could invoke a | 290 // This must be done before running any tasks because they could invoke a |
291 // nested message loop and we risk having a stale |next_delayed_do_work_|. | 291 // nested run loop and we risk having a stale |next_delayed_do_work_|. |
292 if (delayed) | 292 if (delayed) |
293 next_delayed_do_work_.Clear(); | 293 next_delayed_do_work_.Clear(); |
294 | 294 |
295 for (int i = 0; i < work_batch_size_; i++) { | 295 for (int i = 0; i < work_batch_size_; i++) { |
296 IncomingImmediateWorkMap queues_to_reload; | 296 IncomingImmediateWorkMap queues_to_reload; |
297 | 297 |
298 { | 298 { |
299 base::AutoLock lock(any_thread_lock_); | 299 base::AutoLock lock(any_thread_lock_); |
300 if (i == 0) { | 300 if (i == 0) { |
301 any_thread().do_work_running_count++; | 301 any_thread().do_work_running_count++; |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 for (const scoped_refptr<internal::TaskQueueImpl>& queue : queues_) { | 704 for (const scoped_refptr<internal::TaskQueueImpl>& queue : queues_) { |
705 TimeDomain* time_domain = queue->GetTimeDomain(); | 705 TimeDomain* time_domain = queue->GetTimeDomain(); |
706 if (time_domain_now.find(time_domain) == time_domain_now.end()) | 706 if (time_domain_now.find(time_domain) == time_domain_now.end()) |
707 time_domain_now.insert(std::make_pair(time_domain, time_domain->Now())); | 707 time_domain_now.insert(std::make_pair(time_domain, time_domain->Now())); |
708 queue->SweepCanceledDelayedTasks(time_domain_now[time_domain]); | 708 queue->SweepCanceledDelayedTasks(time_domain_now[time_domain]); |
709 } | 709 } |
710 } | 710 } |
711 | 711 |
712 } // namespace scheduler | 712 } // namespace scheduler |
713 } // namespace blink | 713 } // namespace blink |
OLD | NEW |