Bug 1606410. Make idle state peeking look more like idle state getting, so consumers can be more similar. r=smaug

This allows us to consistently use mCachedIdleDeadline to represent whether idle runnables should run.

Differential Revision: https://phabricator.services.mozilla.com/D58419

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2019-12-31 15:15:17 +00:00
parent 7c9506eeb4
commit 9c1009c749
2 changed files with 11 additions and 9 deletions

View File

@ -77,15 +77,16 @@ class IdlePeriodState {
// Get the current cached idle deadline. This may return a null timestamp.
TimeStamp GetCachedIdleDeadline() { return mCachedIdleDeadline; }
// Peek our current idle deadline. This can return a null timestamp (which
// means we are not idle right now). This method does not have any
// side-effects on our state, apart from guaranteeing that if it returns
// non-null then GetDeadlineForIdleTask will return non-null until
// ForgetPendingTaskGuarantee() is called.
// Peek our current idle deadline into mCachedIdleDeadline. This can cause
// mCachedIdleDeadline to be a null timestamp (which means we are not idle
// right now). This method does not have any side-effects on our state, apart
// from guaranteeing that if it returns non-null then GetDeadlineForIdleTask
// will return non-null until ForgetPendingTaskGuarantee() is called, and its
// effects on mCachedIdleDeadline.
//
// aProofOfUnlock is the proof that our caller unlocked its mutex.
TimeStamp PeekIdleDeadline(const MutexAutoUnlock& aProofOfUnlock) {
return GetIdleDeadlineInternal(true, aProofOfUnlock);
void CachePeekedIdleDeadline(const MutexAutoUnlock& aProofOfUnlock) {
mCachedIdleDeadline = GetIdleDeadlineInternal(true, aProofOfUnlock);
}
void SetIdleToken(uint64_t aId, TimeDuration aDuration);

View File

@ -299,11 +299,12 @@ bool PrioritizedEventQueue::HasReadyEvent(const MutexAutoLock& aProofOfLock) {
}
// Temporarily unlock so we can peek our idle deadline.
TimeStamp idleDeadline;
{
MutexAutoUnlock unlock(*mMutex);
idleDeadline = mIdlePeriodState.PeekIdleDeadline(unlock);
mIdlePeriodState.CachePeekedIdleDeadline(unlock);
}
TimeStamp idleDeadline = mIdlePeriodState.GetCachedIdleDeadline();
mIdlePeriodState.ClearCachedIdleDeadline();
// Re-check the emptiness of the queues, since we had the lock released for a
// bit.