summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKurt Miller <kurt@cvs.openbsd.org>2012-04-13 13:50:38 +0000
committerKurt Miller <kurt@cvs.openbsd.org>2012-04-13 13:50:38 +0000
commite0f09140df4d1589ba0508b4df463185b68f2d1d (patch)
treebc30fdb57475affc289b31ee2310a992f163dcf0 /lib
parent28e13e25d7be4da391c39ddc355060d5c010dcf0 (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')
-rw-r--r--lib/librthread/rthread_mutexattr.c4
-rw-r--r--lib/librthread/rthread_sync.c18
2 files changed, 15 insertions, 7 deletions
diff --git a/lib/librthread/rthread_mutexattr.c b/lib/librthread/rthread_mutexattr.c
index d737ea1adf0..7565b4f77a6 100644
--- a/lib/librthread/rthread_mutexattr.c
+++ b/lib/librthread/rthread_mutexattr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread_mutexattr.c,v 1.2 2012/02/15 04:58:42 guenther Exp $ */
+/* $OpenBSD: rthread_mutexattr.c,v 1.3 2012/04/13 13:50:37 kurt Exp $ */
/*
* Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
* Copyright (c) 2011 Philip Guenther <guenther@openbsd.org>
@@ -38,7 +38,7 @@ pthread_mutexattr_init(pthread_mutexattr_t *attrp)
attr = calloc(1, sizeof(*attr));
if (!attr)
return (errno);
- attr->ma_type = PTHREAD_MUTEX_ERRORCHECK;
+ attr->ma_type = PTHREAD_MUTEX_DEFAULT;
*attrp = attr;
return (0);
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) {