Check-in Number:
|
2652 | |
Date: |
2002-Oct-23 16:04:00 (local)
2002-Oct-23 14:04:00 (UTC) |
User: | rse |
Branch: | |
Comment: |
Added pth_nanosleep() function.
Obtained from: NetBSD, Nick Hudson <skrll@netbsd.org> |
Tickets: |
|
Inspections: |
|
Files: |
|
ossp-pkg/pth/ChangeLog 1.576 -> 1.577
--- 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 <skrll@netbsd.org>, 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().
|
|
ossp-pkg/pth/pth.h.in 1.132 -> 1.133
--- 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 <sys/types.h> /* for ssize_t, off_t */
-#include <sys/time.h> /* for struct timeval */
-#include <sys/socket.h> /* for sockaddr */
-#include <sys/signal.h> /* for sigset_t */
+#include <sys/types.h> /* for ssize_t, off_t */
+#include <time.h> /* for struct timespec */
+#include <sys/time.h> /* for struct timeval */
+#include <sys/socket.h> /* for sockaddr */
+#include <sys/signal.h> /* 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);
|
|
ossp-pkg/pth/pth.pod 1.155 -> 1.156
--- 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<Standard POSIX Replacement API>
+pth_nanosleep,
pth_usleep,
pth_sleep,
pth_waitpid,
@@ -1585,6 +1586,18 @@
=over 4
+=item int B<pth_nanosleep>(const struct timespec *I<rqtp>, struct timespec *I<rmtp>);
+
+This is a variant of the POSIX nanosleep(3) function. It suspends the
+current threads execution until the amount of time in I<rqtp> elapsed.
+The thread is guaranteed to not wake up before this time, but because
+of the non-preemptive scheduling nature of B<Pth>, it can be awakened
+later, of course. If I<rmtp> is not C<NULL>, the C<timespec> 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<pth_usleep>(unsigned int I<usec>);
This is a variant of the 4.3BSD usleep(3) function. It suspends the current
|
|
ossp-pkg/pth/pth_high.c 1.88 -> 1.89
--- 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)
{
|
|
ossp-pkg/pth/pth_p.h.in 1.32 -> 1.33
--- 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;
|
|
ossp-pkg/pth/pthread.c 1.59 -> 1.60
--- 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)
{
|
|