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

Unified Diff: third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler.cc

Issue 2548483002: [scheduler] Account for disabling throttling in TaskQueueThrottler::IsThrottled (Closed)
Patch Set: Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler.cc
diff --git a/third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler.cc b/third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler.cc
index bb095ca4604a48b28b3bdefe32bb95d2d61b9daf..87fca098042269ba07625f613336e1e8faf4142f 100644
--- a/third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler.cc
+++ b/third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler.cc
@@ -100,7 +100,7 @@ void TaskQueueThrottler::TimeBudgetPool::AddQueue(base::TimeTicks now,
associated_task_queues_.insert(queue);
- if (!is_enabled_ || !metadata.IsThrottled())
+ if (!is_enabled_ || !task_queue_throttler_->IsThrottled(queue))
return;
queue->SetQueueEnabled(false);
@@ -115,7 +115,7 @@ void TaskQueueThrottler::TimeBudgetPool::RemoveQueue(base::TimeTicks now,
DCHECK(find_it != task_queue_throttler_->queue_details_.end() &&
find_it->second.time_budget_pool == this);
find_it->second.time_budget_pool = nullptr;
- bool is_throttled = find_it->second.IsThrottled();
+ bool is_throttled = task_queue_throttler_->IsThrottled(queue);
task_queue_throttler_->MaybeDeleteQueueMetadata(find_it);
associated_task_queues_.erase(queue);
@@ -293,8 +293,8 @@ TaskQueueThrottler::~TaskQueueThrottler() {
// It's possible for queues to be still throttled, so we need to tidy up
// before unregistering the time domain.
for (const TaskQueueMap::value_type& map_entry : queue_details_) {
- if (map_entry.second.IsThrottled()) {
- TaskQueue* task_queue = map_entry.first;
+ TaskQueue* task_queue = map_entry.first;
+ if (IsThrottled(task_queue)) {
task_queue->SetTimeDomain(renderer_scheduler_->real_time_domain());
task_queue->RemoveFence();
}
@@ -313,7 +313,7 @@ void TaskQueueThrottler::SetQueueEnabled(TaskQueue* task_queue, bool enabled) {
find_it->second.enabled = enabled;
- if (!find_it->second.IsThrottled()) {
+ if (!IsThrottled(task_queue)) {
task_queue->SetQueueEnabled(enabled);
return;
}
@@ -331,13 +331,11 @@ void TaskQueueThrottler::SetQueueEnabled(TaskQueue* task_queue, bool enabled) {
void TaskQueueThrottler::IncreaseThrottleRefCount(TaskQueue* task_queue) {
DCHECK_NE(task_queue, task_runner_.get());
- std::pair<TaskQueueMap::iterator, bool> insert_result =
- queue_details_.insert(std::make_pair(task_queue, Metadata()));
-
- if (!insert_result.first->second.IsThrottled()) {
- // The insert was successful so we need to throttle the queue.
- insert_result.first->second.enabled = task_queue->IsQueueEnabled();
+ std::pair<TaskQueueMap::iterator, bool> insert_result = queue_details_.insert(
+ std::make_pair(task_queue, Metadata(0 /* ref_count */,
+ task_queue->IsQueueEnabled())));
+ if (insert_result.first->second.throttling_ref_count == 0) {
if (allow_throttling_) {
task_queue->SetTimeDomain(time_domain_.get());
task_queue->RemoveFence();
@@ -380,10 +378,13 @@ void TaskQueueThrottler::DecreaseThrottleRefCount(TaskQueue* task_queue) {
}
bool TaskQueueThrottler::IsThrottled(TaskQueue* task_queue) const {
+ if (!allow_throttling_)
+ return false;
+
auto find_it = queue_details_.find(task_queue);
if (find_it == queue_details_.end())
return false;
- return find_it->second.IsThrottled();
+ return find_it->second.throttling_ref_count > 0;
}
void TaskQueueThrottler::UnregisterTaskQueue(TaskQueue* task_queue) {
@@ -437,7 +438,7 @@ void TaskQueueThrottler::PumpThrottledTasks() {
for (const TaskQueueMap::value_type& map_entry : queue_details_) {
TaskQueue* task_queue = map_entry.first;
if (!map_entry.second.enabled || task_queue->IsEmpty() ||
- !map_entry.second.IsThrottled())
+ !IsThrottled(task_queue))
continue;
// Don't enable queues whose budget pool doesn't allow them to run now.
@@ -593,7 +594,7 @@ base::TimeTicks TaskQueueThrottler::GetNextAllowedRunTime(base::TimeTicks now,
}
void TaskQueueThrottler::MaybeDeleteQueueMetadata(TaskQueueMap::iterator it) {
- if (!it->second.IsThrottled() && !it->second.time_budget_pool)
+ if (it->second.throttling_ref_count == 0 && !it->second.time_budget_pool)
queue_details_.erase(it);
}
@@ -604,7 +605,7 @@ void TaskQueueThrottler::DisableThrottling() {
allow_throttling_ = false;
for (const auto& map_entry : queue_details_) {
- if (!map_entry.second.IsThrottled())
+ if (map_entry.second.throttling_ref_count == 0)
continue;
TaskQueue* queue = map_entry.first;
@@ -628,7 +629,7 @@ void TaskQueueThrottler::EnableThrottling() {
LazyNow lazy_now(tick_clock_);
for (const auto& map_entry : queue_details_) {
- if (!map_entry.second.IsThrottled())
+ if (map_entry.second.throttling_ref_count == 0)
continue;
TaskQueue* queue = map_entry.first;

Powered by Google App Engine
This is Rietveld 408576698