Backing out rev b567a93a5086 (bug 558306) to fix test orange

This commit is contained in:
Boris Zbarsky
2010-07-15 13:49:28 -04:00
parent 844457efba
commit 8ca24ae80c
4 changed files with 83 additions and 72 deletions

View File

@@ -50,8 +50,6 @@
#include "nsIProxyObjectManager.h"
#include "mozilla/Services.h"
#include <math.h>
NS_IMPL_THREADSAFE_ISUPPORTS2(TimerThread, nsIRunnable, nsIObserver)
TimerThread::TimerThread() :
@@ -63,7 +61,8 @@ TimerThread::TimerThread() :
mWaiting(PR_FALSE),
mSleeping(PR_FALSE),
mDelayLineCounter(0),
mMinTimerPeriod(0)
mMinTimerPeriod(0),
mTimeoutAdjustment(0)
{
}
@@ -192,27 +191,26 @@ nsresult TimerThread::Shutdown()
// Keep track of how early (positive slack) or late (negative slack) timers
// are running, and use the filtered slack number to adaptively estimate how
// early timers should fire to be "on time".
void TimerThread::UpdateFilter(PRUint32 aDelay, TimeStamp aTimeout,
TimeStamp aNow)
void TimerThread::UpdateFilter(PRUint32 aDelay, PRIntervalTime aTimeout,
PRIntervalTime aNow)
{
TimeDuration slack = aTimeout - aNow;
PRInt32 slack = (PRInt32) (aTimeout - aNow);
double smoothSlack = 0;
PRUint32 i, filterLength;
static TimeDuration kFilterFeedbackMaxTicks =
TimeDuration::FromMilliseconds(FILTER_FEEDBACK_MAX);
static TimeDuration kFilterFeedbackMinTicks =
TimeDuration::FromMilliseconds(-FILTER_FEEDBACK_MAX);
static PRIntervalTime kFilterFeedbackMaxTicks =
PR_MillisecondsToInterval(FILTER_FEEDBACK_MAX);
if (slack > kFilterFeedbackMaxTicks)
slack = kFilterFeedbackMaxTicks;
else if (slack < kFilterFeedbackMinTicks)
slack = kFilterFeedbackMinTicks;
mDelayLine[mDelayLineCounter & DELAY_LINE_LENGTH_MASK] =
slack.ToMilliseconds();
if (slack > 0) {
if (slack > (PRInt32)kFilterFeedbackMaxTicks)
slack = kFilterFeedbackMaxTicks;
} else {
if (slack < -(PRInt32)kFilterFeedbackMaxTicks)
slack = -(PRInt32)kFilterFeedbackMaxTicks;
}
mDelayLine[mDelayLineCounter & DELAY_LINE_LENGTH_MASK] = slack;
if (++mDelayLineCounter < DELAY_LINE_LENGTH) {
// Startup mode: accumulate a full delay line before filtering.
PR_ASSERT(mTimeoutAdjustment.ToSeconds() == 0);
PR_ASSERT(mTimeoutAdjustment == 0);
filterLength = 0;
} else {
// Past startup: compute number of filter taps based on mMinTimerPeriod.
@@ -233,7 +231,7 @@ void TimerThread::UpdateFilter(PRUint32 aDelay, TimeStamp aTimeout,
smoothSlack /= filterLength;
// XXXbe do we need amplification? hacking a fudge factor, need testing...
mTimeoutAdjustment = TimeDuration::FromMilliseconds(smoothSlack * 1.5);
mTimeoutAdjustment = (PRInt32) (smoothSlack * 1.5);
}
#ifdef DEBUG_TIMERS
@@ -249,7 +247,6 @@ NS_IMETHODIMP TimerThread::Run()
nsAutoLock lock(mLock);
while (!mShutdown) {
// Have to use PRIntervalTime here, since PR_WaitCondVar takes it
PRIntervalTime waitFor;
if (mSleeping) {
@@ -257,13 +254,13 @@ NS_IMETHODIMP TimerThread::Run()
waitFor = PR_MillisecondsToInterval(100);
} else {
waitFor = PR_INTERVAL_NO_TIMEOUT;
TimeStamp now = TimeStamp::Now();
PRIntervalTime now = PR_IntervalNow();
nsTimerImpl *timer = nsnull;
if (!mTimers.IsEmpty()) {
timer = mTimers[0];
if (now >= timer->mTimeout + mTimeoutAdjustment) {
if (!TIMER_LESS_THAN(now, timer->mTimeout + mTimeoutAdjustment)) {
next:
// NB: AddRef before the Release under RemoveTimerInternal to avoid
// mRefCnt passing through zero, in case all other refs than the one
@@ -281,7 +278,10 @@ NS_IMETHODIMP TimerThread::Run()
if (PR_LOG_TEST(gTimerLog, PR_LOG_DEBUG)) {
PR_LOG(gTimerLog, PR_LOG_DEBUG,
("Timer thread woke up %dms from when it was supposed to\n",
PRInt32(fabs((now - timer->mTimeout).ToMilliseconds()))));
(now >= timer->mTimeout)
? PR_IntervalToMilliseconds(now - timer->mTimeout)
: -(PRInt32)PR_IntervalToMilliseconds(timer->mTimeout-now))
);
}
#endif
@@ -313,20 +313,20 @@ NS_IMETHODIMP TimerThread::Run()
// Update now, as PostTimerEvent plus the locking may have taken a
// tick or two, and we may goto next below.
now = TimeStamp::Now();
now = PR_IntervalNow();
}
}
if (!mTimers.IsEmpty()) {
timer = mTimers[0];
TimeStamp timeout = timer->mTimeout + mTimeoutAdjustment;
PRIntervalTime timeout = timer->mTimeout + mTimeoutAdjustment;
// Don't wait at all (even for PR_INTERVAL_NO_WAIT) if the next timer
// is due now or overdue.
if (now >= timeout)
if (!TIMER_LESS_THAN(now, timeout))
goto next;
waitFor = PR_MillisecondsToInterval((timeout - now).ToMilliseconds());
waitFor = timeout - now;
}
#ifdef DEBUG_TIMERS
@@ -411,22 +411,23 @@ PRInt32 TimerThread::AddTimerInternal(nsTimerImpl *aTimer)
if (mShutdown)
return -1;
TimeStamp now = TimeStamp::Now();
PRIntervalTime now = PR_IntervalNow();
PRUint32 count = mTimers.Length();
PRUint32 i = 0;
for (; i < count; i++) {
nsTimerImpl *timer = mTimers[i];
// Don't break till we have skipped any overdue timers.
// XXXbz why? Given our definition of overdue in terms of
// mTimeoutAdjustment, aTimer might be overdue already! Why not
// just fire timers in order?
// Don't break till we have skipped any overdue timers. Do not include
// mTimeoutAdjustment here, because we are really trying to avoid calling
// TIMER_LESS_THAN(t, u), where the t is now + DELAY_INTERVAL_MAX, u is
// now - overdue, and DELAY_INTERVAL_MAX + overdue > DELAY_INTERVAL_LIMIT.
// In other words, we want to use now-based time, now adjusted time, even
// though "overdue" ultimately depends on adjusted time.
// XXX does this hold for TYPE_REPEATING_PRECISE? /be
if (now < timer->mTimeout + mTimeoutAdjustment &&
aTimer->mTimeout < timer->mTimeout) {
if (TIMER_LESS_THAN(now, timer->mTimeout) &&
TIMER_LESS_THAN(aTimer->mTimeout, timer->mTimeout)) {
break;
}
}
@@ -472,7 +473,7 @@ void TimerThread::DoAfterSleep()
}
// nuke the stored adjustments, so they get recalibrated
mTimeoutAdjustment = TimeDuration(0);
mTimeoutAdjustment = 0;
mDelayLineCounter = 0;
mSleeping = PR_FALSE;
}