]> granicus.if.org Git - libevent/commitdiff
evutil_time: Implements usleep() using wait funtion on Windows
authoryuangongji <yuangongji@foxmail.com>
Fri, 27 Dec 2019 09:53:28 +0000 (17:53 +0800)
committerAzat Khuzhin <azat@libevent.org>
Mon, 30 Dec 2019 21:37:29 +0000 (00:37 +0300)
evutil_time.c

index c576463ba78387df234820c5989ed454d2117030..9faa8ce71919f87b478196223eb1c8ebe7975c47 100644 (file)
@@ -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)
        {