Index: ossp-pkg/pth/ChangeLog RCS File: /v/ossp/cvs/ossp-pkg/pth/ChangeLog,v rcsdiff -q -kk '-r1.576' '-r1.577' -u '/v/ossp/cvs/ossp-pkg/pth/ChangeLog,v' 2>/dev/null --- ChangeLog 2002/10/23 13:55:49 1.576 +++ ChangeLog 2002/10/23 14:04:00 1.577 @@ -21,6 +21,9 @@ Changes between 1.4.1 and 1.5.0 (27-Jan-2002 to xx-Oct-2002) + *) Added pth_nanosleep() function. + [Nick Hudson , Ralf S. Engelschall] + *) Allow a NULL name for pth_msgport_create() in order to support locally scoped message ports which are not searched via pth_msgport_find(). Index: ossp-pkg/pth/pth.h.in RCS File: /v/ossp/cvs/ossp-pkg/pth/pth.h.in,v rcsdiff -q -kk '-r1.132' '-r1.133' -u '/v/ossp/cvs/ossp-pkg/pth/pth.h.in,v' 2>/dev/null --- pth.h.in 2002/10/15 21:14:27 1.132 +++ pth.h.in 2002/10/23 14:04:00 1.133 @@ -39,10 +39,11 @@ #endif /* essential headers */ -#include /* for ssize_t, off_t */ -#include /* for struct timeval */ -#include /* for sockaddr */ -#include /* for sigset_t */ +#include /* for ssize_t, off_t */ +#include /* for struct timespec */ +#include /* for struct timeval */ +#include /* for sockaddr */ +#include /* for sigset_t */ @EXTRA_INCLUDE_SYS_SELECT_H@ /* fallbacks for essential typedefs */ @@ -58,6 +59,7 @@ /* extra structure definitions */ struct timeval; +struct timespec; /* essential values */ #ifndef FALSE @@ -492,6 +494,7 @@ extern ssize_t pth_sendto_ev(int, const void *, size_t, int, const struct sockaddr *, socklen_t, pth_event_t); /* standard replacement functions */ +extern int pth_nanosleep(const struct timespec *, struct timespec *); extern int pth_usleep(unsigned int); extern unsigned int pth_sleep(unsigned int); extern pid_t pth_waitpid(pid_t, int *, int); Index: ossp-pkg/pth/pth.pod RCS File: /v/ossp/cvs/ossp-pkg/pth/pth.pod,v rcsdiff -q -kk '-r1.155' '-r1.156' -u '/v/ossp/cvs/ossp-pkg/pth/pth.pod,v' 2>/dev/null --- pth.pod 2002/10/23 13:55:49 1.155 +++ pth.pod 2002/10/23 14:04:00 1.156 @@ -156,6 +156,7 @@ =item B +pth_nanosleep, pth_usleep, pth_sleep, pth_waitpid, @@ -1585,6 +1586,18 @@ =over 4 +=item int B(const struct timespec *I, struct timespec *I); + +This is a variant of the POSIX nanosleep(3) function. It suspends the +current threads execution until the amount of time in I elapsed. +The thread is guaranteed to not wake up before this time, but because +of the non-preemptive scheduling nature of B, it can be awakened +later, of course. If I is not C, the C structure +it references is updated to contain the unslept amount (the request time +minus the time actually slept time). The difference between nanosleep(3) +and pth_nanosleep(3) is that that pth_nanosleep(3) suspends only the +execution of the current thread and not the whole process. + =item int B(unsigned int I); This is a variant of the 4.3BSD usleep(3) function. It suspends the current Index: ossp-pkg/pth/pth_high.c RCS File: /v/ossp/cvs/ossp-pkg/pth/pth_high.c,v rcsdiff -q -kk '-r1.88' '-r1.89' -u '/v/ossp/cvs/ossp-pkg/pth/pth_high.c,v' 2>/dev/null --- pth_high.c 2002/10/20 17:49:03 1.88 +++ pth_high.c 2002/10/23 14:04:00 1.89 @@ -35,6 +35,45 @@ #include "pth_p.h" +/* Pth variant of nanosleep(2) */ +int pth_nanosleep(const struct timespec *rqtp, struct timespec *rmtp) +{ + pth_time_t until; + pth_time_t offset; + pth_time_t now; + pth_event_t ev; + static pth_key_t ev_key = PTH_KEY_INIT; + + /* consistency checks for POSIX conformance */ + if (rqtp == NULL) + return_errno(-1, EFAULT); + if (rqtp->tv_nsec < 0 || rqtp->tv_nsec > (1000*1000000)) + return_errno(-1, EINVAL); + + /* short-circuit */ + if (rqtp->tv_sec == 0 && rqtp->tv_nsec == 0) + return 0; + + /* calculate asleep time */ + offset = pth_time((long)(rqtp->tv_sec), (long)(rqtp->tv_nsec) / 1000); + pth_time_set(&until, PTH_TIME_NOW); + pth_time_add(&until, &offset); + + /* and let thread sleep until this time is elapsed */ + ev = pth_event(PTH_EVENT_TIME|PTH_MODE_STATIC, &ev_key, until); + pth_wait(ev); + + /* optionally provide amount of slept time */ + if (rmtp != NULL) { + pth_time_set(&now, PTH_TIME_NOW); + pth_time_sub(&until, &now); + rmtp->tv_sec = until.tv_sec; + rmtp->tv_nsec = until.tv_usec * 1000; + } + + return 0; +} + /* Pth variant of usleep(3) */ int pth_usleep(unsigned int usec) { Index: ossp-pkg/pth/pth_p.h.in RCS File: /v/ossp/cvs/ossp-pkg/pth/pth_p.h.in,v rcsdiff -q -kk '-r1.32' '-r1.33' -u '/v/ossp/cvs/ossp-pkg/pth/pth_p.h.in,v' 2>/dev/null --- pth_p.h.in 2002/10/20 11:45:10 1.32 +++ pth_p.h.in 2002/10/23 14:04:00 1.33 @@ -104,6 +104,14 @@ #endif #endif +/* fallback definition for struct timespec */ +#ifndef HAVE_STRUCT_TIMESPEC +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; +#endif + /* compiler happyness: avoid ``empty compilation unit'' problem */ #define COMPILER_HAPPYNESS(name) \ int __##name##_unit = 0; Index: ossp-pkg/pth/pthread.c RCS File: /v/ossp/cvs/ossp-pkg/pth/pthread.c,v rcsdiff -q -kk '-r1.59' '-r1.60' -u '/v/ossp/cvs/ossp-pkg/pth/pthread.c,v' 2>/dev/null --- pthread.c 2002/10/15 20:34:23 1.59 +++ pthread.c 2002/10/23 14:04:00 1.60 @@ -989,13 +989,6 @@ return OK; } -#ifndef HAVE_STRUCT_TIMESPEC -struct timespec { - time_t tv_sec; /* seconds */ - long tv_nsec; /* and nanoseconds */ -}; -#endif - int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime) {