summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWez Furlong <wez@php.net>2003-11-29 22:48:42 +0000
committerWez Furlong <wez@php.net>2003-11-29 22:48:42 +0000
commitdd60413c6198273c27097567913c0b2c75a7e67c (patch)
tree531ee6dfbda4cf4f72fff0a6c6c1b7f4ab24f15e
parent37f135ceeffa522ec558cfac07bd53b98f5867e6 (diff)
downloadphp-git-dd60413c6198273c27097567913c0b2c75a7e67c.tar.gz
implement usleep for win32
-rw-r--r--main/config.w32.h5
-rw-r--r--win32/time.c38
2 files changed, 13 insertions, 30 deletions
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