summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/librthread/arch/hppa/_atomic_lock.c13
-rw-r--r--lib/librthread/rthread.h13
-rw-r--r--sys/arch/hppa/include/spinlock.h4
3 files changed, 21 insertions, 9 deletions
diff --git a/lib/librthread/arch/hppa/_atomic_lock.c b/lib/librthread/arch/hppa/_atomic_lock.c
index 2b501711715..2b21ee26d9f 100644
--- a/lib/librthread/arch/hppa/_atomic_lock.c
+++ b/lib/librthread/arch/hppa/_atomic_lock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: _atomic_lock.c,v 1.3 2005/12/17 05:28:59 marco Exp $ */
+/* $OpenBSD: _atomic_lock.c,v 1.4 2005/12/19 21:30:10 marco Exp $ */
/*
* Copyright (c) 2005 Marco Peereboom <marco@openbsd.org>
*
@@ -18,13 +18,20 @@
#include <machine/spinlock.h>
int
-_atomic_lock(register volatile _spinlock_lock_t *lock)
+_atomic_lock(volatile _spinlock_lock_t *lock)
{
_spinlock_lock_t old;
+#ifdef DIAGNOSTIC
+ if ((unsigned long)lock & 0xf) {
+ printf("lock not 16 byte aligned\n");
+ abort();
+ }
+#endif
+
asm volatile ("ldcw %1,%0"
: "=r" (old), "=m" (*lock)
: "m" (*lock));
- return (old == _SPINLOCK_UNLOCKED);
+ return (old == _SPINLOCK_LOCKED);
}
diff --git a/lib/librthread/rthread.h b/lib/librthread/rthread.h
index 96596cce16a..6da13075dfd 100644
--- a/lib/librthread/rthread.h
+++ b/lib/librthread/rthread.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread.h,v 1.8 2005/12/19 06:47:40 tedu Exp $ */
+/* $OpenBSD: rthread.h,v 1.9 2005/12/19 21:30:10 marco Exp $ */
/*
* Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
@@ -19,6 +19,10 @@
* Private data structures that back up the typedefs in pthread.h.
* Since only the thread library cares about their size or arrangement,
* it should be possible to switch libraries without relinking.
+ *
+ * Do not reorder _spinlock_lock_t and sem_t variables in the structs.
+ * This is due to alignment requirements of certain arches like hppa.
+ * The current requirement is 16 bytes.
*/
struct stack {
@@ -28,9 +32,10 @@ struct stack {
};
typedef struct semaphore {
+ _spinlock_lock_t lock;
volatile int waitcount;
volatile int value;
- _spinlock_lock_t lock;
+ int pad;
} *sem_t;
struct pthread_mutex {
@@ -53,10 +58,10 @@ struct pthread_cond_attr {
};
struct pthread_rwlock {
+ struct semaphore sem;
_spinlock_lock_t lock;
int readers;
int writer;
- struct semaphore sem;
};
struct pthread_rwlockattr {
@@ -91,8 +96,8 @@ struct rthread_cleanup_fn {
};
struct pthread {
- pid_t tid;
struct semaphore donesem;
+ pid_t tid;
unsigned int flags;
void *retval;
void *(*fn)(void *);
diff --git a/sys/arch/hppa/include/spinlock.h b/sys/arch/hppa/include/spinlock.h
index a429cc3910b..221f35a8621 100644
--- a/sys/arch/hppa/include/spinlock.h
+++ b/sys/arch/hppa/include/spinlock.h
@@ -1,10 +1,10 @@
-/* $OpenBSD: spinlock.h,v 1.1 1999/01/08 08:25:34 d Exp $ */
+/* $OpenBSD: spinlock.h,v 1.2 2005/12/19 21:30:10 marco Exp $ */
#ifndef _MACHINE_SPINLOCK_H_
#define _MACHINE_SPINLOCK_H_
#define _SPINLOCK_UNLOCKED (1)
#define _SPINLOCK_LOCKED (0)
-typedef int _spinlock_lock_t;
+typedef int _spinlock_lock_t __attribute__((__aligned__(16)));
#endif