summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2011-01-12 21:11:13 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2011-01-12 21:11:13 +0000
commit8d8f88eeb53bec32d90502aeaef89e8b487972e7 (patch)
tree2b34b72870c104ce25c2f0c92f31f8d8eca87b6a /sys
parent20be7b702fa19dd2a91c249516182353ed26b97e (diff)
Provide a specific rw_cas() function for MP kernels; stolen from m88k.
ok jsing@, deraadt@
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/hppa/hppa/lock_machdep.c30
-rw-r--r--sys/arch/hppa/include/lock.h7
2 files changed, 35 insertions, 2 deletions
diff --git a/sys/arch/hppa/hppa/lock_machdep.c b/sys/arch/hppa/hppa/lock_machdep.c
index 00377d39667..5feebe9616e 100644
--- a/sys/arch/hppa/hppa/lock_machdep.c
+++ b/sys/arch/hppa/hppa/lock_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lock_machdep.c,v 1.2 2010/05/17 11:25:08 jsing Exp $ */
+/* $OpenBSD: lock_machdep.c,v 1.3 2011/01/12 21:11:12 kettenis Exp $ */
/*
* Copyright (c) 2007 Artur Grabowski <art@openbsd.org>
@@ -204,3 +204,31 @@ __mp_lock_held(struct __mp_lock *mpl)
{
return mpl->mpl_cpu == curcpu();
}
+
+/*
+ * Emulate a compare-and-swap instruction for rwlocks, by using a
+ * __cpu_simple_lock as a critical section.
+ *
+ * Since we are only competing against other processors for rwlocks,
+ * it is not necessary in this case to disable interrupts to prevent
+ * reentrancy on the same processor.
+ */
+
+__cpu_simple_lock_t rw_cas_spinlock = __SIMPLELOCK_UNLOCKED;
+
+int
+rw_cas_hppa(volatile unsigned long *p, unsigned long o, unsigned long n)
+{
+ int rc = 0;
+
+ __cpu_simple_lock(&rw_cas_spinlock);
+
+ if (*p != o)
+ rc = 1;
+ else
+ *p = n;
+
+ __cpu_simple_unlock(&rw_cas_spinlock);
+
+ return (rc);
+}
diff --git a/sys/arch/hppa/include/lock.h b/sys/arch/hppa/include/lock.h
index 48430c7163f..5d21e8cb8ea 100644
--- a/sys/arch/hppa/include/lock.h
+++ b/sys/arch/hppa/include/lock.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: lock.h,v 1.3 2011/01/12 21:07:12 kettenis Exp $ */
+/* $OpenBSD: lock.h,v 1.4 2011/01/12 21:11:12 kettenis Exp $ */
/* public domain */
@@ -47,4 +47,9 @@ __cpu_simple_unlock(__cpu_simple_lock_t *l)
*l = __SIMPLELOCK_UNLOCKED;
}
+#if defined(_KERNEL) && defined(MULTIPROCESSOR)
+int rw_cas_hppa(volatile unsigned long *, unsigned long, unsigned long);
+#define rw_cas rw_cas_hppa
+#endif
+
#endif /* _HPPA_LOCK_H_ */