1311425 - Make requestIdleCallback aware of timeouts.

Prepare for handling several sources of idleness.

Make idle callbacks aware of nsITimers.

Add pref for how far into the timer queue.

1311425 - Avoid expiration timers when scheduling idle runnables.

review comment fix to ensure low priority timers aren't taken into account when calling NS_GetTimerDeadlineHintOnCurrentThread.
This commit is contained in:
win7-7 2024-04-27 19:21:20 +03:00 committed by wuggy
commit 5499c5f9a3
12 changed files with 188 additions and 60 deletions

View file

@ -593,6 +593,52 @@ TimerThread::RemoveTimer(nsTimerImpl* aTimer)
return NS_OK;
}
TimeStamp
TimerThread::FindNextFireTimeForCurrentThread(TimeStamp aDefault, uint32_t aSearchBound)
{
MonitorAutoLock lock(mMonitor);
TimeStamp timeStamp = aDefault;
uint32_t index = 0;
for (auto timers = mTimers.begin(); timers != mTimers.end(); ++timers) {
nsTimerImpl* timer = (*timers)->Value();
if (!timer) {
continue;
}
if (timer->mTimeout > aDefault) {
timeStamp = aDefault;
break;
}
// Don't yield to timers created with the *_LOW_PRIORITY type.
if (timer->IsLowPriority()) {
continue;
}
// Track the currently highest timeout so that we can bail when we
// reach the bound or when we find a timer for the current thread.
timeStamp = timer->mTimeout;
bool isOnCurrentThread = false;
nsresult rv = timer->mEventTarget->IsOnCurrentThread(&isOnCurrentThread);
if (NS_WARN_IF(NS_FAILED(rv))) {
continue;
}
if (isOnCurrentThread) {
break;
}
if (++index > aSearchBound) {
break;
}
}
return timeStamp;
}
// This function must be called from within a lock
int32_t
TimerThread::AddTimerInternal(nsTimerImpl* aTimer)