implement usleep for win32

This commit is contained in:
Wez Furlong 2003-11-29 22:48:42 +00:00
parent 37f135ceef
commit dd60413c61
2 changed files with 12 additions and 29 deletions

View file

@ -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

View file

@ -126,39 +126,19 @@ 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;
HANDLE timer;
LARGE_INTEGER due;
gettimeofday(&tthen, NULL);
t0 = tthen;
tthen.tv_usec += useconds;
while (tthen.tv_usec > 1000000) {
tthen.tv_usec -= 1000000;
tthen.tv_sec++;
}
due.QuadPart = -useconds * 1000;
timer = CreateWaitableTimer(NULL, TRUE, NULL);
if (useconds > 10000) {
useconds -= 10000;
Sleep(useconds/1000);
SetWaitableTimer(timer, &due, 0, NULL, NULL, 0);
WaitForSingleObject(timer, INFINITE);
CloseHandle(timer);
}
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;
}
}
}
}
#ifdef HAVE_SETITIMER