Skip to content

Commit f24219b

Browse files
Arun Sharmatorvalds
authored andcommitted
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 <asharma@fb.com> Signed-off-by: Hans-Christian Egtvedt <hans-christian.egtvedt@atmel.com> Reviewed-by: Eric Dumazet <eric.dumazet@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: David Miller <davem@davemloft.net> Acked-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 6006349 commit f24219b

26 files changed

Lines changed: 109 additions & 102 deletions

File tree

‎arch/alpha/include/asm/atomic.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,15 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
176176
#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
177177

178178
/**
179-
* atomic_add_unless - add unless the number is a given value
179+
* __atomic_add_unless - add unless the number is a given value
180180
* @v: pointer of type atomic_t
181181
* @a: the amount to add to v...
182182
* @u: ...unless v is equal to u.
183183
*
184184
* Atomically adds @a to @v, so long as it was not @u.
185-
* Returns non-zero if @v was not @u, and zero otherwise.
185+
* Returns the old value of @v.
186186
*/
187-
static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
187+
static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
188188
{
189189
int c, old;
190190
c = atomic_read(v);
@@ -196,7 +196,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
196196
break;
197197
c = old;
198198
}
199-
return c != (u);
199+
return c;
200200
}
201201

202202

@@ -207,7 +207,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
207207
* @u: ...unless v is equal to u.
208208
*
209209
* Atomically adds @a to @v, so long as it was not @u.
210-
* Returns non-zero if @v was not @u, and zero otherwise.
210+
* Returns the old value of @v.
211211
*/
212212
static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
213213
{

‎arch/arm/include/asm/atomic.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,14 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
208208

209209
#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
210210

211-
static inline int atomic_add_unless(atomic_t *v, int a, int u)
211+
static inline int __atomic_add_unless(atomic_t *v, int a, int u)
212212
{
213213
int c, old;
214214

215215
c = atomic_read(v);
216216
while (c != u && (old = atomic_cmpxchg((v), c, c + a)) != c)
217217
c = old;
218-
return c != u;
218+
return c;
219219
}
220220

221221
#define atomic_inc(v) atomic_add(1, v)

‎arch/avr32/include/asm/atomic.h‎

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -78,70 +78,63 @@ static inline int atomic_add_return(int i, atomic_t *v)
7878
/*
7979
* atomic_sub_unless - sub unless the number is a given value
8080
* @v: pointer of type atomic_t
81-
* @a: the amount to add to v...
81+
* @a: the amount to subtract from v...
8282
* @u: ...unless v is equal to u.
8383
*
84-
* If the atomic value v is not equal to u, this function subtracts a
85-
* from v, and returns non zero. If v is equal to u then it returns
86-
* zero. This is done as an atomic operation.
84+
* Atomically subtract @a from @v, so long as it was not @u.
85+
* Returns the old value of @v.
8786
*/
88-
static inline int atomic_sub_unless(atomic_t *v, int a, int u)
87+
static inline void atomic_sub_unless(atomic_t *v, int a, int u)
8988
{
90-
int tmp, result = 0;
89+
int tmp;
9190

9291
asm volatile(
9392
"/* atomic_sub_unless */\n"
9493
"1: ssrf 5\n"
95-
" ld.w %0, %3\n"
96-
" cp.w %0, %5\n"
94+
" ld.w %0, %2\n"
95+
" cp.w %0, %4\n"
9796
" breq 1f\n"
98-
" sub %0, %4\n"
99-
" stcond %2, %0\n"
97+
" sub %0, %3\n"
98+
" stcond %1, %0\n"
10099
" brne 1b\n"
101-
" mov %1, 1\n"
102100
"1:"
103-
: "=&r"(tmp), "=&r"(result), "=o"(v->counter)
104-
: "m"(v->counter), "rKs21"(a), "rKs21"(u), "1"(result)
101+
: "=&r"(tmp), "=o"(v->counter)
102+
: "m"(v->counter), "rKs21"(a), "rKs21"(u)
105103
: "cc", "memory");
106-
107-
return result;
108104
}
109105

110106
/*
111-
* atomic_add_unless - add unless the number is a given value
107+
* __atomic_add_unless - add unless the number is a given value
112108
* @v: pointer of type atomic_t
113109
* @a: the amount to add to v...
114110
* @u: ...unless v is equal to u.
115111
*
116-
* If the atomic value v is not equal to u, this function adds a to v,
117-
* and returns non zero. If v is equal to u then it returns zero. This
118-
* is done as an atomic operation.
112+
* Atomically adds @a to @v, so long as it was not @u.
113+
* Returns the old value of @v.
119114
*/
120-
static inline int atomic_add_unless(atomic_t *v, int a, int u)
115+
static inline int __atomic_add_unless(atomic_t *v, int a, int u)
121116
{
122-
int tmp, result;
117+
int tmp, old = atomic_read(v);
123118

124119
if (__builtin_constant_p(a) && (a >= -1048575) && (a <= 1048576))
125-
result = atomic_sub_unless(v, -a, u);
120+
atomic_sub_unless(v, -a, u);
126121
else {
127-
result = 0;
128122
asm volatile(
129-
"/* atomic_add_unless */\n"
123+
"/* __atomic_add_unless */\n"
130124
"1: ssrf 5\n"
131-
" ld.w %0, %3\n"
132-
" cp.w %0, %5\n"
125+
" ld.w %0, %2\n"
126+
" cp.w %0, %4\n"
133127
" breq 1f\n"
134-
" add %0, %4\n"
135-
" stcond %2, %0\n"
128+
" add %0, %3\n"
129+
" stcond %1, %0\n"
136130
" brne 1b\n"
137-
" mov %1, 1\n"
138131
"1:"
139-
: "=&r"(tmp), "=&r"(result), "=o"(v->counter)
140-
: "m"(v->counter), "r"(a), "ir"(u), "1"(result)
132+
: "=&r"(tmp), "=o"(v->counter)
133+
: "m"(v->counter), "r"(a), "ir"(u)
141134
: "cc", "memory");
142135
}
143136

144-
return result;
137+
return old;
145138
}
146139

147140
/*

‎arch/blackfin/include/asm/atomic.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ static inline void atomic_set_mask(int mask, atomic_t *v)
8989
#define atomic_cmpxchg(v, o, n) ((int)cmpxchg(&((v)->counter), (o), (n)))
9090
#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9191

92-
#define atomic_add_unless(v, a, u) \
92+
#define __atomic_add_unless(v, a, u) \
9393
({ \
9494
int c, old; \
9595
c = atomic_read(v); \
9696
while (c != (u) && (old = atomic_cmpxchg((v), c, c + (a))) != c) \
9797
c = old; \
98-
c != (u); \
98+
c; \
9999
})
100100

101101
/*

‎arch/cris/include/asm/atomic.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
138138

139139
#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
140140

141-
static inline int atomic_add_unless(atomic_t *v, int a, int u)
141+
static inline int __atomic_add_unless(atomic_t *v, int a, int u)
142142
{
143143
int ret;
144144
unsigned long flags;
@@ -148,7 +148,7 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
148148
if (ret != u)
149149
v->counter += a;
150150
cris_atomic_restore(v, flags);
151-
return ret != u;
151+
return ret;
152152
}
153153

154154
/* Atomic operations are already serializing */

‎arch/frv/include/asm/atomic.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ extern uint32_t __xchg_32(uint32_t i, volatile void *v);
241241
#define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
242242
#define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
243243

244-
static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
244+
static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
245245
{
246246
int c, old;
247247
c = atomic_read(v);
@@ -253,7 +253,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
253253
break;
254254
c = old;
255255
}
256-
return c != (u);
256+
return c;
257257
}
258258

259259

‎arch/h8300/include/asm/atomic.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
104104

105105
#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
106106

107-
static inline int atomic_add_unless(atomic_t *v, int a, int u)
107+
static inline int __atomic_add_unless(atomic_t *v, int a, int u)
108108
{
109109
int ret;
110110
unsigned long flags;
@@ -114,7 +114,7 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
114114
if (ret != u)
115115
v->counter += a;
116116
local_irq_restore(flags);
117-
return ret != u;
117+
return ret;
118118
}
119119

120120
static __inline__ void atomic_clear_mask(unsigned long mask, unsigned long *v)

‎arch/ia64/include/asm/atomic.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ ia64_atomic64_sub (__s64 i, atomic64_t *v)
9090
(cmpxchg(&((v)->counter), old, new))
9191
#define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9292

93-
static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
93+
static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
9494
{
9595
int c, old;
9696
c = atomic_read(v);
@@ -102,7 +102,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
102102
break;
103103
c = old;
104104
}
105-
return c != (u);
105+
return c;
106106
}
107107

108108

‎arch/m32r/include/asm/atomic.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,15 @@ static __inline__ int atomic_dec_return(atomic_t *v)
239239
#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
240240

241241
/**
242-
* atomic_add_unless - add unless the number is a given value
242+
* __atomic_add_unless - add unless the number is a given value
243243
* @v: pointer of type atomic_t
244244
* @a: the amount to add to v...
245245
* @u: ...unless v is equal to u.
246246
*
247247
* Atomically adds @a to @v, so long as it was not @u.
248-
* Returns non-zero if @v was not @u, and zero otherwise.
248+
* Returns the old value of @v.
249249
*/
250-
static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
250+
static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
251251
{
252252
int c, old;
253253
c = atomic_read(v);
@@ -259,7 +259,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
259259
break;
260260
c = old;
261261
}
262-
return c != (u);
262+
return c;
263263
}
264264

265265

‎arch/m68k/include/asm/atomic.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static inline void atomic_set_mask(unsigned long mask, unsigned long *v)
183183
__asm__ __volatile__("orl %1,%0" : "+m" (*v) : ASM_DI (mask));
184184
}
185185

186-
static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
186+
static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
187187
{
188188
int c, old;
189189
c = atomic_read(v);
@@ -195,7 +195,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
195195
break;
196196
c = old;
197197
}
198-
return c != (u);
198+
return c;
199199
}
200200

201201

0 commit comments

Comments
 (0)