From d42240d1c60ea1386489391dfc650d2f2bda4c99 Mon Sep 17 00:00:00 2001 From: yuangongji Date: Fri, 27 Dec 2019 17:53:28 +0800 Subject: [PATCH] evutil_time: Implements usleep() using wait funtion on Windows (cherry picked from commit 6412f34f242e9b5b87f0378715baf97ba0bf1a8c) --- evutil_time.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/evutil_time.c b/evutil_time.c index c576463b..9faa8ce7 100644 --- a/evutil_time.c +++ b/evutil_time.c @@ -126,8 +126,22 @@ evutil_usleep_(const struct timeval *tv) return; #if defined(_WIN32) { - long msec = evutil_tv_to_msec_(tv); - Sleep((DWORD)msec); + __int64 usec; + LARGE_INTEGER li; + HANDLE timer; + + usec = tv->tv_sec * 1000000LL + tv->tv_usec; + if (!usec) + return; + + li.QuadPart = -10LL * usec; + timer = CreateWaitableTimer(NULL, TRUE, NULL); + if (!timer) + return; + + SetWaitableTimer(timer, &li, 0, NULL, NULL, 0); + WaitForSingleObject(timer, INFINITE); + CloseHandle(timer); } #elif defined(EVENT__HAVE_NANOSLEEP) {