2 * PowerPC atomic operations
5 #ifndef _ASM_PPC_ATOMIC_H_
6 #define _ASM_PPC_ATOMIC_H_
9 typedef struct { volatile int counter; } atomic_t;
11 typedef struct { int counter; } atomic_t;
14 #define ATOMIC_INIT(i) { (i) }
16 #define atomic_read(v) ((v)->counter)
17 #define atomic_set(v,i) (((v)->counter) = (i))
19 extern void atomic_clear_mask(unsigned long mask, unsigned long *addr);
20 extern void atomic_set_mask(unsigned long mask, unsigned long *addr);
22 static __inline__ int atomic_add_return(int a, atomic_t *v)
26 __asm__ __volatile__("\n\
31 : "=&r" (t), "=m" (*v)
32 : "r" (a), "r" (v), "m" (*v)
38 static __inline__ int atomic_sub_return(int a, atomic_t *v)
42 __asm__ __volatile__("\n\
47 : "=&r" (t), "=m" (*v)
48 : "r" (a), "r" (v), "m" (*v)
54 static __inline__ int atomic_inc_return(atomic_t *v)
58 __asm__ __volatile__("\n\
63 : "=&r" (t), "=m" (*v)
70 static __inline__ int atomic_dec_return(atomic_t *v)
74 __asm__ __volatile__("\n\
79 : "=&r" (t), "=m" (*v)
86 #define atomic_add(a, v) ((void) atomic_add_return((a), (v)))
87 #define atomic_sub(a, v) ((void) atomic_sub_return((a), (v)))
88 #define atomic_sub_and_test(a, v) (atomic_sub_return((a), (v)) == 0)
89 #define atomic_inc(v) ((void) atomic_inc_return((v)))
90 #define atomic_dec(v) ((void) atomic_dec_return((v)))
91 #define atomic_dec_and_test(v) (atomic_dec_return((v)) == 0)
93 #endif /* _ASM_PPC_ATOMIC_H_ */