From: Wez Furlong Date: Sat, 29 Nov 2003 22:48:42 +0000 (+0000) Subject: implement usleep for win32 X-Git-Tag: php-5.0.0b3RC1~501 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dd60413c6198273c27097567913c0b2c75a7e67c;p=php implement usleep for win32 --- diff --git a/main/config.w32.h b/main/config.w32.h index 48fb39d943..6b5db664b7 100644 --- a/main/config.w32.h +++ b/main/config.w32.h @@ -103,7 +103,10 @@ #undef HAVE_SOLID #undef HAVE_LINK #undef HAVE_SYMLINK -#undef HAVE_USLEEP + +/* its in win32/time.c */ +#define HAVE_USLEEP 1 + #define HAVE_GETCWD 1 #define HAVE_POSIX_READDIR_R 1 #define NEED_ISBLANK 1 diff --git a/win32/time.c b/win32/time.c index 9f07fab862..f77dfd2ff8 100644 --- a/win32/time.c +++ b/win32/time.c @@ -126,38 +126,18 @@ PHPAPI int gettimeofday(struct timeval *time_Info, struct timezone *timezone_Inf return 0; } - -/* this usleep isnt exactly accurate but should do ok */ void usleep(unsigned int useconds) { -struct timeval tnow, tthen, t0; - - gettimeofday(&tthen, NULL); - t0 = tthen; - tthen.tv_usec += useconds; - while (tthen.tv_usec > 1000000) { - tthen.tv_usec -= 1000000; - tthen.tv_sec++; - } - - if (useconds > 10000) { - useconds -= 10000; - Sleep(useconds/1000); - } - - while (1) { - gettimeofday(&tnow, NULL); - if (tnow.tv_sec > tthen.tv_sec) { - break; - } - if (tnow.tv_sec == tthen.tv_sec) { - if (tnow.tv_usec > tthen.tv_usec) { - break; - } - } - } -} + HANDLE timer; + LARGE_INTEGER due; + + due.QuadPart = -useconds * 1000; + timer = CreateWaitableTimer(NULL, TRUE, NULL); + SetWaitableTimer(timer, &due, 0, NULL, NULL, 0); + WaitForSingleObject(timer, INFINITE); + CloseHandle(timer); +} #ifdef HAVE_SETITIMER