summaryrefslogtreecommitdiff
path: root/lib/libpthread
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libpthread')
-rw-r--r--lib/libpthread/pthread_mutex.c15
-rw-r--r--lib/libpthread/pthread_types.h46
2 files changed, 47 insertions, 14 deletions
diff --git a/lib/libpthread/pthread_mutex.c b/lib/libpthread/pthread_mutex.c
index c6617c4b05d..cf05088d22d 100644
--- a/lib/libpthread/pthread_mutex.c
+++ b/lib/libpthread/pthread_mutex.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_mutex.c,v 1.50 2008/05/25 17:05:28 ad Exp $ */
+/* $NetBSD: pthread_mutex.c,v 1.51 2008/08/02 19:46:30 matt Exp $ */
/*-
* Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -47,10 +47,11 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_mutex.c,v 1.50 2008/05/25 17:05:28 ad Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.51 2008/08/02 19:46:30 matt Exp $");
#include <sys/types.h>
#include <sys/lwpctl.h>
+#include <sys/lock.h>
#include <errno.h>
#include <limits.h>
@@ -111,15 +112,15 @@ pthread_mutex_init(pthread_mutex_t *ptm, const pthread_mutexattr_t *attr)
switch (type) {
case PTHREAD_MUTEX_ERRORCHECK:
- ptm->ptm_errorcheck = 1;
+ __cpu_simple_lock_set(&ptm->ptm_errorcheck);
ptm->ptm_owner = NULL;
break;
case PTHREAD_MUTEX_RECURSIVE:
- ptm->ptm_errorcheck = 0;
+ __cpu_simple_lock_clear(&ptm->ptm_errorcheck);
ptm->ptm_owner = (void *)MUTEX_RECURSIVE_BIT;
break;
default:
- ptm->ptm_errorcheck = 0;
+ __cpu_simple_lock_clear(&ptm->ptm_errorcheck);
ptm->ptm_owner = NULL;
break;
}
@@ -219,7 +220,7 @@ pthread__mutex_lock_slow(pthread_mutex_t *ptm)
ptm->ptm_recursed++;
return 0;
}
- if (ptm->ptm_errorcheck)
+ if (__SIMPLELOCK_LOCKED_P(&ptm->ptm_errorcheck))
return EDEADLK;
}
@@ -400,7 +401,7 @@ pthread__mutex_unlock_slow(pthread_mutex_t *ptm)
deferred = (int)((uintptr_t)owner & MUTEX_DEFERRED_BIT);
error = 0;
- if (ptm->ptm_errorcheck) {
+ if (__SIMPLELOCK_LOCKED_P(&ptm->ptm_errorcheck)) {
if (!weown) {
error = EPERM;
new = owner;
diff --git a/lib/libpthread/pthread_types.h b/lib/libpthread/pthread_types.h
index 919a15bd56a..cf49d0270a4 100644
--- a/lib/libpthread/pthread_types.h
+++ b/lib/libpthread/pthread_types.h
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_types.h,v 1.12 2008/06/05 23:38:51 ad Exp $ */
+/* $NetBSD: pthread_types.h,v 1.13 2008/08/02 19:46:30 matt Exp $ */
/*-
* Copyright (c) 2001, 2008 The NetBSD Foundation, Inc.
@@ -84,21 +84,53 @@ struct __pthread_attr_st {
};
/*
- * ptm_lock will never be spun on: it's locked with
- * pthread__simple_lock_try() or not at all.
+ * ptm_owner is the actual lock field which is locked via CAS operation.
+ * This structure's layout is designed to compatible with the previous
+ * version used in SA pthreads.
*/
+#ifdef __CPU_SIMPLE_LOCK_PAD
+/*
+ * If __SIMPLE_UNLOCKED != 0 and we have to pad, we have to worry about
+ * endianness. Currently that isn't an issue but put in a check in case
+ * something changes in the future.
+ */
+#if __SIMPLELOCK_UNLOCKED != 0
+#error __CPU_SIMPLE_LOCK_PAD incompatible with __SIMPLELOCK_UNLOCKED == 0
+#endif
+#endif
struct __pthread_mutex_st {
unsigned int ptm_magic;
- unsigned int ptm_errorcheck;
- unsigned int ptm_recursed;
- pthread_t * volatile ptm_waiters;
+ pthread_spin_t ptm_errorcheck;
+#ifdef __CPU_SIMPLE_LOCK_PAD
+ uint8_t ptm_pad1[3];
+#endif
+ pthread_spin_t ptm_interlock; /* unused - backwards compat */
+#ifdef __CPU_SIMPLE_LOCK_PAD
+ uint8_t ptm_pad2[3];
+#endif
volatile pthread_t ptm_owner;
+ pthread_t * volatile ptm_waiters;
+ unsigned int ptm_recursed;
+ void *ptm_spare2; /* unused - backwards compat */
};
#define _PT_MUTEX_MAGIC 0x33330003
#define _PT_MUTEX_DEAD 0xDEAD0003
-#define _PTHREAD_MUTEX_INITIALIZER { _PT_MUTEX_MAGIC, 0, 0, NULL, NULL }
+#ifdef __CPU_SIMPLE_LOCK_PAD
+#define _PTHREAD_MUTEX_INITIALIZER { _PT_MUTEX_MAGIC, \
+ __SIMPLELOCK_UNLOCKED, { 0, 0, 0 }, \
+ __SIMPLELOCK_UNLOCKED, { 0, 0, 0 }, \
+ NULL, NULL, 0, NULL \
+ }
+#else
+#define _PTHREAD_MUTEX_INITIALIZER { _PT_MUTEX_MAGIC, \
+ __SIMPLELOCK_UNLOCKED, \
+ __SIMPLELOCK_UNLOCKED, \
+ NULL, NULL, 0, NULL \
+ }
+#endif /* __CPU_SIMPLE_LOCK_PAD */
+
struct __pthread_mutexattr_st {
unsigned int ptma_magic;