@@ -226,31 +226,29 @@ static inline int atomic_cmpxchg_int(unsigned int *p,
226
226
#define atomic_load_acq_64 atomic_load_acq_long
227
227
#define atomic_store_rel_64 atomic_store_rel_long
228
228
229
- /*
230
- * #define atomic_xadd_int(P, V) \
231
- * (return (*(unsigned long *)(P)); *(unsigned long *)(P) += (V);)
232
- */
233
- static inline int atomic_xadd_int (unsigned int * p , unsigned int v )
234
- {
235
- __asm __volatile (BUS_LOCK "xaddl %0,%1"
236
- : "+ r " (v), " + m " (*p)
237
- :
238
- : " cc ", " memory ");
239
- return v ;
240
- }
241
-
242
- static inline int atomic_add_return (int v , unsigned int * p )
243
- {
244
- return v + atomic_xadd_int (p , v );
245
- }
246
-
247
- static inline int atomic_sub_return (int v , unsigned int * p )
248
- {
249
- return atomic_xadd_int (p , - v ) - v ;
250
- }
251
-
252
- #define atomic_inc_return (v ) atomic_add_return(1, (v))
253
- #define atomic_dec_return (v ) atomic_sub_return(1, (v))
229
+ #define build_atomic_xadd (name , size , type , ptr , v ) \
230
+ static inline type name(type *ptr, type v) \
231
+ { \
232
+ asm volatile(BUS_LOCK "xadd" size " %0,%1" \
233
+ : "+r" (v), "+m" (*p) \
234
+ : \
235
+ : "cc", "memory"); \
236
+ return v; \
237
+ }
238
+ build_atomic_xadd (atomic_xadd , "l" , int , p , v )
239
+ build_atomic_xadd (atomic_xadd64 , "q" , long , p , v )
240
+
241
+ #define atomic_add_return (p , v ) ( atomic_xadd(p, v) + v )
242
+ #define atomic_sub_return (p , v ) ( atomic_xadd(p, -v) - v )
243
+
244
+ #define atomic_inc_return (v ) atomic_add_return((v), 1)
245
+ #define atomic_dec_return (v ) atomic_sub_return((v), 1)
246
+
247
+ #define atomic_add64_return (p , v ) ( atomic_xadd64(p, v) + v )
248
+ #define atomic_sub64_return (p , v ) ( atomic_xadd64(p, -v) - v )
249
+
250
+ #define atomic_inc64_return (v ) atomic_add64_return((v), 1)
251
+ #define atomic_dec64_return (v ) atomic_sub64_return((v), 1)
254
252
255
253
static inline int
256
254
atomic_cmpset_long (unsigned long * dst , unsigned long expect , unsigned long src )
0 commit comments