Bug 1004923 part 12 - Use GetSystemTimePreciseAsFileTime if available (Windows 8). r=njn

This commit is contained in:
Jan de Mooij 2014-05-05 13:12:11 +02:00
parent 50f6afb5fc
commit 0f21f62265

View File

@ -123,6 +123,8 @@ NowCalibrate()
static const unsigned DataLockSpinCount = 4096;
static void (WINAPI *pGetSystemTimePreciseAsFileTime)(LPFILETIME) = nullptr;
void
PRMJ_NowInit()
{
@ -141,6 +143,12 @@ PRMJ_NowInit()
#ifdef JS_THREADSAFE
InitializeCriticalSectionAndSpinCount(&calibration.data_lock, DataLockSpinCount);
#endif
// Windows 8 has a new API function we can use.
if (HMODULE h = GetModuleHandle("kernel32.dll")) {
pGetSystemTimePreciseAsFileTime =
(void (WINAPI *)(LPFILETIME))GetProcAddress(h, "GetSystemTimePreciseAsFileTime");
}
}
#ifdef JS_THREADSAFE
@ -166,6 +174,13 @@ PRMJ_NowShutdown()
int64_t
PRMJ_Now()
{
if (pGetSystemTimePreciseAsFileTime) {
// Windows 8 has a new API function that does all the work.
FILETIME ft;
pGetSystemTimePreciseAsFileTime(&ft);
return int64_t(FileTimeToUnixMicroseconds(ft));
}
bool calibrated = false;
bool needsCalibration = !calibration.calibrated;
double cachedOffset = 0.0;