Bug 1696456 - Rename budget to minimumUsefulBudget in IdleTaskRunner r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D107239
This commit is contained in:
@@ -1683,7 +1683,7 @@ void nsJSContext::EnsureCCRunner(TimeDuration aDelay, TimeDuration aBudget) {
|
|||||||
CCRunnerFired, "EnsureCCRunner::CCRunnerFired", aDelay.ToMilliseconds(),
|
CCRunnerFired, "EnsureCCRunner::CCRunnerFired", aDelay.ToMilliseconds(),
|
||||||
aBudget.ToMilliseconds(), true, [] { return sShuttingDown; });
|
aBudget.ToMilliseconds(), true, [] { return sShuttingDown; });
|
||||||
} else {
|
} else {
|
||||||
sCCRunner->SetBudget(aBudget.ToMilliseconds());
|
sCCRunner->SetMinimumUsefulBudget(aBudget.ToMilliseconds());
|
||||||
nsIEventTarget* target = mozilla::GetCurrentEventTarget();
|
nsIEventTarget* target = mozilla::GetCurrentEventTarget();
|
||||||
if (target) {
|
if (target) {
|
||||||
sCCRunner->SetTimer(aDelay.ToMilliseconds(), target);
|
sCCRunner->SetTimer(aDelay.ToMilliseconds(), target);
|
||||||
|
|||||||
@@ -12,27 +12,28 @@ namespace mozilla {
|
|||||||
|
|
||||||
already_AddRefed<IdleTaskRunner> IdleTaskRunner::Create(
|
already_AddRefed<IdleTaskRunner> IdleTaskRunner::Create(
|
||||||
const CallbackType& aCallback, const char* aRunnableName,
|
const CallbackType& aCallback, const char* aRunnableName,
|
||||||
uint32_t aMaxDelay, int64_t aNonIdleBudget, bool aRepeating,
|
uint32_t aMaxDelay, int64_t aMinimumUsefulBudget, bool aRepeating,
|
||||||
const MayStopProcessingCallbackType& aMayStopProcessing) {
|
const MayStopProcessingCallbackType& aMayStopProcessing) {
|
||||||
if (aMayStopProcessing && aMayStopProcessing()) {
|
if (aMayStopProcessing && aMayStopProcessing()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<IdleTaskRunner> runner =
|
RefPtr<IdleTaskRunner> runner =
|
||||||
new IdleTaskRunner(aCallback, aRunnableName, aMaxDelay, aNonIdleBudget,
|
new IdleTaskRunner(aCallback, aRunnableName, aMaxDelay,
|
||||||
aRepeating, aMayStopProcessing);
|
aMinimumUsefulBudget, aRepeating, aMayStopProcessing);
|
||||||
runner->Schedule(false); // Initial scheduling shouldn't use idle dispatch.
|
runner->Schedule(false); // Initial scheduling shouldn't use idle dispatch.
|
||||||
return runner.forget();
|
return runner.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
IdleTaskRunner::IdleTaskRunner(
|
IdleTaskRunner::IdleTaskRunner(
|
||||||
const CallbackType& aCallback, const char* aRunnableName,
|
const CallbackType& aCallback, const char* aRunnableName,
|
||||||
uint32_t aMaxDelay, int64_t aNonIdleBudget, bool aRepeating,
|
uint32_t aMaxDelay, int64_t aMinimumUsefulBudget, bool aRepeating,
|
||||||
const MayStopProcessingCallbackType& aMayStopProcessing)
|
const MayStopProcessingCallbackType& aMayStopProcessing)
|
||||||
: CancelableIdleRunnable(aRunnableName),
|
: CancelableIdleRunnable(aRunnableName),
|
||||||
mCallback(aCallback),
|
mCallback(aCallback),
|
||||||
mDelay(aMaxDelay),
|
mDelay(aMaxDelay),
|
||||||
mBudget(TimeDuration::FromMilliseconds(aNonIdleBudget)),
|
mMinimumUsefulBudget(
|
||||||
|
TimeDuration::FromMilliseconds(aMinimumUsefulBudget)),
|
||||||
mRepeating(aRepeating),
|
mRepeating(aRepeating),
|
||||||
mTimerActive(false),
|
mTimerActive(false),
|
||||||
mMayStopProcessing(aMayStopProcessing),
|
mMayStopProcessing(aMayStopProcessing),
|
||||||
@@ -49,7 +50,7 @@ IdleTaskRunner::Run() {
|
|||||||
bool deadLineWasNull = mDeadline.IsNull();
|
bool deadLineWasNull = mDeadline.IsNull();
|
||||||
bool didRun = false;
|
bool didRun = false;
|
||||||
bool allowIdleDispatch = false;
|
bool allowIdleDispatch = false;
|
||||||
if (deadLineWasNull || ((now + mBudget) < mDeadline)) {
|
if (deadLineWasNull || ((now + mMinimumUsefulBudget) < mDeadline)) {
|
||||||
CancelTimer();
|
CancelTimer();
|
||||||
didRun = mCallback(mDeadline);
|
didRun = mCallback(mDeadline);
|
||||||
// If we didn't do meaningful work, don't schedule using immediate
|
// If we didn't do meaningful work, don't schedule using immediate
|
||||||
@@ -78,8 +79,8 @@ void IdleTaskRunner::SetDeadline(mozilla::TimeStamp aDeadline) {
|
|||||||
mDeadline = aDeadline;
|
mDeadline = aDeadline;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IdleTaskRunner::SetBudget(int64_t aBudget) {
|
void IdleTaskRunner::SetMinimumUsefulBudget(int64_t aMinimumUsefulBudget) {
|
||||||
mBudget = TimeDuration::FromMilliseconds(aBudget);
|
mMinimumUsefulBudget = TimeDuration::FromMilliseconds(aMinimumUsefulBudget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IdleTaskRunner::SetTimer(uint32_t aDelay, nsIEventTarget* aTarget) {
|
void IdleTaskRunner::SetTimer(uint32_t aDelay, nsIEventTarget* aTarget) {
|
||||||
|
|||||||
@@ -29,13 +29,12 @@ class IdleTaskRunner final : public CancelableIdleRunnable {
|
|||||||
using MayStopProcessingCallbackType = std::function<bool()>;
|
using MayStopProcessingCallbackType = std::function<bool()>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// An IdleTaskRunner will attempt to run in idle time, with a budget computed
|
// An IdleTaskRunner will attempt to run in any idle time period large enough
|
||||||
// based on a (capped) estimate for how much idle time is available. If there
|
// to fit `aMinimumUsefulBudget`. If no such window occurs within `aMaxDelay`
|
||||||
// is no idle time within `aMaxDelay` ms, it will fall back to running using
|
// ms, it will stop waiting for idle time and run from a TYPE_ONE_SHOT timer.
|
||||||
// a specified `aNonIdleBudget`.
|
|
||||||
static already_AddRefed<IdleTaskRunner> Create(
|
static already_AddRefed<IdleTaskRunner> Create(
|
||||||
const CallbackType& aCallback, const char* aRunnableName,
|
const CallbackType& aCallback, const char* aRunnableName,
|
||||||
uint32_t aMaxDelay, int64_t aNonIdleBudget, bool aRepeating,
|
uint32_t aMaxDelay, int64_t aMinimumUsefulBudget, bool aRepeating,
|
||||||
const MayStopProcessingCallbackType& aMayStopProcessing);
|
const MayStopProcessingCallbackType& aMayStopProcessing);
|
||||||
|
|
||||||
NS_IMETHOD Run() override;
|
NS_IMETHOD Run() override;
|
||||||
@@ -46,9 +45,8 @@ class IdleTaskRunner final : public CancelableIdleRunnable {
|
|||||||
|
|
||||||
void SetTimer(uint32_t aDelay, nsIEventTarget* aTarget) override;
|
void SetTimer(uint32_t aDelay, nsIEventTarget* aTarget) override;
|
||||||
|
|
||||||
// Update the non-idle time budgeted for this callback. This really only
|
// Update the minimum idle time that this callback would be invoked for.
|
||||||
// makes sense for a repeating runner.
|
void SetMinimumUsefulBudget(int64_t aMinimumUsefulBudget);
|
||||||
void SetBudget(int64_t aBudget);
|
|
||||||
|
|
||||||
nsresult Cancel() override;
|
nsresult Cancel() override;
|
||||||
void Schedule(bool aAllowIdleDispatch);
|
void Schedule(bool aAllowIdleDispatch);
|
||||||
@@ -56,7 +54,7 @@ class IdleTaskRunner final : public CancelableIdleRunnable {
|
|||||||
private:
|
private:
|
||||||
explicit IdleTaskRunner(
|
explicit IdleTaskRunner(
|
||||||
const CallbackType& aCallback, const char* aRunnableName,
|
const CallbackType& aCallback, const char* aRunnableName,
|
||||||
uint32_t aMaxDelay, int64_t aNonIdleBudget, bool aRepeating,
|
uint32_t aMaxDelay, int64_t aMinimumUsefulBudget, bool aRepeating,
|
||||||
const MayStopProcessingCallbackType& aMayStopProcessing);
|
const MayStopProcessingCallbackType& aMayStopProcessing);
|
||||||
~IdleTaskRunner();
|
~IdleTaskRunner();
|
||||||
void CancelTimer();
|
void CancelTimer();
|
||||||
@@ -74,9 +72,8 @@ class IdleTaskRunner final : public CancelableIdleRunnable {
|
|||||||
// The null timestamp when the run is triggered by aMaxDelay instead of idle.
|
// The null timestamp when the run is triggered by aMaxDelay instead of idle.
|
||||||
TimeStamp mDeadline;
|
TimeStamp mDeadline;
|
||||||
|
|
||||||
// The expected amount of time the callback will run for, when not running
|
// The least duration worth calling the callback for during idle time.
|
||||||
// during idle time.
|
TimeDuration mMinimumUsefulBudget;
|
||||||
TimeDuration mBudget;
|
|
||||||
|
|
||||||
bool mRepeating;
|
bool mRepeating;
|
||||||
bool mTimerActive;
|
bool mTimerActive;
|
||||||
|
|||||||
Reference in New Issue
Block a user