diff --git a/js/src/prmjtime.cpp b/js/src/prmjtime.cpp index f1e340ee1c1..c0431a74a18 100644 --- a/js/src/prmjtime.cpp +++ b/js/src/prmjtime.cpp @@ -165,10 +165,25 @@ static const JSInt64 win2un = JSLL_INIT(0x19DB1DE, 0xD53E8000); #endif -#ifdef HAVE_GETSYSTEMTIMEASFILETIME +#if defined(HAVE_GETSYSTEMTIMEASFILETIME) || defined(HAVE_SYSTEMTIMETOFILETIME) -typedef struct CalibrationData +#if defined(HAVE_GETSYSTEMTIMEASFILETIME) +inline void +LowResTime(LPFILETIME lpft) +{ + GetSystemTimeAsFileTime(lpft); +} +#elif defined(HAVE_SYSTEMTIMETOFILETIME) +inline void +LowResTime(LPFILETIME lpft) { + GetCurrentFT(lpft); +} +#else +#error "No implementation of PRMJ_Now was selected." +#endif + +typedef struct CalibrationData { long double freq; /* The performance counter frequency */ long double offset; /* The low res 'epoch' */ long double timer_offset; /* The high res 'epoch' */ @@ -182,6 +197,9 @@ typedef struct CalibrationData CRITICAL_SECTION data_lock; CRITICAL_SECTION calibration_lock; #endif +#ifdef WINCE + JSInt64 granularity; +#endif } CalibrationData; static CalibrationData calibration = { 0 }; @@ -206,12 +224,16 @@ NowCalibrate() /* By wrapping a timeBegin/EndPeriod pair of calls around this loop, the loop seems to take much less time (1 ms vs 15ms) on Vista. */ timeBeginPeriod(1); - GetSystemTimeAsFileTime(&ftStart); + LowResTime(&ftStart); do { - GetSystemTimeAsFileTime(&ft); + LowResTime(&ft); } while (memcmp(&ftStart,&ft, sizeof(ft)) == 0); timeEndPeriod(1); - + +#ifdef WINCE + calibration.granularity = (FILETIME2INT64(ft) - + FILETIME2INT64(ftStart))/10; +#endif /* calibrationDelta = (FILETIME2INT64(ft) - FILETIME2INT64(ftStart))/10; fprintf(stderr, "Calibration delta was %I64d us\n", calibrationDelta); @@ -243,8 +265,13 @@ NowInit(void) { memset(&calibration, 0, sizeof(calibration)); NowCalibrate(); +#ifdef WINCE + InitializeCriticalSection(&calibration.calibration_lock); + InitializeCriticalSection(&calibration.data_lock); +#else InitializeCriticalSectionAndSpinCount(&calibration.calibration_lock, CALIBRATIONLOCK_SPINCOUNT); InitializeCriticalSectionAndSpinCount(&calibration.data_lock, DATALOCK_SPINCOUNT); +#endif return PR_SUCCESS; } @@ -258,7 +285,11 @@ PRMJ_NowShutdown() #define MUTEX_LOCK(m) EnterCriticalSection(m) #define MUTEX_TRYLOCK(m) TryEnterCriticalSection(m) #define MUTEX_UNLOCK(m) LeaveCriticalSection(m) +#ifdef WINCE +#define MUTEX_SETSPINCOUNT(m, c) +#else #define MUTEX_SETSPINCOUNT(m, c) SetCriticalSectionSpinCount((m),(c)) +#endif static PRCallOnceType calibrationOnce = { 0 }; @@ -312,7 +343,7 @@ PRMJ_Now(void) return s; } -#elif defined(HAVE_GETSYSTEMTIMEASFILETIME) +#else /* Win32 python-esque pseudo code @@ -395,7 +426,7 @@ PRMJ_Now(void) int thiscall = JS_ATOMIC_INCREMENT(&nCalls); /* 10 seems to be the number of calls to load with a blank homepage */ if (thiscall <= 10) { - GetSystemTimeAsFileTime(&ft); + LowResTime(&ft); return (FILETIME2INT64(ft)-win2un)/10L; } @@ -427,7 +458,7 @@ PRMJ_Now(void) /* Calculate a low resolution time */ - GetSystemTimeAsFileTime(&ft); + LowResTime(&ft); lowresTime = 0.1*(long double)(FILETIME2INT64(ft) - win2un); if (calibration.freq > 0.0) { @@ -453,6 +484,10 @@ PRMJ_Now(void) returnedTime = calibration.last; MUTEX_UNLOCK(&calibration.data_lock); +#ifdef WINCE + /* Get an estimate of clock ticks per second from our own test */ + skewThreshold = calibration.granularity; +#else /* Rather than assume the NT kernel ticks every 15.6ms, ask it */ if (GetSystemTimeAdjustment(&timeAdjustment, &timeIncrement, @@ -465,7 +500,7 @@ PRMJ_Now(void) skewThreshold = timeIncrement/10.0; } } - +#endif /* Check for clock skew */ diff = lowresTime - highresTime; @@ -514,20 +549,6 @@ PRMJ_Now(void) return returnedTime; } - -#elif defined (HAVE_SYSTEMTIMETOFILETIME) -JSInt64 -PRMJ_Now(void) -{ - FILETIME ft; - SYSTEMTIME st; - GetSystemTime(&st); - SystemTimeToFileTime(&st,&ft); - return (FILETIME2INT64(ft)-win2un)/10L; -} - -#else -#error "No implementation of PRMJ_Now was selected." #endif /* Get the DST timezone offset for the time passed in */ diff --git a/js/src/prmjtime.h b/js/src/prmjtime.h index 9005ef82351..2ff07eb378f 100644 --- a/js/src/prmjtime.h +++ b/js/src/prmjtime.h @@ -78,7 +78,7 @@ extern JSInt64 PRMJ_Now(void); /* Release the resources associated with PRMJ_Now; don't call PRMJ_Now again */ -#if defined(JS_THREADSAFE) && defined(HAVE_GETSYSTEMTIMEASFILETIME) +#if defined(JS_THREADSAFE) && (defined(HAVE_GETSYSTEMTIMEASFILETIME) || defined(HAVE_SYSTEMTIMETOFILETIME)) extern void PRMJ_NowShutdown(void); #else