Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[POWERPC] atomic.h: Add atomic64 cmpxchg, xchg and add_unless to powerpc

atomic.h : Add atomic64 cmpxchg, xchg and add_unless to powerpc

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Signed-off-by: Paul Mackerras <paulus@samba.org>

authored by

Mathieu Desnoyers and committed by
Paul Mackerras
41806ef4 8c0238b3

+39 -1
+39 -1
include/asm-powerpc/atomic.h
··· 165 165 return t; 166 166 } 167 167 168 - #define atomic_cmpxchg(v, o, n) ((int)cmpxchg(&((v)->counter), (o), (n))) 168 + #define atomic_cmpxchg(v, o, n) \ 169 + ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n))) 169 170 #define atomic_xchg(v, new) (xchg(&((v)->counter), new)) 170 171 171 172 /** ··· 413 412 414 413 return t; 415 414 } 415 + 416 + #define atomic64_cmpxchg(v, o, n) \ 417 + ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n))) 418 + #define atomic64_xchg(v, new) (xchg(&((v)->counter), new)) 419 + 420 + /** 421 + * atomic64_add_unless - add unless the number is a given value 422 + * @v: pointer of type atomic64_t 423 + * @a: the amount to add to v... 424 + * @u: ...unless v is equal to u. 425 + * 426 + * Atomically adds @a to @v, so long as it was not @u. 427 + * Returns non-zero if @v was not @u, and zero otherwise. 428 + */ 429 + static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u) 430 + { 431 + long t; 432 + 433 + __asm__ __volatile__ ( 434 + LWSYNC_ON_SMP 435 + "1: ldarx %0,0,%1 # atomic_add_unless\n\ 436 + cmpd 0,%0,%3 \n\ 437 + beq- 2f \n\ 438 + add %0,%2,%0 \n" 439 + " stdcx. %0,0,%1 \n\ 440 + bne- 1b \n" 441 + ISYNC_ON_SMP 442 + " subf %0,%2,%0 \n\ 443 + 2:" 444 + : "=&r" (t) 445 + : "r" (&v->counter), "r" (a), "r" (u) 446 + : "cc", "memory"); 447 + 448 + return t != u; 449 + } 450 + 451 + #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0) 416 452 417 453 #endif /* __powerpc64__ */ 418 454