Commit f24219b4 authored by Arun Sharma's avatar Arun Sharma Committed by Linus Torvalds

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: default avatarArun Sharma <asharma@fb.com>
Signed-off-by: default avatarHans-Christian Egtvedt <hans-christian.egtvedt@atmel.com>
Reviewed-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: David Miller <davem@davemloft.net>
Acked-by: default avatarMike Frysinger <vapier@gentoo.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 60063497
...@@ -176,15 +176,15 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v) ...@@ -176,15 +176,15 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
#define atomic_xchg(v, new) (xchg(&((v)->counter), new)) #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
/** /**
* atomic_add_unless - add unless the number is a given value * __atomic_add_unless - add unless the number is a given value
* @v: pointer of type atomic_t * @v: pointer of type atomic_t
* @a: the amount to add to v... * @a: the amount to add to v...
* @u: ...unless v is equal to u. * @u: ...unless v is equal to u.
* *
* Atomically adds @a to @v, so long as it was not @u. * Atomically adds @a to @v, so long as it was not @u.
* Returns non-zero if @v was not @u, and zero otherwise. * Returns the old value of @v.
*/ */
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; int c, old;
c = atomic_read(v); c = atomic_read(v);
...@@ -196,7 +196,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u) ...@@ -196,7 +196,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
break; break;
c = old; c = old;
} }
return c != (u); return c;
} }
...@@ -207,7 +207,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u) ...@@ -207,7 +207,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
* @u: ...unless v is equal to u. * @u: ...unless v is equal to u.
* *
* Atomically adds @a to @v, so long as it was not @u. * Atomically adds @a to @v, so long as it was not @u.
* Returns non-zero if @v was not @u, and zero otherwise. * Returns the old value of @v.
*/ */
static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u) static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
{ {
......
...@@ -208,14 +208,14 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr) ...@@ -208,14 +208,14 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
#define atomic_xchg(v, new) (xchg(&((v)->counter), new)) #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
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; int c, old;
c = atomic_read(v); c = atomic_read(v);
while (c != u && (old = atomic_cmpxchg((v), c, c + a)) != c) while (c != u && (old = atomic_cmpxchg((v), c, c + a)) != c)
c = old; c = old;
return c != u; return c;
} }
#define atomic_inc(v) atomic_add(1, v) #define atomic_inc(v) atomic_add(1, v)
......
...@@ -78,70 +78,63 @@ static inline int atomic_add_return(int i, atomic_t *v) ...@@ -78,70 +78,63 @@ static inline int atomic_add_return(int i, atomic_t *v)
/* /*
* atomic_sub_unless - sub unless the number is a given value * atomic_sub_unless - sub unless the number is a given value
* @v: pointer of type atomic_t * @v: pointer of type atomic_t
* @a: the amount to add to v... * @a: the amount to subtract from v...
* @u: ...unless v is equal to u. * @u: ...unless v is equal to u.
* *
* If the atomic value v is not equal to u, this function subtracts a * Atomically subtract @a from @v, so long as it was not @u.
* from v, and returns non zero. If v is equal to u then it returns * Returns the old value of @v.
* zero. This is done as an atomic operation.
*/ */
static inline int atomic_sub_unless(atomic_t *v, int a, int u) static inline void atomic_sub_unless(atomic_t *v, int a, int u)
{ {
int tmp, result = 0; int tmp;
asm volatile( asm volatile(
"/* atomic_sub_unless */\n" "/* atomic_sub_unless */\n"
"1: ssrf 5\n" "1: ssrf 5\n"
" ld.w %0, %3\n" " ld.w %0, %2\n"
" cp.w %0, %5\n" " cp.w %0, %4\n"
" breq 1f\n" " breq 1f\n"
" sub %0, %4\n" " sub %0, %3\n"
" stcond %2, %0\n" " stcond %1, %0\n"
" brne 1b\n" " brne 1b\n"
" mov %1, 1\n"
"1:" "1:"
: "=&r"(tmp), "=&r"(result), "=o"(v->counter) : "=&r"(tmp), "=o"(v->counter)
: "m"(v->counter), "rKs21"(a), "rKs21"(u), "1"(result) : "m"(v->counter), "rKs21"(a), "rKs21"(u)
: "cc", "memory"); : "cc", "memory");
return result;
} }
/* /*
* atomic_add_unless - add unless the number is a given value * __atomic_add_unless - add unless the number is a given value
* @v: pointer of type atomic_t * @v: pointer of type atomic_t
* @a: the amount to add to v... * @a: the amount to add to v...
* @u: ...unless v is equal to u. * @u: ...unless v is equal to u.
* *
* If the atomic value v is not equal to u, this function adds a to v, * Atomically adds @a to @v, so long as it was not @u.
* and returns non zero. If v is equal to u then it returns zero. This * Returns the old value of @v.
* is done as an atomic operation.
*/ */
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 tmp, result; int tmp, old = atomic_read(v);
if (__builtin_constant_p(a) && (a >= -1048575) && (a <= 1048576)) if (__builtin_constant_p(a) && (a >= -1048575) && (a <= 1048576))
result = atomic_sub_unless(v, -a, u); atomic_sub_unless(v, -a, u);
else { else {
result = 0;
asm volatile( asm volatile(
"/* atomic_add_unless */\n" "/* __atomic_add_unless */\n"
"1: ssrf 5\n" "1: ssrf 5\n"
" ld.w %0, %3\n" " ld.w %0, %2\n"
" cp.w %0, %5\n" " cp.w %0, %4\n"
" breq 1f\n" " breq 1f\n"
" add %0, %4\n" " add %0, %3\n"
" stcond %2, %0\n" " stcond %1, %0\n"
" brne 1b\n" " brne 1b\n"
" mov %1, 1\n"
"1:" "1:"
: "=&r"(tmp), "=&r"(result), "=o"(v->counter) : "=&r"(tmp), "=o"(v->counter)
: "m"(v->counter), "r"(a), "ir"(u), "1"(result) : "m"(v->counter), "r"(a), "ir"(u)
: "cc", "memory"); : "cc", "memory");
} }
return result; return old;
} }
/* /*
......
...@@ -89,13 +89,13 @@ static inline void atomic_set_mask(int mask, atomic_t *v) ...@@ -89,13 +89,13 @@ static inline void atomic_set_mask(int mask, atomic_t *v)
#define atomic_cmpxchg(v, o, n) ((int)cmpxchg(&((v)->counter), (o), (n))) #define atomic_cmpxchg(v, o, n) ((int)cmpxchg(&((v)->counter), (o), (n)))
#define atomic_xchg(v, new) (xchg(&((v)->counter), new)) #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
#define atomic_add_unless(v, a, u) \ #define __atomic_add_unless(v, a, u) \
({ \ ({ \
int c, old; \ int c, old; \
c = atomic_read(v); \ c = atomic_read(v); \
while (c != (u) && (old = atomic_cmpxchg((v), c, c + (a))) != c) \ while (c != (u) && (old = atomic_cmpxchg((v), c, c + (a))) != c) \
c = old; \ c = old; \
c != (u); \ c; \
}) })
/* /*
......
...@@ -138,7 +138,7 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new) ...@@ -138,7 +138,7 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
#define atomic_xchg(v, new) (xchg(&((v)->counter), new)) #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
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 ret; int ret;
unsigned long flags; unsigned long flags;
...@@ -148,7 +148,7 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u) ...@@ -148,7 +148,7 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
if (ret != u) if (ret != u)
v->counter += a; v->counter += a;
cris_atomic_restore(v, flags); cris_atomic_restore(v, flags);
return ret != u; return ret;
} }
/* Atomic operations are already serializing */ /* Atomic operations are already serializing */
......
...@@ -241,7 +241,7 @@ extern uint32_t __xchg_32(uint32_t i, volatile void *v); ...@@ -241,7 +241,7 @@ extern uint32_t __xchg_32(uint32_t i, volatile void *v);
#define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter)) #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
#define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter)) #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
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; int c, old;
c = atomic_read(v); c = atomic_read(v);
...@@ -253,7 +253,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u) ...@@ -253,7 +253,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
break; break;
c = old; c = old;
} }
return c != (u); return c;
} }
......
...@@ -104,7 +104,7 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new) ...@@ -104,7 +104,7 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
#define atomic_xchg(v, new) (xchg(&((v)->counter), new)) #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
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 ret; int ret;
unsigned long flags; unsigned long flags;
...@@ -114,7 +114,7 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u) ...@@ -114,7 +114,7 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
if (ret != u) if (ret != u)
v->counter += a; v->counter += a;
local_irq_restore(flags); local_irq_restore(flags);
return ret != u; return ret;
} }
static __inline__ void atomic_clear_mask(unsigned long mask, unsigned long *v) static __inline__ void atomic_clear_mask(unsigned long mask, unsigned long *v)
......
...@@ -90,7 +90,7 @@ ia64_atomic64_sub (__s64 i, atomic64_t *v) ...@@ -90,7 +90,7 @@ ia64_atomic64_sub (__s64 i, atomic64_t *v)
(cmpxchg(&((v)->counter), old, new)) (cmpxchg(&((v)->counter), old, new))
#define atomic64_xchg(v, new) (xchg(&((v)->counter), new)) #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
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; int c, old;
c = atomic_read(v); c = atomic_read(v);
...@@ -102,7 +102,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u) ...@@ -102,7 +102,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
break; break;
c = old; c = old;
} }
return c != (u); return c;
} }
......
...@@ -239,15 +239,15 @@ static __inline__ int atomic_dec_return(atomic_t *v) ...@@ -239,15 +239,15 @@ static __inline__ int atomic_dec_return(atomic_t *v)
#define atomic_xchg(v, new) (xchg(&((v)->counter), new)) #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
/** /**
* atomic_add_unless - add unless the number is a given value * __atomic_add_unless - add unless the number is a given value
* @v: pointer of type atomic_t * @v: pointer of type atomic_t
* @a: the amount to add to v... * @a: the amount to add to v...
* @u: ...unless v is equal to u. * @u: ...unless v is equal to u.
* *
* Atomically adds @a to @v, so long as it was not @u. * Atomically adds @a to @v, so long as it was not @u.
* Returns non-zero if @v was not @u, and zero otherwise. * Returns the old value of @v.
*/ */
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; int c, old;
c = atomic_read(v); c = atomic_read(v);
...@@ -259,7 +259,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u) ...@@ -259,7 +259,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
break; break;
c = old; c = old;
} }
return c != (u); return c;
} }
......
...@@ -183,7 +183,7 @@ static inline void atomic_set_mask(unsigned long mask, unsigned long *v) ...@@ -183,7 +183,7 @@ static inline void atomic_set_mask(unsigned long mask, unsigned long *v)
__asm__ __volatile__("orl %1,%0" : "+m" (*v) : ASM_DI (mask)); __asm__ __volatile__("orl %1,%0" : "+m" (*v) : ASM_DI (mask));
} }
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; int c, old;
c = atomic_read(v); c = atomic_read(v);
...@@ -195,7 +195,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u) ...@@ -195,7 +195,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
break; break;
c = old; c = old;
} }
return c != (u); return c;
} }
......
...@@ -303,15 +303,15 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v) ...@@ -303,15 +303,15 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
#define atomic_xchg(v, new) (xchg(&((v)->counter), (new))) #define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
/** /**
* atomic_add_unless - add unless the number is a given value * __atomic_add_unless - add unless the number is a given value
* @v: pointer of type atomic_t * @v: pointer of type atomic_t
* @a: the amount to add to v... * @a: the amount to add to v...
* @u: ...unless v is equal to u. * @u: ...unless v is equal to u.
* *
* Atomically adds @a to @v, so long as it was not @u. * Atomically adds @a to @v, so long as it was not @u.
* Returns non-zero if @v was not @u, and zero otherwise. * Returns the old value of @v.
*/ */
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; int c, old;
c = atomic_read(v); c = atomic_read(v);
...@@ -323,7 +323,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u) ...@@ -323,7 +323,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
break; break;
c = old; c = old;
} }
return c != (u); return c;
} }
#define atomic_dec_return(v) atomic_sub_return(1, (v)) #define atomic_dec_return(v) atomic_sub_return(1, (v))
...@@ -679,7 +679,7 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v) ...@@ -679,7 +679,7 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
* @u: ...unless v is equal to u. * @u: ...unless v is equal to u.
* *
* Atomically adds @a to @v, so long as it was not @u. * Atomically adds @a to @v, so long as it was not @u.
* Returns non-zero if @v was not @u, and zero otherwise. * Returns the old value of @v.
*/ */
static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u) static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
{ {
......
...@@ -260,13 +260,13 @@ static inline void atomic_dec(atomic_t *v) ...@@ -260,13 +260,13 @@ static inline void atomic_dec(atomic_t *v)
#define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0) #define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
#define atomic_inc_and_test(v) (atomic_add_return(1, (v)) == 0) #define atomic_inc_and_test(v) (atomic_add_return(1, (v)) == 0)
#define atomic_add_unless(v, a, u) \ #define __atomic_add_unless(v, a, u) \
({ \ ({ \
int c, old; \ int c, old; \
c = atomic_read(v); \ c = atomic_read(v); \
while (c != (u) && (old = atomic_cmpxchg((v), c, c + (a))) != c) \ while (c != (u) && (old = atomic_cmpxchg((v), c, c + (a))) != c) \
c = old; \ c = old; \
c != (u); \ c; \
}) })
......
...@@ -197,15 +197,15 @@ static __inline__ int atomic_read(const atomic_t *v) ...@@ -197,15 +197,15 @@ static __inline__ int atomic_read(const atomic_t *v)
#define atomic_xchg(v, new) (xchg(&((v)->counter), new)) #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
/** /**
* atomic_add_unless - add unless the number is a given value * __atomic_add_unless - add unless the number is a given value
* @v: pointer of type atomic_t * @v: pointer of type atomic_t
* @a: the amount to add to v... * @a: the amount to add to v...
* @u: ...unless v is equal to u. * @u: ...unless v is equal to u.
* *
* Atomically adds @a to @v, so long as it was not @u. * Atomically adds @a to @v, so long as it was not @u.
* Returns non-zero if @v was not @u, and zero otherwise. * Returns the old value of @v.
*/ */
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; int c, old;
c = atomic_read(v); c = atomic_read(v);
...@@ -217,7 +217,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u) ...@@ -217,7 +217,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
break; break;
c = old; c = old;
} }
return c != (u); return c;
} }
...@@ -316,7 +316,7 @@ atomic64_read(const atomic64_t *v) ...@@ -316,7 +316,7 @@ atomic64_read(const atomic64_t *v)
* @u: ...unless v is equal to u. * @u: ...unless v is equal to u.
* *
* Atomically adds @a to @v, so long as it was not @u. * Atomically adds @a to @v, so long as it was not @u.
* Returns non-zero if @v was not @u, and zero otherwise. * Returns the old value of @v.
*/ */
static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u) static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
{ {
......
...@@ -181,21 +181,21 @@ static __inline__ int atomic_dec_return(atomic_t *v) ...@@ -181,21 +181,21 @@ static __inline__ int atomic_dec_return(atomic_t *v)
#define atomic_xchg(v, new) (xchg(&((v)->counter), new)) #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
/** /**
* atomic_add_unless - add unless the number is a given value * __atomic_add_unless - add unless the number is a given value
* @v: pointer of type atomic_t * @v: pointer of type atomic_t
* @a: the amount to add to v... * @a: the amount to add to v...
* @u: ...unless v is equal to u. * @u: ...unless v is equal to u.
* *
* Atomically adds @a to @v, so long as it was not @u. * Atomically adds @a to @v, so long as it was not @u.
* Returns non-zero if @v was not @u, and zero otherwise. * Returns the old value of @v.
*/ */
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 t; int t;
__asm__ __volatile__ ( __asm__ __volatile__ (
PPC_RELEASE_BARRIER PPC_RELEASE_BARRIER
"1: lwarx %0,0,%1 # atomic_add_unless\n\ "1: lwarx %0,0,%1 # __atomic_add_unless\n\
cmpw 0,%0,%3 \n\ cmpw 0,%0,%3 \n\
beq- 2f \n\ beq- 2f \n\
add %0,%2,%0 \n" add %0,%2,%0 \n"
...@@ -209,7 +209,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u) ...@@ -209,7 +209,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
: "r" (&v->counter), "r" (a), "r" (u) : "r" (&v->counter), "r" (a), "r" (u)
: "cc", "memory"); : "cc", "memory");
return t != u; return t;
} }
...@@ -443,7 +443,7 @@ static __inline__ long atomic64_dec_if_positive(atomic64_t *v) ...@@ -443,7 +443,7 @@ static __inline__ long atomic64_dec_if_positive(atomic64_t *v)
* @u: ...unless v is equal to u. * @u: ...unless v is equal to u.
* *
* Atomically adds @a to @v, so long as it was not @u. * Atomically adds @a to @v, so long as it was not @u.
* Returns non-zero if @v was not @u, and zero otherwise. * Returns the old value of @v.
*/ */
static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u) static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
{ {
...@@ -451,7 +451,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u) ...@@ -451,7 +451,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
__asm__ __volatile__ ( __asm__ __volatile__ (
PPC_RELEASE_BARRIER PPC_RELEASE_BARRIER
"1: ldarx %0,0,%1 # atomic_add_unless\n\ "1: ldarx %0,0,%1 # __atomic_add_unless\n\
cmpd 0,%0,%3 \n\ cmpd 0,%0,%3 \n\
beq- 2f \n\ beq- 2f \n\
add %0,%2,%0 \n" add %0,%2,%0 \n"
......
...@@ -93,7 +93,7 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new) ...@@ -93,7 +93,7 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
return old; return old;
} }
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; int c, old;
c = atomic_read(v); c = atomic_read(v);
...@@ -105,7 +105,7 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u) ...@@ -105,7 +105,7 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
break; break;
c = old; c = old;
} }
return c != u; return c;
} }
......
...@@ -38,15 +38,15 @@ ...@@ -38,15 +38,15 @@
#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n))) #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
/** /**
* atomic_add_unless - add unless the number is a given value * __atomic_add_unless - add unless the number is a given value
* @v: pointer of type atomic_t * @v: pointer of type atomic_t
* @a: the amount to add to v... * @a: the amount to add to v...
* @u: ...unless v is equal to u. * @u: ...unless v is equal to u.
* *
* Atomically adds @a to @v, so long as it was not @u. * Atomically adds @a to @v, so long as it was not @u.
* Returns non-zero if @v was not @u, and zero otherwise. * Returns the old value of @v.
*/ */
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; int c, old;
c = atomic_read(v); c = atomic_read(v);
...@@ -59,7 +59,7 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u) ...@@ -59,7 +59,7 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
c = old; c = old;
} }
return c != (u); return c;
} }
#define smp_mb__before_atomic_dec() smp_mb() #define smp_mb__before_atomic_dec() smp_mb()
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
extern int __atomic_add_return(int, atomic_t *); extern int __atomic_add_return(int, atomic_t *);
extern int atomic_cmpxchg(atomic_t *, int, int); extern int atomic_cmpxchg(atomic_t *, int, int);
#define atomic_xchg(v, new) (xchg(&((v)->counter), new)) #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
extern int atomic_add_unless(atomic_t *, int, int); extern int __atomic_add_unless(atomic_t *, int, int);
extern void atomic_set(atomic_t *, int); extern void atomic_set(atomic_t *, int);
#define atomic_read(v) (*(volatile int *)&(v)->counter) #define atomic_read(v) (*(volatile int *)&(v)->counter)
......
...@@ -70,7 +70,7 @@ extern long atomic64_sub_ret(long, atomic64_t *); ...@@ -70,7 +70,7 @@ extern long atomic64_sub_ret(long, atomic64_t *);
#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n))) #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
#define atomic_xchg(v, new) (xchg(&((v)->counter), new)) #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
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; int c, old;
c = atomic_read(v); c = atomic_read(v);
...@@ -82,7 +82,7 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u) ...@@ -82,7 +82,7 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
break; break;
c = old; c = old;
} }
return c != (u); return c;
} }
......
...@@ -81,18 +81,18 @@ static inline int atomic_add_return(int i, atomic_t *v) ...@@ -81,18 +81,18 @@ static inline int atomic_add_return(int i, atomic_t *v)
} }
/** /**
* atomic_add_unless - add unless the number is already a given value * __atomic_add_unless - add unless the number is already a given value
* @v: pointer of type atomic_t * @v: pointer of type atomic_t
* @a: the amount to add to v... * @a: the amount to add to v...
* @u: ...unless v is equal to u. * @u: ...unless v is equal to u.
* *
* Atomically adds @a to @v, so long as @v was not already @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. * Returns the old value of @v.
*/ */
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)
{ {
smp_mb(); /* barrier for proper semantics */ smp_mb(); /* barrier for proper semantics */
return _atomic_xchg_add_unless(v, a, u) != u; return _atomic_xchg_add_unless(v, a, u);
} }
/** /**
...@@ -199,7 +199,7 @@ static inline u64 atomic64_add_return(u64 i, atomic64_t *v) ...@@ -199,7 +199,7 @@ static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
* @u: ...unless v is equal to u. * @u: ...unless v is equal to u.
* *
* Atomically adds @a to @v, so long as @v was not already @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. * Returns the old value of @v.
*/ */
static inline u64 atomic64_add_unless(atomic64_t *v, u64 a, u64 u) static inline u64 atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
{ {
......
...@@ -64,7 +64,7 @@ static inline int atomic_add_return(int i, atomic_t *v) ...@@ -64,7 +64,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
return val; return val;
} }
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 guess, oldval = v->counter; int guess, oldval = v->counter;
do { do {
...@@ -73,7 +73,7 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u) ...@@ -73,7 +73,7 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
guess = oldval; guess = oldval;
oldval = atomic_cmpxchg(v, guess, guess + a); oldval = atomic_cmpxchg(v, guess, guess + a);
} while (guess != oldval); } while (guess != oldval);
return oldval != u; return oldval;
} }
/* Now the true 64-bit operations. */ /* Now the true 64-bit operations. */
......
...@@ -221,15 +221,15 @@ static inline int atomic_xchg(atomic_t *v, int new) ...@@ -221,15 +221,15 @@ static inline int atomic_xchg(atomic_t *v, int new)
} }
/** /**
* atomic_add_unless - add unless the number is already a given value * __atomic_add_unless - add unless the number is already a given value
* @v: pointer of type atomic_t * @v: pointer of type atomic_t
* @a: the amount to add to v... * @a: the amount to add to v...
* @u: ...unless v is equal to u. * @u: ...unless v is equal to u.
* *
* Atomically adds @a to @v, so long as @v was not already @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. * Returns the old value of @v.
*/ */
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; int c, old;
c = atomic_read(v); c = atomic_read(v);
...@@ -241,7 +241,7 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u) ...@@ -241,7 +241,7 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
break; break;
c = old; c = old;
} }
return c != (u); return c;
} }
......
...@@ -263,7 +263,7 @@ static inline int atomic64_add_negative(long long i, atomic64_t *v) ...@@ -263,7 +263,7 @@ static inline int atomic64_add_negative(long long i, atomic64_t *v)
* @u: ...unless v is equal to u. * @u: ...unless v is equal to u.
* *
* Atomically adds @a to @v, so long as it was not @u. * Atomically adds @a to @v, so long as it was not @u.
* Returns non-zero if @v was not @u, and zero otherwise. * Returns the old value of @v.
*/ */
static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u) static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
{ {
......
...@@ -202,7 +202,7 @@ static inline long atomic64_xchg(atomic64_t *v, long new) ...@@ -202,7 +202,7 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
* @u: ...unless v is equal to u. * @u: ...unless v is equal to u.
* *
* Atomically adds @a to @v, so long as it was not @u. * Atomically adds @a to @v, so long as it was not @u.
* Returns non-zero if @v was not @u, and zero otherwise. * Returns the old value of @v.
*/ */
static inline int atomic64_add_unless(atomic64_t *v, long a, long u) static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
{ {
......
...@@ -225,15 +225,15 @@ static inline int atomic_sub_return(int i, atomic_t * v) ...@@ -225,15 +225,15 @@ static inline int atomic_sub_return(int i, atomic_t * v)
#define atomic_xchg(v, new) (xchg(&((v)->counter), new)) #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
/** /**
* atomic_add_unless - add unless the number is a given value * __atomic_add_unless - add unless the number is a given value
* @v: pointer of type atomic_t * @v: pointer of type atomic_t
* @a: the amount to add to v... * @a: the amount to add to v...
* @u: ...unless v is equal to u. * @u: ...unless v is equal to u.
* *
* Atomically adds @a to @v, so long as it was not @u. * Atomically adds @a to @v, so long as it was not @u.
* Returns non-zero if @v was not @u, and zero otherwise. * Returns the old value of @v.
*/ */
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; int c, old;
c = atomic_read(v); c = atomic_read(v);
...@@ -245,7 +245,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u) ...@@ -245,7 +245,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
break; break;
c = old; c = old;
} }
return c != (u); return c;
} }
......
...@@ -129,13 +129,13 @@ static inline void atomic_dec(atomic_t *v) ...@@ -129,13 +129,13 @@ static inline void atomic_dec(atomic_t *v)
#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n)) #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; int c, old;
c = atomic_read(v); c = atomic_read(v);
while (c != u && (old = atomic_cmpxchg(v, c, c + a)) != c) while (c != u && (old = atomic_cmpxchg(v, c, c + a)) != c)
c = old; c = old;
return c != u; return c;
} }
static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr) static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
......
...@@ -2,6 +2,20 @@ ...@@ -2,6 +2,20 @@
#define _LINUX_ATOMIC_H #define _LINUX_ATOMIC_H
#include <asm/atomic.h> #include <asm/atomic.h>
/**
* 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 * atomic_inc_not_zero - increment unless the number is zero
* @v: pointer of type atomic_t * @v: pointer of type atomic_t
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment