mirror of
https://github.com/libevent/libevent.git
synced 2025-01-09 00:56:20 +08:00
evutil_time: improve evutil_gettimeofday on Windows
If present, use GetSystemTimePreciseAsFileTime instead of GetSystemTimeAsFileTime. Available since Windows 8.
This commit is contained in:
parent
5caffa7a5b
commit
f0b3160f8c
@ -65,6 +65,9 @@
|
||||
|
||||
#ifndef EVENT__HAVE_GETTIMEOFDAY
|
||||
/* No gettimeofday; this must be windows. */
|
||||
|
||||
typedef void (WINAPI *GetSystemTimePreciseAsFileTime_fn_t) (LPFILETIME);
|
||||
|
||||
int
|
||||
evutil_gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||
{
|
||||
@ -90,6 +93,21 @@ evutil_gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||
if (tv == NULL)
|
||||
return -1;
|
||||
|
||||
static GetSystemTimePreciseAsFileTime_fn_t GetSystemTimePreciseAsFileTime_fn = NULL;
|
||||
static int check_precise = 1;
|
||||
|
||||
if (EVUTIL_UNLIKELY(check_precise)) {
|
||||
HMODULE h = evutil_load_windows_system_library_(TEXT("kernel32.dll"));
|
||||
if (h != NULL)
|
||||
GetSystemTimePreciseAsFileTime_fn =
|
||||
(GetSystemTimePreciseAsFileTime_fn_t)
|
||||
GetProcAddress(h, "GetSystemTimePreciseAsFileTime");
|
||||
check_precise = 0;
|
||||
}
|
||||
|
||||
if (GetSystemTimePreciseAsFileTime_fn != NULL)
|
||||
GetSystemTimePreciseAsFileTime_fn(&ft.ft_ft);
|
||||
else
|
||||
GetSystemTimeAsFileTime(&ft.ft_ft);
|
||||
|
||||
if (EVUTIL_UNLIKELY(ft.ft_64 < EPOCH_BIAS)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user