diff options
author | Uros Bizjak <ubizjak@gmail.com> | 2023-07-31 11:42:23 +0300 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2023-10-04 12:38:11 +0300 |
commit | 5e0eb67974e88dbaded765278a3ffe7af33e3b22 (patch) | |
tree | 25a10882e7c17e57798a4187a40f42b9c5ac5cb5 /arch/x86/include/asm/local.h | |
parent | 8788c6c2feb3600ba1a2f84ac5d258af4a284cea (diff) | |
download | linux-5e0eb67974e88dbaded765278a3ffe7af33e3b22.tar.xz |
locking/local, arch: Rewrite local_add_unless() as a static inline function
Rewrite local_add_unless() as a static inline function with boolean
return value, similar to the arch_atomic_add_unless() arch fallbacks.
The function is currently unused.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20230731084458.28096-1-ubizjak@gmail.com
Diffstat (limited to 'arch/x86/include/asm/local.h')
-rw-r--r-- | arch/x86/include/asm/local.h | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h index 635132a12778..73dba8b94443 100644 --- a/arch/x86/include/asm/local.h +++ b/arch/x86/include/asm/local.h @@ -135,28 +135,27 @@ static inline bool local_try_cmpxchg(local_t *l, long *old, long new) #define local_xchg(l, n) (xchg(&((l)->a.counter), (n))) /** - * local_add_unless - add unless the number is a given value + * local_add_unless - add unless the number is already a given value * @l: pointer of type local_t * @a: the amount to add to l... * @u: ...unless l is equal to u. * - * Atomically adds @a to @l, so long as it was not @u. - * Returns non-zero if @l was not @u, and zero otherwise. + * Atomically adds @a to @l, if @v was not already @u. + * Returns true if the addition was done. */ -#define local_add_unless(l, a, u) \ -({ \ - long c, old; \ - c = local_read((l)); \ - for (;;) { \ - if (unlikely(c == (u))) \ - break; \ - old = local_cmpxchg((l), c, c + (a)); \ - if (likely(old == c)) \ - break; \ - c = old; \ - } \ - c != (u); \ -}) +static __always_inline bool +local_add_unless(local_t *l, long a, long u) +{ + long c = local_read(l); + + do { + if (unlikely(c == u)) + return false; + } while (!local_try_cmpxchg(l, &c, c + a)); + + return true; +} + #define local_inc_not_zero(l) local_add_unless((l), 1, 0) /* On x86_32, these are no better than the atomic variants. |