mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
implement usleep for win32
This commit is contained in:
parent
37f135ceef
commit
dd60413c61
2 changed files with 12 additions and 29 deletions
|
@ -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
|
||||
|
|
34
win32/time.c
34
win32/time.c
|
@ -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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
SetWaitableTimer(timer, &due, 0, NULL, NULL, 0);
|
||||
WaitForSingleObject(timer, INFINITE);
|
||||
CloseHandle(timer);
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_SETITIMER
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue