From f24219b4e90cf70ec4a211b17fbabc725a0ddf3c Mon Sep 17 00:00:00 2001 From: Arun Sharma Date: Tue, 26 Jul 2011 16:09:07 -0700 Subject: atomic: move atomic_add_unless to generic code This is in preparation for more generic atomic primitives based on __atomic_add_unless. Signed-off-by: Arun Sharma Signed-off-by: Hans-Christian Egtvedt Reviewed-by: Eric Dumazet Cc: Ingo Molnar Cc: David Miller Acked-by: Mike Frysinger Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- include/asm-generic/atomic.h | 4 ++-- include/linux/atomic.h | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h index 7f84414c5f53..bd18bfd78e9b 100644 --- a/include/asm-generic/atomic.h +++ b/include/asm-generic/atomic.h @@ -129,13 +129,13 @@ static inline void atomic_dec(atomic_t *v) #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n)) -static inline int atomic_add_unless(atomic_t *v, int a, int u) +static inline int __atomic_add_unless(atomic_t *v, int a, int u) { int c, old; c = atomic_read(v); while (c != u && (old = atomic_cmpxchg(v, c, c + a)) != c) c = old; - return c != u; + return c; } static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr) diff --git a/include/linux/atomic.h b/include/linux/atomic.h index 66fed6364122..d5e167a6a398 100644 --- a/include/linux/atomic.h +++ b/include/linux/atomic.h @@ -2,6 +2,20 @@ #define _LINUX_ATOMIC_H #include +/** + * atomic_add_unless - add unless the number is already a given value + * @v: pointer of type atomic_t + * @a: the amount to add to v... + * @u: ...unless v is equal to u. + * + * Atomically adds @a to @v, so long as @v was not already @u. + * Returns non-zero if @v was not @u, and zero otherwise. + */ +static inline int atomic_add_unless(atomic_t *v, int a, int u) +{ + return __atomic_add_unless(v, a, u) != u; +} + /** * atomic_inc_not_zero - increment unless the number is zero * @v: pointer of type atomic_t -- cgit v1.2.3