diff options
author | Kurt Miller <kurt@cvs.openbsd.org> | 2012-04-13 13:50:38 +0000 |
---|---|---|
committer | Kurt Miller <kurt@cvs.openbsd.org> | 2012-04-13 13:50:38 +0000 |
commit | e0f09140df4d1589ba0508b4df463185b68f2d1d (patch) | |
tree | bc30fdb57475affc289b31ee2310a992f163dcf0 /lib/librthread/rthread_sync.c | |
parent | 28e13e25d7be4da391c39ddc355060d5c010dcf0 (diff) |
Use PTHREAD_MUTEX_DEFAULT in static init and mutexattr_init. If the
default mutex type changes to NORMAL, when there is an uninitialized
mutex provided to unlock, allow it to succeed similar to an unlocked
mutex. For other cases abort instead of segfault. okay guenther@
Diffstat (limited to 'lib/librthread/rthread_sync.c')
-rw-r--r-- | lib/librthread/rthread_sync.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/librthread/rthread_sync.c b/lib/librthread/rthread_sync.c index a050ee60e6c..7a041fae754 100644 --- a/lib/librthread/rthread_sync.c +++ b/lib/librthread/rthread_sync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_sync.c,v 1.34 2012/04/13 12:39:28 kurt Exp $ */ +/* $OpenBSD: rthread_sync.c,v 1.35 2012/04/13 13:50:37 kurt Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * Copyright (c) 2012 Philip Guenther <guenther@openbsd.org> @@ -47,7 +47,7 @@ pthread_mutex_init(pthread_mutex_t *mutexp, const pthread_mutexattr_t *attr) mutex->lock = _SPINLOCK_UNLOCKED; TAILQ_INIT(&mutex->lockers); if (attr == NULL) { - mutex->type = PTHREAD_MUTEX_ERRORCHECK; + mutex->type = PTHREAD_MUTEX_DEFAULT; mutex->prioceiling = -1; } else { mutex->type = (*attr)->ma_type; @@ -187,9 +187,13 @@ pthread_mutex_unlock(pthread_mutex_t *mutexp) _rthread_debug(5, "%p: mutex_unlock %p\n", (void *)self, (void *)mutex); -#if PTHREAD_MUTEX_DEFAULT == PTHREAD_MUTEX_ERRORCHECK if (mutex == NULL) +#if PTHREAD_MUTEX_DEFAULT == PTHREAD_MUTEX_ERRORCHECK return (EPERM); +#elif PTHREAD_MUTEX_DEFAULT == PTHREAD_MUTEX_NORMAL + return(0); +#else + abort(); #endif if (mutex->owner != self) { @@ -288,9 +292,11 @@ pthread_cond_timedwait(pthread_cond_t *condp, pthread_mutex_t *mutexp, _rthread_debug(5, "%p: cond_timed %p,%p\n", (void *)self, (void *)cond, (void *)mutex); -#if PTHREAD_MUTEX_DEFAULT == PTHREAD_MUTEX_ERRORCHECK if (mutex == NULL) +#if PTHREAD_MUTEX_DEFAULT == PTHREAD_MUTEX_ERRORCHECK return (EPERM); +#else + abort(); #endif if (mutex->owner != self) { @@ -437,9 +443,11 @@ pthread_cond_wait(pthread_cond_t *condp, pthread_mutex_t *mutexp) _rthread_debug(5, "%p: cond_timed %p,%p\n", (void *)self, (void *)cond, (void *)mutex); -#if PTHREAD_MUTEX_DEFAULT == PTHREAD_MUTEX_ERRORCHECK if (mutex == NULL) +#if PTHREAD_MUTEX_DEFAULT == PTHREAD_MUTEX_ERRORCHECK return (EPERM); +#else + abort(); #endif if (mutex->owner != self) { |