Skip to content

Commit 434b6ac

Browse files
mrutland-armingomolnar
authored andcommitted
atomics/alpha: Define atomic64_fetch_add_unless()
As a step towards unifying the atomic/atomic64/atomic_long APIs, this patch converts the arch/alpha implementation of atomic64_add_unless() into an implementation of atomic64_fetch_add_unless(). A wrapper in <linux/atomic.h> will build atomic_add_unless() atop of this, provided it is given a preprocessor definition. No functional change is intended as a result of this patch. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Reviewed-by: Will Deacon <will.deacon@arm.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Boqun Feng <boqun.feng@gmail.com> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Matt Turner <mattst88@gmail.com> Cc: Richard Henderson <rth@twiddle.net> Cc: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/lkml/20180621121321.4761-10-mark.rutland@arm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 00b808a commit 434b6ac

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -238,35 +238,36 @@ static __inline__ int atomic_fetch_add_unless(atomic_t *v, int a, int u)
238238
#define atomic_fetch_add_unless atomic_fetch_add_unless
239239

240240
/**
241-
* atomic64_add_unless - add unless the number is a given value
241+
* atomic64_fetch_add_unless - add unless the number is a given value
242242
* @v: pointer of type atomic64_t
243243
* @a: the amount to add to v...
244244
* @u: ...unless v is equal to u.
245245
*
246246
* Atomically adds @a to @v, so long as it was not @u.
247-
* Returns true iff @v was not @u.
247+
* Returns the old value of @v.
248248
*/
249-
static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
249+
static __inline__ long atomic64_fetch_add_unless(atomic64_t *v, long a, long u)
250250
{
251-
long c, tmp;
251+
long c, new, old;
252252
smp_mb();
253253
__asm__ __volatile__(
254-
"1: ldq_l %[tmp],%[mem]\n"
255-
" cmpeq %[tmp],%[u],%[c]\n"
256-
" addq %[tmp],%[a],%[tmp]\n"
254+
"1: ldq_l %[old],%[mem]\n"
255+
" cmpeq %[old],%[u],%[c]\n"
256+
" addq %[old],%[a],%[new]\n"
257257
" bne %[c],2f\n"
258-
" stq_c %[tmp],%[mem]\n"
259-
" beq %[tmp],3f\n"
258+
" stq_c %[new],%[mem]\n"
259+
" beq %[new],3f\n"
260260
"2:\n"
261261
".subsection 2\n"
262262
"3: br 1b\n"
263263
".previous"
264-
: [tmp] "=&r"(tmp), [c] "=&r"(c)
264+
: [old] "=&r"(old), [new] "=&r"(new), [c] "=&r"(c)
265265
: [mem] "m"(*v), [a] "rI"(a), [u] "rI"(u)
266266
: "memory");
267267
smp_mb();
268-
return !c;
268+
return old;
269269
}
270+
#define atomic64_fetch_add_unless atomic64_fetch_add_unless
270271

271272
/*
272273
* atomic64_dec_if_positive - decrement by 1 if old value positive

0 commit comments

Comments
 (0)