diff options
author | Uros Bizjak <ubizjak@gmail.com> | 2023-04-05 16:17:07 +0200 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2023-04-29 09:09:09 +0200 |
commit | 8fc4fddaf9a184eea7da21290236a1764e608a01 (patch) | |
tree | 6443e9faadcb782b6cd239f34d74c4323d606567 /include/asm-generic/local64.h | |
parent | locking/atomic: Add generic try_cmpxchg{,64}_local() support (diff) | |
download | linux-8fc4fddaf9a184eea7da21290236a1764e608a01.tar.xz linux-8fc4fddaf9a184eea7da21290236a1764e608a01.zip |
locking/generic: Wire up local{,64}_try_cmpxchg()
Implement generic support for local{,64}_try_cmpxchg().
Redirect to the atomic_ family of functions when the target
does not provide its own local.h definitions.
For 64-bit targets, implement local64_try_cmpxchg and
local64_cmpxchg using typed C wrappers that call local_
family of functions and provide additional checking
of their input arguments.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Link: https://lore.kernel.org/r/20230405141710.3551-3-ubizjak@gmail.com
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/asm-generic/local64.h')
-rw-r--r-- | include/asm-generic/local64.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/include/asm-generic/local64.h b/include/asm-generic/local64.h index 765be0b7d883..14963a7a6253 100644 --- a/include/asm-generic/local64.h +++ b/include/asm-generic/local64.h @@ -42,7 +42,16 @@ typedef struct { #define local64_sub_return(i, l) local_sub_return((i), (&(l)->a)) #define local64_inc_return(l) local_inc_return(&(l)->a) -#define local64_cmpxchg(l, o, n) local_cmpxchg((&(l)->a), (o), (n)) +static inline s64 local64_cmpxchg(local64_t *l, s64 old, s64 new) +{ + return local_cmpxchg(&l->a, old, new); +} + +static inline bool local64_try_cmpxchg(local64_t *l, s64 *old, s64 new) +{ + return local_try_cmpxchg(&l->a, (long *)old, new); +} + #define local64_xchg(l, n) local_xchg((&(l)->a), (n)) #define local64_add_unless(l, _a, u) local_add_unless((&(l)->a), (_a), (u)) #define local64_inc_not_zero(l) local_inc_not_zero(&(l)->a) @@ -81,6 +90,7 @@ typedef struct { #define local64_inc_return(l) atomic64_inc_return(&(l)->a) #define local64_cmpxchg(l, o, n) atomic64_cmpxchg((&(l)->a), (o), (n)) +#define local64_try_cmpxchg(l, po, n) atomic64_try_cmpxchg((&(l)->a), (po), (n)) #define local64_xchg(l, n) atomic64_xchg((&(l)->a), (n)) #define local64_add_unless(l, _a, u) atomic64_add_unless((&(l)->a), (_a), (u)) #define local64_inc_not_zero(l) atomic64_inc_not_zero(&(l)->a) |