Skip to content

Commit dd60413

Browse files
committed
implement usleep for win32
1 parent 37f135c commit dd60413

File tree

2 files changed

+13
-30
lines changed

2 files changed

+13
-30
lines changed

main/config.w32.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@
103103
#undef HAVE_SOLID
104104
#undef HAVE_LINK
105105
#undef HAVE_SYMLINK
106-
#undef HAVE_USLEEP
106+
107+
/* its in win32/time.c */
108+
#define HAVE_USLEEP 1
109+
107110
#define HAVE_GETCWD 1
108111
#define HAVE_POSIX_READDIR_R 1
109112
#define NEED_ISBLANK 1

win32/time.c

+9-29
Original file line numberDiff line numberDiff line change
@@ -126,38 +126,18 @@ PHPAPI int gettimeofday(struct timeval *time_Info, struct timezone *timezone_Inf
126126
return 0;
127127
}
128128

129-
130-
/* this usleep isnt exactly accurate but should do ok */
131129
void usleep(unsigned int useconds)
132130
{
133-
struct timeval tnow, tthen, t0;
134-
135-
gettimeofday(&tthen, NULL);
136-
t0 = tthen;
137-
tthen.tv_usec += useconds;
138-
while (tthen.tv_usec > 1000000) {
139-
tthen.tv_usec -= 1000000;
140-
tthen.tv_sec++;
141-
}
142-
143-
if (useconds > 10000) {
144-
useconds -= 10000;
145-
Sleep(useconds/1000);
146-
}
147-
148-
while (1) {
149-
gettimeofday(&tnow, NULL);
150-
if (tnow.tv_sec > tthen.tv_sec) {
151-
break;
152-
}
153-
if (tnow.tv_sec == tthen.tv_sec) {
154-
if (tnow.tv_usec > tthen.tv_usec) {
155-
break;
156-
}
157-
}
158-
}
159-
}
131+
HANDLE timer;
132+
LARGE_INTEGER due;
133+
134+
due.QuadPart = -useconds * 1000;
135+
timer = CreateWaitableTimer(NULL, TRUE, NULL);
160136

137+
SetWaitableTimer(timer, &due, 0, NULL, NULL, 0);
138+
WaitForSingleObject(timer, INFINITE);
139+
CloseHandle(timer);
140+
}
161141

162142
#ifdef HAVE_SETITIMER
163143

0 commit comments

Comments
 (0)