Go to the documentation of this file.
15 #ifndef __ASM_GENERIC_ATOMIC_H
16 #define __ASM_GENERIC_ATOMIC_H
18 #include <asm/cmpxchg.h>
22 # if !defined(atomic_add_return) || !defined(atomic_sub_return) || \
23 !defined(atomic_clear_mask) || !defined(atomic_set_mask)
24 # error "SMP requires a little arch-specific magic"
33 #define ATOMIC_INIT(i) { (i) }
44 #define atomic_read(v) (*(volatile int *)&(v)->counter)
54 #define atomic_set(v, i) (((v)->counter) = (i))
65 #ifndef atomic_add_return
88 #ifndef atomic_sub_return
129 #define atomic_dec_return(v) atomic_sub_return(1, (v))
130 #define atomic_inc_return(v) atomic_add_return(1, (v))
132 #define atomic_sub_and_test(i, v) (atomic_sub_return((i), (v)) == 0)
133 #define atomic_dec_and_test(v) (atomic_dec_return(v) == 0)
134 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
136 #define atomic_xchg(ptr, v) (xchg(&(ptr)->counter, (v)))
137 #define atomic_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), (old), (new)))
139 #define cmpxchg_local(ptr, o, n) \
140 ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
141 (unsigned long)(n), sizeof(*(ptr))))
143 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
161 #ifndef atomic_clear_mask
180 #ifndef atomic_set_mask
192 #define smp_mb__before_atomic_dec() barrier()
193 #define smp_mb__after_atomic_dec() barrier()
194 #define smp_mb__before_atomic_inc() barrier()
195 #define smp_mb__after_atomic_inc() barrier()