]> granicus.if.org Git - php/commitdiff
- add nanosleep
authorPierre Joye <pajoye@php.net>
Mon, 19 Jan 2009 02:29:24 +0000 (02:29 +0000)
committerPierre Joye <pajoye@php.net>
Mon, 19 Jan 2009 02:29:24 +0000 (02:29 +0000)
- expose nanosleep and usleep
- [DOC] time_ nanosleep and time_ sleep_ until available on windows

win32/time.c
win32/time.h
win32/unistd.h

index 816eb63b1444758bada9a1998decb6f0c46a8a57..808ce8d5bd41326545d9df1e5dbfc6821d51ad74 100644 (file)
@@ -127,7 +127,7 @@ PHPAPI int gettimeofday(struct timeval *time_Info, struct timezone *timezone_Inf
        return 0;
 }
 
-void usleep(unsigned int useconds)
+PHPAPI int usleep(unsigned int useconds)
 {
        HANDLE timer;
        LARGE_INTEGER due;
@@ -138,6 +138,17 @@ void usleep(unsigned int useconds)
        SetWaitableTimer(timer, &due, 0, NULL, NULL, 0);
        WaitForSingleObject(timer, INFINITE);
        CloseHandle(timer);
+       return 0;
+}
+
+PHPAPI int nanosleep( const struct timespec * rqtp, struct timespec * rmtp )
+{
+       if (rqtp->tv_nsec > 999999999) {
+               /* The time interval specified 1,000,000 or more microseconds. */
+               errno = EINVAL;
+               return -1;
+       }
+       return usleep( rqtp->tv_sec * 1000000 + rqtp->tv_nsec / 1000  );
 }
 
 #if 0 /* looks pretty ropey in here */
index 5c52e7837e16610b35427a0695be9e00216d678d..f841a2b601fe355cb4379b3e38a852838f8d9eb0 100644 (file)
@@ -28,6 +28,14 @@ struct itimerval {
        struct timeval it_value;        /* current value */
 };
 
+#ifndef timespec
+struct timespec
+{
+       time_t   tv_sec;   /* seconds */
+       long     tv_nsec;  /* nanoseconds */
+};
+#endif
+
 #define ITIMER_REAL    0               /*generates sigalrm */
 #define ITIMER_VIRTUAL 1               /*generates sigvtalrm */
 #define ITIMER_VIRT    1               /*generates sigvtalrm */
@@ -40,4 +48,6 @@ PHPAPI extern int gettimeofday(struct timeval *time_Info, struct timezone *timez
 PHPAPI extern int setitimer(int which, const struct itimerval *value,
                                         struct itimerval *ovalue);
 
+PHPAPI int nanosleep( const struct timespec * rqtp, struct timespec * rmtp );
+
 #endif
index 96e0aedc13475a3eb89af0f0e7b525a18b9e1174..0b9446149c59a13657900f5f6b5335d84aab54a0 100644 (file)
@@ -1,4 +1,4 @@
 #ifndef _PHP_WIN32_UNISTD_H
 #define _PHP_WIN32_UNISTD_H
-void usleep(unsigned int useconds);
+PHPAPI int usleep(unsigned int useconds);
 #endif