summaryrefslogtreecommitdiffstats
path: root/lib/libthr
diff options
context:
space:
mode:
authormtm <mtm@FreeBSD.org>2003-05-15 18:17:13 +0000
committermtm <mtm@FreeBSD.org>2003-05-15 18:17:13 +0000
commit2dcd31b90a6c6e72607e9798a06896d3806fd7a9 (patch)
treeb61383b6a3c541529a05d087b64fd9091479373d /lib/libthr
parent3100b1e28046ab92a2ed60fd300fbaf76de1ed56 (diff)
downloadFreeBSD-src-2dcd31b90a6c6e72607e9798a06896d3806fd7a9.zip
FreeBSD-src-2dcd31b90a6c6e72607e9798a06896d3806fd7a9.tar.gz
Do some cleanup with respect to condition variables. The implementation
of pthread_cond_timedwait() is moved into cond_wait_common(). Pthread_cond_wait() and pthread_cond_timedwait() are now wrappers around this function. Previously, the former called the latter with the abstime pointing to 0 time. This violated Posix semantics should an application have reason to call it with that argument because instead or returning immediately it would have waited indefinitely for the cv to be signaled. Approved by: markm/mentor, re/blanket libthr Reviewed by: jeff
Diffstat (limited to 'lib/libthr')
-rw-r--r--lib/libthr/thread/thr_cond.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/lib/libthr/thread/thr_cond.c b/lib/libthr/thread/thr_cond.c
index 2ff97a0..e48b121 100644
--- a/lib/libthr/thread/thr_cond.c
+++ b/lib/libthr/thread/thr_cond.c
@@ -43,6 +43,8 @@
static pthread_t cond_queue_deq(pthread_cond_t);
static void cond_queue_remove(pthread_cond_t, pthread_t);
static void cond_queue_enq(pthread_cond_t, pthread_t);
+static int cond_wait_common(pthread_cond_t *,
+ pthread_mutex_t *, const struct timespec *);
__weak_reference(_pthread_cond_init, pthread_cond_init);
__weak_reference(_pthread_cond_destroy, pthread_cond_destroy);
@@ -161,13 +163,8 @@ int
_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
{
int rval;
- struct timespec abstime = { 0, 0 };
- /*
- * XXXTHR This is a hack. Make a pthread_cond_common function that
- * accepts NULL so we don't change posix semantics for timedwait.
- */
- rval = pthread_cond_timedwait(cond, mutex, &abstime);
+ rval = cond_wait_common(cond, mutex, NULL);
/* This should never happen. */
if (rval == ETIMEDOUT)
@@ -180,7 +177,16 @@ int
_pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
const struct timespec * abstime)
{
- struct timespec *time;
+ if (abstime == NULL || abstime->tv_nsec >= 1000000000)
+ return (EINVAL);
+
+ return (cond_wait_common(cond, mutex, abstime));
+}
+
+static int
+cond_wait_common(pthread_cond_t * cond, pthread_mutex_t * mutex,
+ const struct timespec * abstime)
+{
int rval = 0;
int done = 0;
int seqno;
@@ -189,13 +195,6 @@ _pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
_thread_enter_cancellation_point();
- if (abstime == NULL || abstime->tv_nsec >= 1000000000)
- return (EINVAL);
-
- if (abstime->tv_sec == 0 && abstime->tv_nsec == 0)
- time = NULL;
- else
- time = abstime;
/*
* If the condition variable is statically initialized, perform dynamic
* initialization.
@@ -273,7 +272,7 @@ _pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
PTHREAD_SET_STATE(curthread, PS_COND_WAIT);
GIANT_UNLOCK(curthread);
- rval = _thread_suspend(curthread, time);
+ rval = _thread_suspend(curthread, (struct timespec *)abstime);
if (rval == -1) {
printf("foo");
fflush(stdout);
OpenPOWER on IntegriCloud