| 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/renderer/task_queue_throttler.h" | 5 #include "platform/scheduler/renderer/task_queue_throttler.h" |
| 6 | 6 |
| 7 #include <cstdint> | 7 #include <cstdint> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 if (IsThrottled(task_queue)) { | 308 if (IsThrottled(task_queue)) { |
| 309 task_queue->SetTimeDomain(renderer_scheduler_->real_time_domain()); | 309 task_queue->SetTimeDomain(renderer_scheduler_->real_time_domain()); |
| 310 task_queue->RemoveFence(); | 310 task_queue->RemoveFence(); |
| 311 } | 311 } |
| 312 } | 312 } |
| 313 | 313 |
| 314 renderer_scheduler_->UnregisterTimeDomain(time_domain_.get()); | 314 renderer_scheduler_->UnregisterTimeDomain(time_domain_.get()); |
| 315 } | 315 } |
| 316 | 316 |
| 317 void TaskQueueThrottler::SetQueueEnabled(TaskQueue* task_queue, bool enabled) { | 317 void TaskQueueThrottler::SetQueueEnabled(TaskQueue* task_queue, bool enabled) { |
| 318 // Both the TaskQueueThrottler and other systems want to enable and disable |
| 319 // task queues. The policy we've adopted to deal with this is: |
| 320 // |
| 321 // A task queue is disabled if either the TaskQueueThrottler or the caller |
| 322 // vote to disable it. |
| 323 // |
| 324 // A task queue is enabled only if both the TaskQueueThrottler and the caller |
| 325 // vote to enable it. |
| 318 TaskQueueMap::iterator find_it = queue_details_.find(task_queue); | 326 TaskQueueMap::iterator find_it = queue_details_.find(task_queue); |
| 319 | 327 |
| 328 // If TaskQueueThrottler does not know about this queue, just call |
| 329 // SetQueueEnabled directly. |
| 320 if (find_it == queue_details_.end()) { | 330 if (find_it == queue_details_.end()) { |
| 321 task_queue->SetQueueEnabled(enabled); | 331 task_queue->SetQueueEnabled(enabled); |
| 322 return; | 332 return; |
| 323 } | 333 } |
| 324 | 334 |
| 335 // Remember the caller's preference so we know what to do when the task queue |
| 336 // isn't throttled, or has budget to run. |
| 325 find_it->second.enabled = enabled; | 337 find_it->second.enabled = enabled; |
| 326 | 338 |
| 327 if (!IsThrottled(task_queue)) { | 339 if (!IsThrottled(task_queue)) { |
| 328 task_queue->SetQueueEnabled(enabled); | 340 task_queue->SetQueueEnabled(enabled); |
| 329 return; | 341 return; |
| 330 } | 342 } |
| 331 | 343 |
| 332 // We don't enable the queue here because it's throttled and there might be | 344 if (enabled) { |
| 333 // tasks in it's work queue that would execute immediatly rather than after | 345 // If the task queue is throttled and we want to enable it, we can't |
| 334 // PumpThrottledTasks runs. | 346 // do it immediately due to task alignment requirement and we should |
| 335 if (!enabled) { | 347 // schedule a call to PumpThrottledTasks. |
| 336 task_queue->SetQueueEnabled(false); | |
| 337 MaybeSchedulePumpQueue(FROM_HERE, tick_clock_->NowTicks(), task_queue, | 348 MaybeSchedulePumpQueue(FROM_HERE, tick_clock_->NowTicks(), task_queue, |
| 338 base::nullopt); | 349 base::nullopt); |
| 350 } else { |
| 351 task_queue->SetQueueEnabled(false); |
| 339 } | 352 } |
| 340 } | 353 } |
| 341 | 354 |
| 342 void TaskQueueThrottler::IncreaseThrottleRefCount(TaskQueue* task_queue) { | 355 void TaskQueueThrottler::IncreaseThrottleRefCount(TaskQueue* task_queue) { |
| 343 DCHECK_NE(task_queue, task_runner_.get()); | 356 DCHECK_NE(task_queue, task_runner_.get()); |
| 344 | 357 |
| 345 std::pair<TaskQueueMap::iterator, bool> insert_result = queue_details_.insert( | 358 std::pair<TaskQueueMap::iterator, bool> insert_result = queue_details_.insert( |
| 346 std::make_pair(task_queue, Metadata(0 /* ref_count */, | 359 std::make_pair(task_queue, Metadata(0 /* ref_count */, |
| 347 task_queue->IsQueueEnabled()))); | 360 task_queue->IsQueueEnabled()))); |
| 348 | 361 |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 queue->SetTimeDomain(time_domain_.get()); | 676 queue->SetTimeDomain(time_domain_.get()); |
| 664 MaybeSchedulePumpQueue(FROM_HERE, lazy_now.Now(), queue, | 677 MaybeSchedulePumpQueue(FROM_HERE, lazy_now.Now(), queue, |
| 665 GetNextAllowedRunTime(lazy_now.Now(), queue)); | 678 GetNextAllowedRunTime(lazy_now.Now(), queue)); |
| 666 } | 679 } |
| 667 | 680 |
| 668 TRACE_EVENT0(tracing_category_, "TaskQueueThrottler_EnableThrottling"); | 681 TRACE_EVENT0(tracing_category_, "TaskQueueThrottler_EnableThrottling"); |
| 669 } | 682 } |
| 670 | 683 |
| 671 } // namespace scheduler | 684 } // namespace scheduler |
| 672 } // namespace blink | 685 } // namespace blink |
| OLD | NEW |