diff options
Diffstat (limited to 'lib/libpthread')
-rw-r--r-- | lib/libpthread/uthread/pthread_private.h | 9 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_cond.c | 41 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_mutex.c | 20 |
3 files changed, 54 insertions, 16 deletions
diff --git a/lib/libpthread/uthread/pthread_private.h b/lib/libpthread/uthread/pthread_private.h index 7643b99a19c..ef7b7e838e2 100644 --- a/lib/libpthread/uthread/pthread_private.h +++ b/lib/libpthread/uthread/pthread_private.h @@ -31,7 +31,7 @@ * * Private thread definitions for the uthread kernel. * - * $OpenBSD: pthread_private.h,v 1.14 1999/05/26 00:18:21 d Exp $ + * $OpenBSD: pthread_private.h,v 1.15 1999/06/09 07:06:54 d Exp $ * */ @@ -214,7 +214,8 @@ struct pthread_mutex { */ #define PTHREAD_MUTEX_STATIC_INITIALIZER \ { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, TAILQ_INITIALIZER, \ - NULL, { NULL }, MUTEX_FLAGS_INITED, 0, 0, 0, TAILQ_INITIALIZER } + NULL, { NULL }, 0, 0, 0, 0, TAILQ_INITIALIZER, \ + _SPINLOCK_INITIALIZER } struct pthread_mutex_attr { enum pthread_mutextype m_type; @@ -260,8 +261,8 @@ struct pthread_cond_attr { * Static cond initialization values. */ #define PTHREAD_COND_STATIC_INITIALIZER \ - { COND_TYPE_FAST, PTHREAD_QUEUE_INITIALIZER, NULL, NULL, \ - COND_FLAGS_INITED } + { COND_TYPE_FAST, PTHREAD_QUEUE_INITIALIZER, NULL, NULL, \ + 0, _SPINLOCK_INITIALIZER } /* * Cleanup definitions. diff --git a/lib/libpthread/uthread/uthread_cond.c b/lib/libpthread/uthread/uthread_cond.c index 501ad84478a..aef5daac188 100644 --- a/lib/libpthread/uthread/uthread_cond.c +++ b/lib/libpthread/uthread/uthread_cond.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_cond.c,v 1.6 1999/05/26 00:18:23 d Exp $ */ +/* $OpenBSD: uthread_cond.c,v 1.7 1999/06/09 07:06:54 d Exp $ */ /* * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. * All rights reserved. @@ -137,6 +137,9 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex) { int rval = 0; + /* This is a cancellation point: */ + _thread_enter_cancellation_point(); + if (cond == NULL) rval = EINVAL; @@ -146,8 +149,14 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex) */ else if (*cond != NULL || (rval = pthread_cond_init(cond,NULL)) == 0) { - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); + /* + * If the condvar was statically allocated, properly + * initialize the tail queue. + */ + if (((*cond)->c_flags & COND_FLAGS_INITED) == 0) { + TAILQ_INIT(&(*cond)->c_queue); + (*cond)->c_flags |= COND_FLAGS_INITED; + } /* Lock the condition variable structure: */ _SPINLOCK(&(*cond)->lock); @@ -219,11 +228,11 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex) rval = EINVAL; break; } - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); } + /* No longer in a cancellation point: */ + _thread_leave_cancellation_point(); + /* Return the completion status: */ return (rval); } @@ -234,6 +243,9 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex, { int rval = 0; + /* This is a cancellation point: */ + _thread_enter_cancellation_point(); + if (cond == NULL) rval = EINVAL; @@ -243,8 +255,15 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex, */ else if (*cond != NULL || (rval = pthread_cond_init(cond,NULL)) == 0) { - /* This is a cancellation point: */ - _thread_enter_cancellation_point(); + /* + * If the condvar was statically allocated, properly + * initialize the tail queue. + */ + if (((*cond)->c_flags & COND_FLAGS_INITED) == 0) { + TAILQ_INIT(&(*cond)->c_queue); + (*cond)->c_flags |= COND_FLAGS_INITED; + } + /* Lock the condition variable structure: */ _SPINLOCK(&(*cond)->lock); @@ -348,11 +367,11 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex, rval = EINVAL; break; } - - /* No longer in a cancellation point: */ - _thread_leave_cancellation_point(); } + /* No longer in a cancellation point: */ + _thread_leave_cancellation_point(); + /* Return the completion status: */ return (rval); } diff --git a/lib/libpthread/uthread/uthread_mutex.c b/lib/libpthread/uthread/uthread_mutex.c index 1968c953a27..8cb8760046c 100644 --- a/lib/libpthread/uthread/uthread_mutex.c +++ b/lib/libpthread/uthread/uthread_mutex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_mutex.c,v 1.7 1999/05/26 00:18:25 d Exp $ */ +/* $OpenBSD: uthread_mutex.c,v 1.8 1999/06/09 07:06:54 d Exp $ */ /* * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. * All rights reserved. @@ -223,6 +223,15 @@ pthread_mutex_trylock(pthread_mutex_t * mutex) */ else if (*mutex != NULL || (ret = init_static(mutex)) == 0) { /* + * If the mutex was statically allocated, properly + * initialize the tail queue. + */ + if (((*mutex)->m_flags & MUTEX_FLAGS_INITED) == 0) { + TAILQ_INIT(&(*mutex)->m_queue); + (*mutex)->m_flags |= MUTEX_FLAGS_INITED; + } + + /* * Guard against being preempted by a scheduling signal. * To support priority inheritence mutexes, we need to * maintain lists of mutex ownerships for each thread as @@ -353,6 +362,15 @@ pthread_mutex_lock(pthread_mutex_t * mutex) */ else if (*mutex != NULL || (ret = init_static(mutex)) == 0) { /* + * If the mutex was statically allocated, properly + * initialize the tail queue. + */ + if (((*mutex)->m_flags & MUTEX_FLAGS_INITED) == 0) { + TAILQ_INIT(&(*mutex)->m_queue); + (*mutex)->m_flags |= MUTEX_FLAGS_INITED; + } + + /* * Guard against being preempted by a scheduling signal. * To support priority inheritence mutexes, we need to * maintain lists of mutex ownerships for each thread as |