diff options
| author | ad <ad@NetBSD.org> | 2008-02-14 21:40:51 +0000 |
|---|---|---|
| committer | ad <ad@NetBSD.org> | 2008-02-14 21:40:51 +0000 |
| commit | 377f098ab0450bbd86a6f5f8b98ccb552eed0945 (patch) | |
| tree | 89833bd2defbc19ecf283c202a26d4d39674c14a /lib/libpthread | |
| parent | 86a2448d10f1984c0a34c2a1a7777c8875cc1cd1 (diff) | |
Adjust mutex/rwlock definitions to match reality now that there is only
one implementation of each. PR lib/38030.
Diffstat (limited to 'lib/libpthread')
| -rw-r--r-- | lib/libpthread/pthread_cond.c | 8 | ||||
| -rw-r--r-- | lib/libpthread/pthread_int.h | 4 | ||||
| -rw-r--r-- | lib/libpthread/pthread_mutex.c | 45 | ||||
| -rw-r--r-- | lib/libpthread/pthread_types.h | 22 |
4 files changed, 31 insertions, 48 deletions
diff --git a/lib/libpthread/pthread_cond.c b/lib/libpthread/pthread_cond.c index 32167111ab7..25081c5f6ef 100644 --- a/lib/libpthread/pthread_cond.c +++ b/lib/libpthread/pthread_cond.c @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_cond.c,v 1.40 2007/12/24 16:04:21 ad Exp $ */ +/* $NetBSD: pthread_cond.c,v 1.41 2008/02/14 21:40:51 ad Exp $ */ /*- * Copyright (c) 2001, 2006, 2007 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: pthread_cond.c,v 1.40 2007/12/24 16:04:21 ad Exp $"); +__RCSID("$NetBSD: pthread_cond.c,v 1.41 2008/02/14 21:40:51 ad Exp $"); #include <errno.h> #include <sys/time.h> @@ -145,7 +145,7 @@ pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) self->pt_willpark = 1; pthread_mutex_unlock(mutex); (void)pthread__park(self, &cond->ptc_lock, &cond->ptc_waiters, - NULL, 1, &mutex->ptm_blocked); + NULL, 1, __UNVOLATILE(&mutex->ptm_waiters)); pthread_mutex_lock(mutex); /* @@ -235,7 +235,7 @@ pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, self->pt_willpark = 1; pthread_mutex_unlock(mutex); retval = pthread__park(self, &cond->ptc_lock, &cond->ptc_waiters, - abstime, 1, &mutex->ptm_blocked); + abstime, 1, __UNVOLATILE(&mutex->ptm_waiters)); pthread_mutex_lock(mutex); /* diff --git a/lib/libpthread/pthread_int.h b/lib/libpthread/pthread_int.h index 82c5d21d006..8211d1a410c 100644 --- a/lib/libpthread/pthread_int.h +++ b/lib/libpthread/pthread_int.h @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_int.h,v 1.66 2008/02/10 18:50:54 ad Exp $ */ +/* $NetBSD: pthread_int.h,v 1.67 2008/02/14 21:40:51 ad Exp $ */ /*- * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -318,6 +318,4 @@ int pthread__mutex_deferwake(pthread_t, pthread_mutex_t *) PTHREAD_HIDE; #define RW_COUNT(rw) ((rw)->rw_owner & RW_THREAD) #define RW_FLAGS(rw) ((rw)->rw_owner & ~RW_THREAD) -#define ptr_owner ptr_writer - #endif /* _LIB_PTHREAD_INT_H */ diff --git a/lib/libpthread/pthread_mutex.c b/lib/libpthread/pthread_mutex.c index 54cf1dc434f..c58bc548470 100644 --- a/lib/libpthread/pthread_mutex.c +++ b/lib/libpthread/pthread_mutex.c @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_mutex.c,v 1.44 2008/02/10 18:50:54 ad Exp $ */ +/* $NetBSD: pthread_mutex.c,v 1.45 2008/02/14 21:40:51 ad Exp $ */ /*- * Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: pthread_mutex.c,v 1.44 2008/02/10 18:50:54 ad Exp $"); +__RCSID("$NetBSD: pthread_mutex.c,v 1.45 2008/02/14 21:40:51 ad Exp $"); #include <sys/types.h> #include <sys/lwpctl.h> @@ -51,14 +51,7 @@ __RCSID("$NetBSD: pthread_mutex.c,v 1.44 2008/02/10 18:50:54 ad Exp $"); #include "pthread.h" #include "pthread_int.h" -/* - * Note that it's important to use the address of ptm_waiters as - * the list head in order for the hint arguments to _lwp_park / - * _lwp_unpark_all to match. - */ #define pt_nextwaiter pt_sleep.ptqe_next -#define ptm_waiters ptm_blocked.ptqh_first -#define ptm_errorcheck ptm_lock #define MUTEX_WAITERS_BIT ((uintptr_t)0x01) #define MUTEX_RECURSIVE_BIT ((uintptr_t)0x02) @@ -68,9 +61,6 @@ __RCSID("$NetBSD: pthread_mutex.c,v 1.44 2008/02/10 18:50:54 ad Exp $"); #define MUTEX_HAS_WAITERS(x) ((uintptr_t)(x) & MUTEX_WAITERS_BIT) #define MUTEX_RECURSIVE(x) ((uintptr_t)(x) & MUTEX_RECURSIVE_BIT) #define MUTEX_OWNER(x) ((uintptr_t)(x) & MUTEX_THREAD) -#define MUTEX_GET_RECURSE(ptm) ((intptr_t)(ptm)->ptm_private) -#define MUTEX_SET_RECURSE(ptm, delta) \ - ((ptm)->ptm_private = (void *)((intptr_t)(ptm)->ptm_private + delta)) #if __GNUC_PREREQ__(3, 0) #define NOINLINE __attribute ((noinline)) @@ -128,7 +118,7 @@ pthread_mutex_init(pthread_mutex_t *ptm, const pthread_mutexattr_t *attr) ptm->ptm_magic = _PT_MUTEX_MAGIC; ptm->ptm_waiters = NULL; - ptm->ptm_private = NULL; + ptm->ptm_recursed = 0; return 0; } @@ -216,9 +206,9 @@ pthread__mutex_lock_slow(pthread_mutex_t *ptm) /* Recursive or errorcheck? */ if (MUTEX_OWNER(owner) == (uintptr_t)self) { if (MUTEX_RECURSIVE(owner)) { - if (MUTEX_GET_RECURSE(ptm) == INT_MAX) + if (ptm->ptm_recursed == INT_MAX) return EAGAIN; - MUTEX_SET_RECURSE(ptm, +1); + ptm->ptm_recursed++; return 0; } if (ptm->ptm_errorcheck) @@ -320,7 +310,8 @@ pthread__mutex_lock_slow(pthread_mutex_t *ptm) */ while (self->pt_sleeponq) { self->pt_blocking++; - (void)_lwp_park(NULL, 0, &ptm->ptm_waiters, NULL); + (void)_lwp_park(NULL, 0, + __UNVOLATILE(&ptm->ptm_waiters), NULL); self->pt_blocking--; membar_sync(); } @@ -343,9 +334,9 @@ pthread_mutex_trylock(pthread_mutex_t *ptm) } if (MUTEX_OWNER(val) == (uintptr_t)self && MUTEX_RECURSIVE(val)) { - if (MUTEX_GET_RECURSE(ptm) == INT_MAX) + if (ptm->ptm_recursed == INT_MAX) return EAGAIN; - MUTEX_SET_RECURSE(ptm, +1); + ptm->ptm_recursed++; return 0; } @@ -398,8 +389,8 @@ pthread__mutex_unlock_slow(pthread_mutex_t *ptm) if (!weown) { error = EPERM; new = owner; - } else if (MUTEX_GET_RECURSE(ptm) != 0) { - MUTEX_SET_RECURSE(ptm, -1); + } else if (ptm->ptm_recursed) { + ptm->ptm_recursed--; new = owner; } else { new = (pthread_t)MUTEX_RECURSIVE_BIT; @@ -438,14 +429,15 @@ pthread__mutex_unlock_slow(pthread_mutex_t *ptm) */ if (self->pt_willpark && self->pt_unpark == 0) { self->pt_unpark = self->pt_waiters[0]; - self->pt_unparkhint = &ptm->ptm_waiters; + self->pt_unparkhint = + __UNVOLATILE(&ptm->ptm_waiters); } else { (void)_lwp_unpark(self->pt_waiters[0], - &ptm->ptm_waiters); + __UNVOLATILE(&ptm->ptm_waiters)); } } else { (void)_lwp_unpark_all(self->pt_waiters, self->pt_nwaiters, - &ptm->ptm_waiters); + __UNVOLATILE(&ptm->ptm_waiters)); } self->pt_nwaiters = 0; @@ -495,11 +487,12 @@ pthread__mutex_wakeup(pthread_t self, pthread_mutex_t *ptm) */ if (self->pt_willpark && self->pt_unpark == 0) { self->pt_unpark = self->pt_waiters[0]; - self->pt_unparkhint = &ptm->ptm_waiters; + self->pt_unparkhint = + __UNVOLATILE(&ptm->ptm_waiters); return; } rv = (ssize_t)_lwp_unpark(self->pt_waiters[0], - &ptm->ptm_waiters); + __UNVOLATILE(&ptm->ptm_waiters)); if (rv != 0 && errno != EALREADY && errno != EINTR && errno != ESRCH) { pthread__errorfunc(__FILE__, __LINE__, @@ -508,7 +501,7 @@ pthread__mutex_wakeup(pthread_t self, pthread_mutex_t *ptm) return; default: rv = _lwp_unpark_all(self->pt_waiters, (size_t)n, - &ptm->ptm_waiters); + __UNVOLATILE(&ptm->ptm_waiters)); if (rv != 0 && errno != EINTR) { pthread__errorfunc(__FILE__, __LINE__, __func__, "_lwp_unpark_all failed"); diff --git a/lib/libpthread/pthread_types.h b/lib/libpthread/pthread_types.h index 6fefe4487b9..851b06e7253 100644 --- a/lib/libpthread/pthread_types.h +++ b/lib/libpthread/pthread_types.h @@ -1,7 +1,7 @@ -/* $NetBSD: pthread_types.h,v 1.8 2007/09/07 14:09:28 ad Exp $ */ +/* $NetBSD: pthread_types.h,v 1.9 2008/02/14 21:40:51 ad Exp $ */ /*- - * Copyright (c) 2001 The NetBSD Foundation, Inc. + * Copyright (c) 2001, 2008 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -96,24 +96,16 @@ struct __pthread_attr_st { */ struct __pthread_mutex_st { unsigned int ptm_magic; - pthread_spin_t ptm_lock; - pthread_spin_t ptm_interlock; + unsigned int ptm_errorcheck; + unsigned int ptm_recursed; + pthread_t * volatile ptm_waiters; volatile pthread_t ptm_owner; - pthread_queue_t ptm_blocked; - void *ptm_private; }; #define _PT_MUTEX_MAGIC 0x33330003 #define _PT_MUTEX_DEAD 0xDEAD0003 -#define _PTHREAD_MUTEX_INITIALIZER { _PT_MUTEX_MAGIC, \ - __SIMPLELOCK_UNLOCKED, \ - __SIMPLELOCK_UNLOCKED, \ - NULL, \ - {NULL, NULL}, \ - NULL \ - } - +#define _PTHREAD_MUTEX_INITIALIZER { _PT_MUTEX_MAGIC, 0, 0, NULL, NULL } struct __pthread_mutexattr_st { unsigned int ptma_magic; @@ -185,7 +177,7 @@ struct __pthread_rwlock_st { pthread_queue_t ptr_rblocked; pthread_queue_t ptr_wblocked; unsigned int ptr_nreaders; - volatile pthread_t ptr_writer; + volatile pthread_t ptr_owner; void *ptr_private; }; |
