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

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

Issue 2523673003: [scheduler] Fix bug in task queue throttler (Closed)
Patch Set: Deleted Metadata::IsThrottled Created 4 years, 1 month 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 803cf4e82cba882c257e953857ff71bed594826c..107ea1f3c08945e4ee60ab8b4005fd3aee5f4bb3 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);
@@ -294,8 +294,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)) {
Sami 2016/11/23 16:47:18 Hmm, this could end badly if the throttler is shut
altimin 2016/11/23 16:56:08 If throttling is disabled then all queues are enab
Sami 2016/11/23 17:00:59 I see, okay.
task_queue->SetTimeDomain(renderer_scheduler_->real_time_domain());
task_queue->RemoveFence();
}
@@ -314,7 +314,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;
}
@@ -332,13 +332,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();
@@ -381,10 +379,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) {
@@ -438,7 +439,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.
@@ -594,7 +595,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);
}
@@ -605,7 +606,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;
@@ -629,7 +630,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