roken: gettimeofday using GetSystemTimePreciseAsFileTime
GetSystemTimeAsFileTime() has 16ms precision. GetSystemTimePreciseAsFileTime() has <1ns precision but is only available on Windows 8 or later. This change dynamically loads GetSystemTimePreciseAsFileTime() if it is available. Change-Id: Ib9c616c01948384e6b256ac9b6023f1e39673613
This commit is contained in:

committed by
Jeffrey Altman

parent
07b3e6fd74
commit
1feff82129
@ -37,6 +37,10 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
typedef BOOL (WINAPI *LPFN_GETSYSTEMTIME) (LPFILETIME);
|
||||
|
||||
static LPFN_GETSYSTEMTIME lpGetSystemTime = NULL;
|
||||
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
gettimeofday (struct timeval *tp, void *ignore)
|
||||
{
|
||||
@ -44,7 +48,20 @@ gettimeofday (struct timeval *tp, void *ignore)
|
||||
ULARGE_INTEGER li;
|
||||
ULONGLONG ull;
|
||||
|
||||
GetSystemTimeAsFileTime(&ft);
|
||||
if (lpGetSystemTime == NULL) {
|
||||
HANDLE h1;
|
||||
LPFN_GETSYSTEMTIME fn;
|
||||
|
||||
h1 = GetModuleHandle(TEXT("kernel32.dll")); /* no refcount increase */
|
||||
fn = (LPFN_GETSYSTEMTIME)GetProcAddress(h1,
|
||||
"GetSystemTimePreciseAsFileTime");
|
||||
if (fn == NULL)
|
||||
fn = (LPFN_GETSYSTEMTIME)GetProcAddress(h1,
|
||||
"GetSystemTimeAsFileTime");
|
||||
lpGetSystemTime = fn;
|
||||
}
|
||||
|
||||
lpGetSystemTime(&ft);
|
||||
li.LowPart = ft.dwLowDateTime;
|
||||
li.HighPart = ft.dwHighDateTime;
|
||||
ull = li.QuadPart;
|
||||
@ -57,7 +74,6 @@ gettimeofday (struct timeval *tp, void *ignore)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user