Index: pthread_cond.c =================================================================== RCS file: /cvsroot/src/lib/libpthread/pthread_cond.c,v retrieving revision 1.59 diff -u -p -u -r1.59 pthread_cond.c --- pthread_cond.c 21 Mar 2013 16:49:12 -0000 1.59 +++ pthread_cond.c 28 Mar 2013 17:27:13 -0000 @@ -75,6 +75,13 @@ __strong_alias(__libc_cond_wait,pthread_ __strong_alias(__libc_cond_timedwait,pthread_cond_timedwait) __strong_alias(__libc_cond_destroy,pthread_cond_destroy) +static clockid_t +pthread_cond_getclock(const pthread_cond_t *cond) +{ + return cond->ptc_private ? + *(clockid_t *)cond->ptc_private : CLOCK_REALTIME; +} + int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) { @@ -135,6 +142,19 @@ pthread_cond_timedwait(pthread_cond_t *c pthread__error(EPERM, "Mutex not locked in condition wait", mutex->ptm_owner != NULL); if (abstime != NULL) { + /* + * XXX: This should be done in the kernel to avoid + * extra system calls! + */ + if (pthread_cond_getclock(cond) == CLOCK_MONOTONIC) { + struct timespec mono, real; + if (clock_gettime(CLOCK_REALTIME, &real) == -1 || + clock_gettime(CLOCK_MONOTONIC, &mono) == -1) + return errno; + timespecsub(abstime, &mono, &mono); + timespecadd(&mono, &real, &mono); + abstime = &mono; + } pthread__error(EINVAL, "Invalid wait time", (abstime->tv_sec >= 0) && (abstime->tv_nsec >= 0) && @@ -390,8 +410,7 @@ pthread_cond_wait_nothread(pthread_t sel diff.tv_sec = 99999999; diff.tv_nsec = 0; } else { - clockid_t clck = cond->ptc_private ? - *(clockid_t *)cond->ptc_private : CLOCK_REALTIME; + clockid_t clck = pthread_cond_getclock(cond); clock_gettime(clck, &now); if (timespeccmp(abstime, &now, <)) timespecclear(&diff);