зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1311425 - Add pref for how far into the timer queue, r=smaug,f=froydnj
--HG-- extra : rebase_source : 170404bed646efffa71f1e5b0970ec69f6dc4ce5
This commit is contained in:
Родитель
8e2322bcce
Коммит
892408079a
|
@ -13,6 +13,9 @@
|
|||
|
||||
#define DEFAULT_LONG_IDLE_PERIOD 50.0f
|
||||
#define DEFAULT_MIN_IDLE_PERIOD 3.0f
|
||||
#define DEFAULT_MAX_TIMER_THREAD_BOUND 5
|
||||
|
||||
const uint32_t kMaxTimerThreadBoundClamp = 15;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
|
@ -27,7 +30,7 @@ MainThreadIdlePeriod::GetIdlePeriodHint(TimeStamp* aIdleDeadline)
|
|||
now + TimeDuration::FromMilliseconds(GetLongIdlePeriod());
|
||||
|
||||
currentGuess = nsRefreshDriver::GetIdleDeadlineHint(currentGuess);
|
||||
currentGuess = NS_GetTimerDeadlineHintOnCurrentThread(currentGuess);
|
||||
currentGuess = NS_GetTimerDeadlineHintOnCurrentThread(currentGuess, GetMaxTimerThreadBound());
|
||||
|
||||
// If the idle period is too small, then just return a null time
|
||||
// to indicate we are busy. Otherwise return the actual deadline.
|
||||
|
@ -78,4 +81,21 @@ MainThreadIdlePeriod::GetMinIdlePeriod()
|
|||
return sMinIdlePeriod;
|
||||
}
|
||||
|
||||
/* static */ uint32_t
|
||||
MainThreadIdlePeriod::GetMaxTimerThreadBound()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
static uint32_t sMaxTimerThreadBound = DEFAULT_MAX_TIMER_THREAD_BOUND;
|
||||
static bool sInitialized = false;
|
||||
|
||||
if (!sInitialized && Preferences::IsServiceAvailable()) {
|
||||
sInitialized = true;
|
||||
Preferences::AddUintVarCache(&sMaxTimerThreadBound, "idle_queue.max_timer_thread_bound",
|
||||
DEFAULT_MAX_TIMER_THREAD_BOUND);
|
||||
}
|
||||
|
||||
return std::max(sMaxTimerThreadBound, kMaxTimerThreadBoundClamp);
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -24,6 +24,7 @@ public:
|
|||
|
||||
static float GetLongIdlePeriod();
|
||||
static float GetMinIdlePeriod();
|
||||
static uint32_t GetMaxTimerThreadBound();
|
||||
private:
|
||||
virtual ~MainThreadIdlePeriod() {}
|
||||
|
||||
|
|
|
@ -590,10 +590,11 @@ TimerThread::RemoveTimer(nsTimerImpl* aTimer)
|
|||
}
|
||||
|
||||
TimeStamp
|
||||
TimerThread::FindNextFireTimeForCurrentThread(TimeStamp aDefault)
|
||||
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();
|
||||
|
@ -603,9 +604,14 @@ TimerThread::FindNextFireTimeForCurrentThread(TimeStamp aDefault)
|
|||
}
|
||||
|
||||
if (timer->mTimeout > aDefault) {
|
||||
timeStamp = aDefault;
|
||||
break;
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
// Don't yield to timers created with the *_LOW_PRIORITY type.
|
||||
if (timer->IsLowPriority()) {
|
||||
continue;
|
||||
|
@ -618,7 +624,11 @@ TimerThread::FindNextFireTimeForCurrentThread(TimeStamp aDefault)
|
|||
}
|
||||
|
||||
if (isOnCurrentThread) {
|
||||
timeStamp = timer->mTimeout;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (++index > aSearchBound) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public:
|
|||
|
||||
nsresult AddTimer(nsTimerImpl* aTimer);
|
||||
nsresult RemoveTimer(nsTimerImpl* aTimer);
|
||||
TimeStamp FindNextFireTimeForCurrentThread(TimeStamp );
|
||||
TimeStamp FindNextFireTimeForCurrentThread(TimeStamp aDefault, uint32_t aSearchBound);
|
||||
|
||||
void DoBeforeSleep();
|
||||
void DoAfterSleep();
|
||||
|
|
|
@ -1770,7 +1770,11 @@ NS_SetMainThread();
|
|||
/**
|
||||
* Return the expiration time of the next timer to run on the current
|
||||
* thread. If that expiration time is greater than aDefault, then
|
||||
* return aDefault.
|
||||
* return aDefault. aSearchBound specifies a maximum number of timers
|
||||
* to examine to find a timer on the current thread. If no timer that
|
||||
* will run on the current thread is found after examining
|
||||
* aSearchBound timers, return the highest seen expiration time as a
|
||||
* best effort guess.
|
||||
*
|
||||
* Timers with either the type nsITimer::TYPE_ONE_SHOT_LOW_PRIORITY or
|
||||
* nsITIMER::TYPE_REPEATING_SLACK_LOW_PRIORITY will be skipped when
|
||||
|
@ -1779,7 +1783,7 @@ NS_SetMainThread();
|
|||
* nsIThread::IdleDispatch.
|
||||
*/
|
||||
extern mozilla::TimeStamp
|
||||
NS_GetTimerDeadlineHintOnCurrentThread(mozilla::TimeStamp aDefault);
|
||||
NS_GetTimerDeadlineHintOnCurrentThread(mozilla::TimeStamp aDefault, uint32_t aSearchBound);
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
|
|
|
@ -45,10 +45,10 @@ GetTimerLog()
|
|||
}
|
||||
|
||||
TimeStamp
|
||||
NS_GetTimerDeadlineHintOnCurrentThread(TimeStamp aDefault)
|
||||
NS_GetTimerDeadlineHintOnCurrentThread(TimeStamp aDefault, uint32_t aSearchBound)
|
||||
{
|
||||
return gThread
|
||||
? gThread->FindNextFireTimeForCurrentThread(aDefault)
|
||||
? gThread->FindNextFireTimeForCurrentThread(aDefault, aSearchBound)
|
||||
: TimeStamp();
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче