diff options
| author | ad <ad@NetBSD.org> | 2007-09-09 20:13:23 +0000 |
|---|---|---|
| committer | ad <ad@NetBSD.org> | 2007-09-09 20:13:23 +0000 |
| commit | e2c2fa5d099085138549ac45ff095939c2be925b (patch) | |
| tree | 4042999f5c290368bef6ad881b4606ff98b7ddd9 /lib/libpthread | |
| parent | b1749a12b7d7a768f2cd0a0529b94e150a78e55d (diff) | |
Fix recursive mutexes to work again in non-threaded applications.
Diffstat (limited to 'lib/libpthread')
| -rw-r--r-- | lib/libpthread/pthread_mutex2.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/lib/libpthread/pthread_mutex2.c b/lib/libpthread/pthread_mutex2.c index 649085ddb61..3b267c815f2 100644 --- a/lib/libpthread/pthread_mutex2.c +++ b/lib/libpthread/pthread_mutex2.c @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_mutex2.c,v 1.2 2007/09/08 22:49:50 ad Exp $ */ +/* $NetBSD: pthread_mutex2.c,v 1.3 2007/09/09 20:13:23 ad Exp $ */ /*- * Copyright (c) 2001, 2003, 2006, 2007 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: pthread_mutex2.c,v 1.2 2007/09/08 22:49:50 ad Exp $"); +__RCSID("$NetBSD: pthread_mutex2.c,v 1.3 2007/09/09 20:13:23 ad Exp $"); #include <errno.h> #include <limits.h> @@ -194,17 +194,6 @@ pthread__mutex_lock_slow(pthread_mutex_t *ptm, void *owner) pthread__error(EINVAL, "Invalid mutex", ptm->ptm_magic == _PT_MUTEX_MAGIC); - if (pthread__started == 0) { - /* The spec says we must deadlock, so... */ - mp = ptm->ptm_private; - pthread__assert(mp->type == PTHREAD_MUTEX_NORMAL); - (void) sigprocmask(SIG_SETMASK, NULL, &ss); - for (;;) { - sigsuspend(&ss); - } - /*NOTREACHED*/ - } - /* Recursive or errorcheck? */ mp = ptm->ptm_private; self = pthread__self(); @@ -234,10 +223,22 @@ pthread__mutex_lock_slow(pthread_mutex_t *ptm, void *owner) return 0; } + /* Nope, still held. */ + if (pthread__started == 0) { + /* The spec says we must deadlock, so... */ + mp = ptm->ptm_private; + pthread__assert(mp->type == PTHREAD_MUTEX_NORMAL); + (void) sigprocmask(SIG_SETMASK, NULL, &ss); + for (;;) { + sigsuspend(&ss); + } + /*NOTREACHED*/ + } + /* - * Nope: still held. Add us to the list of waiters. - * Issue memory barrier to ensure sleeponq/nextwaiter - * are visible before we enter the waiters list. + * Add thread to the list of waiters. Issue a memory + * barrier to ensure sleeponq/nextwaiter are visible + * before we enter the waiters list. */ self->pt_sleeponq = 1; for (waiters = ptm->ptm_waiters;;) { |
