Skip to content

Commit ab0b910

Browse files
mrutland-armingomolnar
authored andcommitted
atomics/arc: Define atomic64_fetch_add_unless()
As a step towards unifying the atomic/atomic64/atomic_long APIs, this patch converts the arch/arc 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: Linus Torvalds <torvalds@linux-foundation.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vineet Gupta <vgupta@synopsys.com> Link: https://lore.kernel.org/lkml/20180621121321.4761-11-mark.rutland@arm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 434b6ac commit ab0b910

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -531,41 +531,40 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
531531
}
532532

533533
/**
534-
* atomic64_add_unless - add unless the number is a given value
534+
* atomic64_fetch_add_unless - add unless the number is a given value
535535
* @v: pointer of type atomic64_t
536536
* @a: the amount to add to v...
537537
* @u: ...unless v is equal to u.
538538
*
539-
* if (v != u) { v += a; ret = 1} else {ret = 0}
540-
* Returns 1 iff @v was not @u (i.e. if add actually happened)
539+
* Atomically adds @a to @v, if it was not @u.
540+
* Returns the old value of @v
541541
*/
542-
static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
542+
static inline long long atomic64_fetch_add_unless(atomic64_t *v, long long a,
543+
long long u)
543544
{
544-
long long val;
545-
int op_done;
545+
long long old, temp;
546546

547547
smp_mb();
548548

549549
__asm__ __volatile__(
550550
"1: llockd %0, [%2] \n"
551-
" mov %1, 1 \n"
552551
" brne %L0, %L4, 2f # continue to add since v != u \n"
553552
" breq.d %H0, %H4, 3f # return since v == u \n"
554-
" mov %1, 0 \n"
555553
"2: \n"
556-
" add.f %L0, %L0, %L3 \n"
557-
" adc %H0, %H0, %H3 \n"
558-
" scondd %0, [%2] \n"
554+
" add.f %L1, %L0, %L3 \n"
555+
" adc %H1, %H0, %H3 \n"
556+
" scondd %1, [%2] \n"
559557
" bnz 1b \n"
560558
"3: \n"
561-
: "=&r"(val), "=&r" (op_done)
559+
: "=&r"(old), "=&r" (temp)
562560
: "r"(&v->counter), "r"(a), "r"(u)
563561
: "cc"); /* memory clobber comes from smp_mb() */
564562

565563
smp_mb();
566564

567-
return op_done;
565+
return old;
568566
}
567+
#define atomic64_fetch_add_unless atomic64_fetch_add_unless
569568

570569
#define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
571570
#define atomic64_inc(v) atomic64_add(1LL, (v))

0 commit comments

Comments
 (0)