diff options
author | Kurt Miller <kurt@cvs.openbsd.org> | 2012-04-14 12:07:50 +0000 |
---|---|---|
committer | Kurt Miller <kurt@cvs.openbsd.org> | 2012-04-14 12:07:50 +0000 |
commit | 43d6abbdbca95ffcdcf76bd4e43405d0795776ee (patch) | |
tree | 24b1ca8ae89eebd16749bee889f7231e84a9c0e0 | |
parent | 1035f26f14674e2605b7150a8f23e4d132e082d5 (diff) |
Add new mutex type, PTHREAD_MUTEX_STRICT_NP which checks for application
errors similar to PTHREAD_MUTEX_ERRORCHECK, however upon error it aborts.
The rational is that many applications don't check the return values on
pthread functions and will miss the errors that ERRORCHECK returns.
PTHREAD_MUTEX_STRICT_NP will be our default mutex type for awhile
okay guenther@ dcoppa@
-rw-r--r-- | lib/libpthread/include/pthread.h | 7 | ||||
-rw-r--r-- | lib/librthread/rthread_sync.c | 11 |
2 files changed, 12 insertions, 6 deletions
diff --git a/lib/libpthread/include/pthread.h b/lib/libpthread/include/pthread.h index 7a149d10373..c21f753de12 100644 --- a/lib/libpthread/include/pthread.h +++ b/lib/libpthread/include/pthread.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pthread.h,v 1.34 2012/04/12 12:09:30 kurt Exp $ */ +/* $OpenBSD: pthread.h,v 1.35 2012/04/14 12:07:49 kurt Exp $ */ /* * Copyright (c) 1993, 1994 by Chris Provenzano, proven@mit.edu @@ -187,13 +187,14 @@ struct pthread_once { * will deviate from POSIX specified semantics. */ enum pthread_mutextype { - PTHREAD_MUTEX_ERRORCHECK = 1, /* Default POSIX mutex */ + PTHREAD_MUTEX_ERRORCHECK = 1, /* Error checking mutex */ PTHREAD_MUTEX_RECURSIVE = 2, /* Recursive mutex */ PTHREAD_MUTEX_NORMAL = 3, /* No error checking */ + PTHREAD_MUTEX_STRICT_NP = 4, /* Strict error checking */ PTHREAD_MUTEX_TYPE_MAX }; -#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_ERRORCHECK +#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_STRICT_NP /* * Thread function prototype definitions: diff --git a/lib/librthread/rthread_sync.c b/lib/librthread/rthread_sync.c index 7a041fae754..077ecbc7d56 100644 --- a/lib/librthread/rthread_sync.c +++ b/lib/librthread/rthread_sync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_sync.c,v 1.35 2012/04/13 13:50:37 kurt Exp $ */ +/* $OpenBSD: rthread_sync.c,v 1.36 2012/04/14 12:07:49 kurt Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * Copyright (c) 2012 Philip Guenther <guenther@openbsd.org> @@ -121,8 +121,12 @@ _rthread_mutex_lock(pthread_mutex_t *mutexp, int trywait, return (trywait ? EBUSY : EDEADLK); } + /* self-deadlock is disallowed by strict */ + if (mutex->type == PTHREAD_MUTEX_STRICT_NP && + abstime == NULL) + abort(); + /* self-deadlock, possibly until timeout */ - assert(mutex->type == PTHREAD_MUTEX_NORMAL); while (__thrsleep(self, CLOCK_REALTIME, abstime, &mutex->lock, NULL) != EWOULDBLOCK) _spinlock(&mutex->lock); @@ -207,7 +211,8 @@ pthread_mutex_unlock(pthread_mutex_t *mutexp) * error. All other undefined behaviors are to * abort() immediately. */ - if (mutex->owner == NULL) + if (mutex->owner == NULL && + mutex->type == PTHREAD_MUTEX_NORMAL) return (0); else abort(); |