OSSP CVS Repository

ossp - Difference in ossp-pkg/pth/pth_high.c versions 1.88 and 1.89
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

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)
 {

CVSTrac 2.0.1