summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2005-12-13 07:04:35 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2005-12-13 07:04:35 +0000
commit5cd76579013633c8efd815e096c26ad86304e740 (patch)
treeac950ebefc07c95b0c417d3f5aec5cfe6d89e7c3 /lib
parentfabba4b0fc511c15d3ea033f62337e56398b0a1a (diff)
several silly bugs in pthread_cond_timedwait.
1. the time was off by a factor of 10 2. wouldn't return error code if timeout was reached 3. the big one. thrsleep syscall doesn't return EWOULDBLOCK. it returns -1 and puts the error in errno. doh.
Diffstat (limited to 'lib')
-rw-r--r--lib/librthread/rthread_sync.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/librthread/rthread_sync.c b/lib/librthread/rthread_sync.c
index 56b7fcda0d9..d0afd85ce3b 100644
--- a/lib/librthread/rthread_sync.c
+++ b/lib/librthread/rthread_sync.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread_sync.c,v 1.5 2005/12/13 06:04:53 tedu Exp $ */
+/* $OpenBSD: rthread_sync.c,v 1.6 2005/12/13 07:04:34 tedu Exp $ */
/*
* Copyright (c) 2004 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
@@ -64,7 +64,8 @@ again:
}
if (do_sleep) {
- if (thrsleep(sem, timo, &sem->lock) == EWOULDBLOCK)
+ if (thrsleep(sem, timo, &sem->lock) == -1 &&
+ errno == EWOULDBLOCK)
return (0);
_spinlock(&sem->lock);
sem->waitcount--;
@@ -354,17 +355,18 @@ pthread_cond_timedwait(pthread_cond_t *condp, pthread_mutex_t *mutexp,
const struct timespec *abstime)
{
int error;
+ int rv;
if (!*condp)
if ((error = pthread_cond_init(condp, NULL)))
return (error);
pthread_mutex_unlock(mutexp);
- _sem_wait(&(*condp)->sem, 0, (abstime ?
- abstime->tv_sec * 100 + abstime->tv_nsec / 10000000 : 0));
+ rv = _sem_wait(&(*condp)->sem, 0, (abstime ?
+ abstime->tv_sec * 1000 + abstime->tv_nsec / 1000000 : 0));
error = pthread_mutex_lock(mutexp);
- return (error);
+ return (error ? error : rv ? 0 : ETIMEDOUT);
}
int