diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2014-12-04 01:50:40 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2014-12-04 01:50:40 +0000 |
commit | 7bb3334875fd974cb0873330c7725cb8ed21021a (patch) | |
tree | 4b1926264a9ec1273d58bea59412b339db48cb89 /sys | |
parent | e417e703d6f790767960b2ad999684fd42686c21 (diff) |
split the word ops into int and longs so things that care a lot
about types are happy.
ok jsg@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/sparc/include/atomic.h | 87 |
1 files changed, 74 insertions, 13 deletions
diff --git a/sys/arch/sparc/include/atomic.h b/sys/arch/sparc/include/atomic.h index b567c09d381..071e3541216 100644 --- a/sys/arch/sparc/include/atomic.h +++ b/sys/arch/sparc/include/atomic.h @@ -1,4 +1,4 @@ -/* $OpenBSD: atomic.h,v 1.7 2014/09/30 05:07:51 dlg Exp $ */ +/* $OpenBSD: atomic.h,v 1.8 2014/12/04 01:50:39 dlg Exp $ */ /* Public Domain */ @@ -10,7 +10,7 @@ #include <machine/psl.h> static inline unsigned int -_atomic_cas_word(volatile unsigned int *uip, unsigned int o, unsigned int n) +_atomic_cas_uint(volatile unsigned int *uip, unsigned int o, unsigned int n) { int psr; unsigned int rv; @@ -24,8 +24,24 @@ _atomic_cas_word(volatile unsigned int *uip, unsigned int o, unsigned int n) return (rv); } -#define atomic_cas_uint(_p, _o, _n) _atomic_cas_word((_p), (_o), (_n)) -#define atomic_cas_ulong(_p, _o, _n) _atomic_cas_word((_p), (_o), (_n)) +#define atomic_cas_uint(_p, _o, _n) _atomic_cas_uint((_p), (_o), (_n)) + +static inline unsigned long +_atomic_cas_ulong(volatile unsigned long *uip, unsigned long o, unsigned long n) +{ + int psr; + unsigned long rv; + + psr = getpsr(); + setpsr(psr | PSR_PIL); + rv = *uip; + if (rv == o) + *uip = n; + setpsr(psr); + + return (rv); +} +#define atomic_cas_ulong(_p, _o, _n) _atomic_cas_ulong((_p), (_o), (_n)) static inline void * _atomic_cas_ptr(volatile void *uip, void *o, void *n) @@ -46,7 +62,7 @@ _atomic_cas_ptr(volatile void *uip, void *o, void *n) #define atomic_cas_ptr(_p, _o, _n) _atomic_cas_ptr((_p), (_o), (_n)) static inline unsigned int -_atomic_swap_word(volatile unsigned int *uip, unsigned int n) +_atomic_swap_uint(volatile unsigned int *uip, unsigned int n) { int psr; unsigned int rv; @@ -59,8 +75,23 @@ _atomic_swap_word(volatile unsigned int *uip, unsigned int n) return (rv); } -#define atomic_swap_uint(_p, _n) _atomic_swap_word((_p), (_n)) -#define atomic_swap_ulong(_p, _n) _atomic_swap_word((_p), (_n)) +#define atomic_swap_uint(_p, _n) _atomic_swap_uint((_p), (_n)) + +static inline unsigned long +_atomic_swap_ulong(volatile unsigned long *uip, unsigned long n) +{ + int psr; + unsigned long rv; + + psr = getpsr(); + setpsr(psr | PSR_PIL); + rv = *uip; + *uip = n; + setpsr(psr); + + return (rv); +} +#define atomic_swap_ulong(_p, _n) _atomic_swap_ulong((_p), (_n)) static inline void * _atomic_swap_ptr(volatile void *uip, void *n) @@ -80,7 +111,7 @@ _atomic_swap_ptr(volatile void *uip, void *n) #define atomic_swap_ptr(_p, _o, _n) _atomic_swap_ptr((_p), (_o), (_n)) static inline unsigned int -_atomic_add_word_nv(volatile unsigned int *uip, unsigned int v) +_atomic_add_int_nv(volatile unsigned int *uip, unsigned int v) { int psr; unsigned int rv; @@ -93,11 +124,26 @@ _atomic_add_word_nv(volatile unsigned int *uip, unsigned int v) return (rv); } -#define atomic_add_int_nv(_p, _v) _atomic_add_word_nv((_p), (_v)) -#define atomic_add_long_nv(_p, _v) _atomic_add_word_nv((_p), (_v)) +#define atomic_add_int_nv(_p, _v) _atomic_add_int_nv((_p), (_v)) + +static inline unsigned long +_atomic_add_long_nv(volatile unsigned long *uip, unsigned long v) +{ + int psr; + unsigned long rv; + + psr = getpsr(); + setpsr(psr | PSR_PIL); + rv = *uip + v; + *uip = rv; + setpsr(psr); + + return (rv); +} +#define atomic_add_long_nv(_p, _v) _atomic_add_long_nv((_p), (_v)) static inline unsigned int -_atomic_sub_word_nv(volatile unsigned int *uip, unsigned int v) +_atomic_sub_int_nv(volatile unsigned int *uip, unsigned int v) { int psr; unsigned int rv; @@ -110,8 +156,23 @@ _atomic_sub_word_nv(volatile unsigned int *uip, unsigned int v) return (rv); } -#define atomic_sub_int_nv(_p, _v) _atomic_sub_word_nv((_p), (_v)) -#define atomic_sub_long_nv(_p, _v) _atomic_sub_word_nv((_p), (_v)) +#define atomic_sub_int_nv(_p, _v) _atomic_sub_int_nv((_p), (_v)) + +static inline unsigned long +_atomic_sub_long_nv(volatile unsigned long *uip, unsigned long v) +{ + int psr; + unsigned long rv; + + psr = getpsr(); + setpsr(psr | PSR_PIL); + rv = *uip - v; + *uip = rv; + setpsr(psr); + + return (rv); +} +#define atomic_sub_long_nv(_p, _v) _atomic_sub_long_nv((_p), (_v)) static inline void atomic_setbits_int(volatile unsigned int *uip, unsigned int v) |