Go to the documentation of this file. 1 #ifndef _ASM_IA64_ATOMIC_H
2 #define _ASM_IA64_ATOMIC_H
15 #include <linux/types.h>
17 #include <asm/intrinsics.h>
20 #define ATOMIC_INIT(i) { (i) }
21 #define ATOMIC64_INIT(i) { (i) }
23 #define atomic_read(v) (*(volatile int *)&(v)->counter)
24 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
26 #define atomic_set(v,i) (((v)->counter) = (i))
27 #define atomic64_set(v,i) (((v)->counter) = (i))
85 #define atomic_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), old, new))
86 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
88 #define atomic64_cmpxchg(v, old, new) \
89 (cmpxchg(&((v)->counter), old, new))
90 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
123 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
125 #define atomic_add_return(i,v) \
127 int __ia64_aar_i = (i); \
128 (__builtin_constant_p(i) \
129 && ( (__ia64_aar_i == 1) || (__ia64_aar_i == 4) \
130 || (__ia64_aar_i == 8) || (__ia64_aar_i == 16) \
131 || (__ia64_aar_i == -1) || (__ia64_aar_i == -4) \
132 || (__ia64_aar_i == -8) || (__ia64_aar_i == -16))) \
133 ? ia64_fetch_and_add(__ia64_aar_i, &(v)->counter) \
134 : ia64_atomic_add(__ia64_aar_i, v); \
137 #define atomic64_add_return(i,v) \
139 long __ia64_aar_i = (i); \
140 (__builtin_constant_p(i) \
141 && ( (__ia64_aar_i == 1) || (__ia64_aar_i == 4) \
142 || (__ia64_aar_i == 8) || (__ia64_aar_i == 16) \
143 || (__ia64_aar_i == -1) || (__ia64_aar_i == -4) \
144 || (__ia64_aar_i == -8) || (__ia64_aar_i == -16))) \
145 ? ia64_fetch_and_add(__ia64_aar_i, &(v)->counter) \
146 : ia64_atomic64_add(__ia64_aar_i, v); \
165 #define atomic_sub_return(i,v) \
167 int __ia64_asr_i = (i); \
168 (__builtin_constant_p(i) \
169 && ( (__ia64_asr_i == 1) || (__ia64_asr_i == 4) \
170 || (__ia64_asr_i == 8) || (__ia64_asr_i == 16) \
171 || (__ia64_asr_i == -1) || (__ia64_asr_i == -4) \
172 || (__ia64_asr_i == -8) || (__ia64_asr_i == -16))) \
173 ? ia64_fetch_and_add(-__ia64_asr_i, &(v)->counter) \
174 : ia64_atomic_sub(__ia64_asr_i, v); \
177 #define atomic64_sub_return(i,v) \
179 long __ia64_asr_i = (i); \
180 (__builtin_constant_p(i) \
181 && ( (__ia64_asr_i == 1) || (__ia64_asr_i == 4) \
182 || (__ia64_asr_i == 8) || (__ia64_asr_i == 16) \
183 || (__ia64_asr_i == -1) || (__ia64_asr_i == -4) \
184 || (__ia64_asr_i == -8) || (__ia64_asr_i == -16))) \
185 ? ia64_fetch_and_add(-__ia64_asr_i, &(v)->counter) \
186 : ia64_atomic64_sub(__ia64_asr_i, v); \
189 #define atomic_dec_return(v) atomic_sub_return(1, (v))
190 #define atomic_inc_return(v) atomic_add_return(1, (v))
191 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
192 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
194 #define atomic_sub_and_test(i,v) (atomic_sub_return((i), (v)) == 0)
195 #define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
196 #define atomic_inc_and_test(v) (atomic_add_return(1, (v)) == 0)
197 #define atomic64_sub_and_test(i,v) (atomic64_sub_return((i), (v)) == 0)
198 #define atomic64_dec_and_test(v) (atomic64_sub_return(1, (v)) == 0)
199 #define atomic64_inc_and_test(v) (atomic64_add_return(1, (v)) == 0)
201 #define atomic_add(i,v) atomic_add_return((i), (v))
202 #define atomic_sub(i,v) atomic_sub_return((i), (v))
203 #define atomic_inc(v) atomic_add(1, (v))
204 #define atomic_dec(v) atomic_sub(1, (v))
206 #define atomic64_add(i,v) atomic64_add_return((i), (v))
207 #define atomic64_sub(i,v) atomic64_sub_return((i), (v))
208 #define atomic64_inc(v) atomic64_add(1, (v))
209 #define atomic64_dec(v) atomic64_sub(1, (v))
212 #define smp_mb__before_atomic_dec() barrier()
213 #define smp_mb__after_atomic_dec() barrier()
214 #define smp_mb__before_atomic_inc() barrier()
215 #define smp_mb__after_atomic_inc() barrier()