]> granicus.if.org Git - php/commitdiff
implement usleep for win32
authorWez Furlong <wez@php.net>
Sat, 29 Nov 2003 22:48:42 +0000 (22:48 +0000)
committerWez Furlong <wez@php.net>
Sat, 29 Nov 2003 22:48:42 +0000 (22:48 +0000)
main/config.w32.h
win32/time.c

index 48fb39d943a3461736a95f00b94edaf81157f7c1..6b5db664b7591293d65ace85a01a07e674794a1f 100644 (file)
 #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
index 9f07fab862ce8430fb3c07708bca1177819b8324..f77dfd2ff8f52914b3a6496d46266f34028c9de4 100644 (file)
@@ -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