Skip to content

Commit 274dad3

Browse files
committed
- MFH:
- add nanosleep - expose nanosleep and usleep - [DOC] time_ nanosleep and time_ sleep_ until available on windows - change nanosleep signature to match posix one
1 parent e77326f commit 274dad3

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

ext/standard/basic_functions.c

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
#ifdef PHP_WIN32
4141
#include "win32/php_win32_globals.h"
42+
#include "win32/time.h"
4243
#endif
4344

4445
typedef struct yy_buffer_state *YY_BUFFER_STATE;

win32/build/config.w32.h.in

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
/* its in win32/time.c */
5555
#define HAVE_USLEEP 1
56+
#define HAVE_NANOSLEEP 1
5657

5758
#define HAVE_GETHOSTNAME 1
5859
#define HAVE_GETCWD 1

win32/time.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ PHPAPI int gettimeofday(struct timeval *time_Info, struct timezone *timezone_Inf
127127
return 0;
128128
}
129129

130-
void usleep(unsigned int useconds)
130+
PHPAPI int usleep(unsigned int useconds)
131131
{
132132
HANDLE timer;
133133
LARGE_INTEGER due;
@@ -138,6 +138,17 @@ void usleep(unsigned int useconds)
138138
SetWaitableTimer(timer, &due, 0, NULL, NULL, 0);
139139
WaitForSingleObject(timer, INFINITE);
140140
CloseHandle(timer);
141+
return 0;
142+
}
143+
144+
PHPAPI int nanosleep( const struct timespec * rqtp, struct timespec * rmtp )
145+
{
146+
if (rqtp->tv_nsec > 999999999) {
147+
/* The time interval specified 1,000,000 or more microseconds. */
148+
errno = EINVAL;
149+
return -1;
150+
}
151+
return usleep( rqtp->tv_sec * 1000000 + rqtp->tv_nsec / 1000 );
141152
}
142153

143154
#if 0 /* looks pretty ropey in here */

win32/time.h

+10
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ struct itimerval {
2828
struct timeval it_value; /* current value */
2929
};
3030

31+
#ifndef timespec
32+
struct timespec
33+
{
34+
time_t tv_sec; /* seconds */
35+
long tv_nsec; /* nanoseconds */
36+
};
37+
#endif
38+
3139
#define ITIMER_REAL 0 /*generates sigalrm */
3240
#define ITIMER_VIRTUAL 1 /*generates sigvtalrm */
3341
#define ITIMER_VIRT 1 /*generates sigvtalrm */
@@ -40,4 +48,6 @@ PHPAPI extern int gettimeofday(struct timeval *time_Info, struct timezone *timez
4048
PHPAPI extern int setitimer(int which, const struct itimerval *value,
4149
struct itimerval *ovalue);
4250

51+
PHPAPI int nanosleep( const struct timespec * rqtp, struct timespec * rmtp );
52+
4353
#endif

win32/unistd.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#ifndef _PHP_WIN32_UNISTD_H
22
#define _PHP_WIN32_UNISTD_H
3-
void usleep(unsigned int useconds);
3+
PHPAPI int usleep(unsigned int useconds);
44
#endif

0 commit comments

Comments
 (0)