From 8d8f88eeb53bec32d90502aeaef89e8b487972e7 Mon Sep 17 00:00:00 2001 From: Mark Kettenis Date: Wed, 12 Jan 2011 21:11:13 +0000 Subject: Provide a specific rw_cas() function for MP kernels; stolen from m88k. ok jsing@, deraadt@ --- sys/arch/hppa/hppa/lock_machdep.c | 30 +++++++++++++++++++++++++++++- sys/arch/hppa/include/lock.h | 7 ++++++- 2 files changed, 35 insertions(+), 2 deletions(-) (limited to 'sys') 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 @@ -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_ */ -- cgit v1.2.3