diff options
author | Paul Irofti <pirofti@cvs.openbsd.org> | 2012-11-19 15:18:07 +0000 |
---|---|---|
committer | Paul Irofti <pirofti@cvs.openbsd.org> | 2012-11-19 15:18:07 +0000 |
commit | 0e08eeef6781467acc87f53e95ba005c5680186b (patch) | |
tree | 3f249c46080de729a84a6f6cb1c62172c2c5e398 | |
parent | d6b26a98fcca45808b4798c6ea16a2341cf4f2a9 (diff) |
Add atomic 32-bit cas operations.
This is needed for future acpi global locking routines.
Okay kettenis@
-rw-r--r-- | sys/arch/amd64/include/atomic.h | 13 | ||||
-rw-r--r-- | sys/arch/i386/include/atomic.h | 13 |
2 files changed, 24 insertions, 2 deletions
diff --git a/sys/arch/amd64/include/atomic.h b/sys/arch/amd64/include/atomic.h index effbb04c4db..48df00fae57 100644 --- a/sys/arch/amd64/include/atomic.h +++ b/sys/arch/amd64/include/atomic.h @@ -1,4 +1,4 @@ -/* $OpenBSD: atomic.h,v 1.8 2011/03/23 16:54:34 pirofti Exp $ */ +/* $OpenBSD: atomic.h,v 1.9 2012/11/19 15:18:06 pirofti Exp $ */ /* $NetBSD: atomic.h,v 1.1 2003/04/26 18:39:37 fvdl Exp $ */ /* @@ -90,6 +90,17 @@ x86_atomic_clearbits_u32(volatile u_int32_t *ptr, u_int32_t bits) __asm __volatile(LOCK " andl %1,%0" : "=m" (*ptr) : "ir" (~bits)); } +static __inline int +x86_atomic_cas_int32(volatile int32_t *ptr, int32_t expect, int32_t set) +{ + int res; + + __asm volatile(LOCK " cmpxchgl %2, %1" : "=a" (res), "=m" (*ptr) + : "r" (set), "a" (expect), "m" (*ptr) : "memory"); + + return (res); +} + static __inline u_long x86_atomic_cas_ul(volatile u_long *ptr, u_long expect, u_long set) { diff --git a/sys/arch/i386/include/atomic.h b/sys/arch/i386/include/atomic.h index 292654f39d8..eac3adc86c6 100644 --- a/sys/arch/i386/include/atomic.h +++ b/sys/arch/i386/include/atomic.h @@ -1,4 +1,4 @@ -/* $OpenBSD: atomic.h,v 1.10 2012/11/19 15:03:55 pirofti Exp $ */ +/* $OpenBSD: atomic.h,v 1.11 2012/11/19 15:18:06 pirofti Exp $ */ /* $NetBSD: atomic.h,v 1.1.2.2 2000/02/21 18:54:07 sommerfeld Exp $ */ /*- @@ -99,6 +99,17 @@ i486_atomic_cas_int(volatile u_int *ptr, u_int expect, u_int set) return (res); } +static __inline int +i386_atomic_cas_int32(volatile int32_t *ptr, int32_t expect, int32_t set) +{ + int res; + + __asm volatile(LOCK " cmpxchgl %2, %1" : "=a" (res), "=m" (*ptr) + : "r" (set), "a" (expect), "m" (*ptr) : "memory"); + + return (res); +} + int ucas_32(volatile int32_t *, int32_t, int32_t); #define futex_atomic_ucas_int32 ucas_32 |