summaryrefslogtreecommitdiff
path: root/lib/libpthread/pthread_cond.c
diff options
context:
space:
mode:
authormycroft <mycroft@NetBSD.org>2005-01-06 17:33:36 +0000
committermycroft <mycroft@NetBSD.org>2005-01-06 17:33:36 +0000
commit8fa85b4a6533033ea7fbe7c66ecfba8b89b62461 (patch)
treed3d5f664586f3796147b5c521872417be455f8a9 /lib/libpthread/pthread_cond.c
parent9d30c15dda5a57b217a74d8236c44525e2a802bc (diff)
gettimeofday();TIMEVAL_TO_TIMESPEC(); is exactly equivalent to
clock_gettime(CLOCK_REALTIME), except the latter may have more preicison some day. So, use that.
Diffstat (limited to 'lib/libpthread/pthread_cond.c')
-rw-r--r--lib/libpthread/pthread_cond.c42
1 files changed, 18 insertions, 24 deletions
diff --git a/lib/libpthread/pthread_cond.c b/lib/libpthread/pthread_cond.c
index 3b83eab2894..2686bdf9f85 100644
--- a/lib/libpthread/pthread_cond.c
+++ b/lib/libpthread/pthread_cond.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_cond.c,v 1.17 2004/12/10 17:11:53 nathanw Exp $ */
+/* $NetBSD: pthread_cond.c,v 1.18 2005/01/06 17:33:36 mycroft Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_cond.c,v 1.17 2004/12/10 17:11:53 nathanw Exp $");
+__RCSID("$NetBSD: pthread_cond.c,v 1.18 2005/01/06 17:33:36 mycroft Exp $");
#include <errno.h>
#include <sys/time.h>
@@ -52,7 +52,7 @@ __RCSID("$NetBSD: pthread_cond.c,v 1.17 2004/12/10 17:11:53 nathanw Exp $");
#define SDPRINTF(x)
#endif
-int _sys_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
+int _sys_nanosleep(const struct timespec *, struct timespec *);
extern int pthread__started;
@@ -363,32 +363,26 @@ static int
pthread_cond_wait_nothread(pthread_t self, pthread_mutex_t *mutex,
const struct timespec *abstime)
{
- struct timeval now, tv, *tvp;
+ struct timespec now, diff;
int retval;
- if (abstime == NULL)
- tvp = NULL;
- else {
- tvp = &tv;
- gettimeofday(&now, NULL);
- TIMESPEC_TO_TIMEVAL(tvp, abstime);
-
- if (timercmp(tvp, &now, <))
- timerclear(tvp);
+ if (abstime == NULL) {
+ diff.tv_sec = 99999999;
+ diff.tv_nsec = 0;
+ } else {
+ clock_gettime(CLOCK_REALTIME, &now);
+ if (timespeccmp(abstime, &now, <))
+ timespecclear(&diff);
else
- timersub(tvp, &now, tvp);
+ timespecsub(abstime, &now, &diff);
}
- /*
- * The libpthread select() wrapper has cancellation tests, but
- * we need to have the mutex locked when testing for
- * cancellation and unlocked while we sleep. So, skip the
- * wrapper.
- */
- pthread__testcancel(self);
- pthread_mutex_unlock(mutex);
- retval = _sys_select(0, NULL, NULL, NULL, tvp);
- pthread_mutex_lock(mutex);
+ do {
+ pthread__testcancel(self);
+ pthread_mutex_unlock(mutex);
+ retval = _sys_nanosleep(&diff, NULL);
+ pthread_mutex_lock(mutex);
+ } while (abstime == NULL && retval == 0);
pthread__testcancel(self);
if (retval == 0)