Skip to content

Commit 00b808a

Browse files
mrutland-armingomolnar
authored andcommitted
atomics/generic: Define atomic64_fetch_add_unless()
As a step towards unifying the atomic/atomic64/atomic_long APIs, this patch converts the generic implementation of atomic64_add_unless() into a generic 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: Arnd Bergmann <arnd@arndb.de> Cc: Boqun Feng <boqun.feng@gmail.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/lkml/20180621121321.4761-9-mark.rutland@arm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 0ae1d99 commit 00b808a

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

include/asm-generic/atomic64.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ ATOMIC64_OPS(xor)
5353
extern long long atomic64_dec_if_positive(atomic64_t *v);
5454
extern long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n);
5555
extern long long atomic64_xchg(atomic64_t *v, long long new);
56-
extern bool atomic64_add_unless(atomic64_t *v, long long a, long long u);
56+
extern long long atomic64_fetch_add_unless(atomic64_t *v, long long a, long long u);
57+
#define atomic64_fetch_add_unless atomic64_fetch_add_unless
5758

5859
#define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
5960
#define atomic64_inc(v) atomic64_add(1LL, (v))

lib/atomic64.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,18 @@ long long atomic64_xchg(atomic64_t *v, long long new)
178178
}
179179
EXPORT_SYMBOL(atomic64_xchg);
180180

181-
bool atomic64_add_unless(atomic64_t *v, long long a, long long u)
181+
long long atomic64_fetch_add_unless(atomic64_t *v, long long a, long long u)
182182
{
183183
unsigned long flags;
184184
raw_spinlock_t *lock = lock_addr(v);
185-
bool ret = false;
185+
long long val;
186186

187187
raw_spin_lock_irqsave(lock, flags);
188-
if (v->counter != u) {
188+
val = v->counter;
189+
if (val != u)
189190
v->counter += a;
190-
ret = true;
191-
}
192191
raw_spin_unlock_irqrestore(lock, flags);
193-
return ret;
192+
193+
return val;
194194
}
195-
EXPORT_SYMBOL(atomic64_add_unless);
195+
EXPORT_SYMBOL(atomic64_fetch_add_unless);

0 commit comments

Comments
 (0)