diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2015-02-11 00:14:12 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2015-02-11 00:14:12 +0000 |
commit | c4427bcd781765e2f91f6109bbd3267e7d9c4232 (patch) | |
tree | 3d165a2943dc27e75242e5c202c9cb43389d9218 /sys/kern | |
parent | 327e76719bad93f8260eacba21e3bf58cfe1f944 (diff) |
make the rwlock implementation MI.
each arch used to have to provide an rw_cas operation, but now we
have the rwlock code build its own version. on smp machines it uses
atomic_cas_ulong. on uniproc machines it avoids interlocked
instructions by using straight loads and stores. this is safe because
rwlocks are only used from process context and processes are currently
not preemptible in our kernel. so alpha/ppc/etc might get a benefit.
ok miod@ kettenis@ deraadt@
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_rwlock.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c index f50cf65a033..3ad22be632a 100644 --- a/sys/kern/kern_rwlock.c +++ b/sys/kern/kern_rwlock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_rwlock.c,v 1.24 2015/02/10 10:04:27 dlg Exp $ */ +/* $OpenBSD: kern_rwlock.c,v 1.25 2015/02/11 00:14:11 dlg Exp $ */ /* * Copyright (c) 2002, 2003 Artur Grabowski <art@openbsd.org> @@ -24,11 +24,23 @@ #include <sys/limits.h> #include <sys/atomic.h> -#include <machine/lock.h> - /* XXX - temporary measure until proc0 is properly aligned */ #define RW_PROC(p) (((long)p) & ~RWLOCK_MASK) +#ifdef MULTIPROCESSOR +#define rw_cas(p, o, n) (atomic_cas_ulong(p, o, n) != o) +#else +static inline int +rw_cas(volatile unsigned long *p, unsigned long o, unsigned long n) +{ + if (*p != o) + return (1); + *p = n; + + return (0); +} +#endif + /* * Magic wand for lock operations. Every operation checks if certain * flags are set and if they aren't, it increments the lock with some @@ -124,18 +136,6 @@ rw_exit_write(struct rwlock *rwl) rw_exit(rwl); } -#ifndef rw_cas -int -rw_cas(volatile unsigned long *p, unsigned long o, unsigned long n) -{ - if (*p != o) - return (1); - *p = n; - - return (0); -} -#endif - #ifdef DIAGNOSTIC /* * Put the diagnostic functions here to keep the main code free |