mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
evutil_time: improve evutil_gettimeofday on Windows
If present, use GetSystemTimePreciseAsFileTime instead of GetSystemTimeAsFileTime. Available since Windows 8. (cherry picked from commit f0b3160f8ce7fbd411493dcd023f562f4f9d17ee)
This commit is contained in:
parent
1fce771dc8
commit
a821914368
@ -65,6 +65,9 @@
|
|||||||
|
|
||||||
#ifndef EVENT__HAVE_GETTIMEOFDAY
|
#ifndef EVENT__HAVE_GETTIMEOFDAY
|
||||||
/* No gettimeofday; this must be windows. */
|
/* No gettimeofday; this must be windows. */
|
||||||
|
|
||||||
|
typedef void (WINAPI *GetSystemTimePreciseAsFileTime_fn_t) (LPFILETIME);
|
||||||
|
|
||||||
int
|
int
|
||||||
evutil_gettimeofday(struct timeval *tv, struct timezone *tz)
|
evutil_gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||||
{
|
{
|
||||||
@ -90,7 +93,22 @@ evutil_gettimeofday(struct timeval *tv, struct timezone *tz)
|
|||||||
if (tv == NULL)
|
if (tv == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
GetSystemTimeAsFileTime(&ft.ft_ft);
|
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)) {
|
if (EVUTIL_UNLIKELY(ft.ft_64 < EPOCH_BIAS)) {
|
||||||
/* Time before the unix epoch. */
|
/* Time before the unix epoch. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user