1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/platform/scheduler/common/throttling/budget_pool.h"
#include <cstdint>
#include <optional>
#include "third_party/blink/renderer/platform/scheduler/common/tracing_helper.h"
namespace blink {
namespace scheduler {
using base::sequence_manager::TaskQueue;
BudgetPool::BudgetPool(const char* name) : name_(name), is_enabled_(true) {}
BudgetPool::~BudgetPool() {
for (auto* throttler : associated_throttlers_) {
throttler->RemoveBudgetPool(this);
}
}
const char* BudgetPool::Name() const {
return name_;
}
void BudgetPool::AddThrottler(base::TimeTicks now,
TaskQueueThrottler* throttler) {
throttler->AddBudgetPool(this);
associated_throttlers_.insert(throttler);
if (!is_enabled_)
return;
throttler->UpdateQueueState(now);
}
void BudgetPool::UnregisterThrottler(TaskQueueThrottler* throttler) {
associated_throttlers_.erase(throttler);
}
void BudgetPool::RemoveThrottler(base::TimeTicks now,
TaskQueueThrottler* throttler) {
throttler->RemoveBudgetPool(this);
associated_throttlers_.erase(throttler);
if (!is_enabled_)
return;
throttler->UpdateQueueState(now);
}
void BudgetPool::EnableThrottling(base::LazyNow* lazy_now) {
if (is_enabled_)
return;
is_enabled_ = true;
TRACE_EVENT0("renderer.scheduler", "BudgetPool_EnableThrottling");
UpdateStateForAllThrottlers(lazy_now->Now());
}
void BudgetPool::DisableThrottling(base::LazyNow* lazy_now) {
if (!is_enabled_)
return;
is_enabled_ = false;
TRACE_EVENT0("renderer.scheduler", "BudgetPool_DisableThrottling");
UpdateStateForAllThrottlers(lazy_now->Now());
// TODO(altimin): We need to disable TimeBudgetQueues here or they will
// regenerate extra time budget when they are disabled.
}
bool BudgetPool::IsThrottlingEnabled() const {
return is_enabled_;
}
void BudgetPool::Close() {
DCHECK_EQ(0u, associated_throttlers_.size());
}
void BudgetPool::UpdateStateForAllThrottlers(base::TimeTicks now) {
for (TaskQueueThrottler* throttler : associated_throttlers_)
throttler->UpdateQueueState(now);
}
} // namespace scheduler
} // namespace blink
|