Skip to content

Commit 8fc4fdd

Browse files
ubizjakingomolnar
authored andcommitted
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>
1 parent e6ce9d7 commit 8fc4fdd

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

include/asm-generic/local.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ typedef struct
4242
#define local_inc_return(l) atomic_long_inc_return(&(l)->a)
4343

4444
#define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
45+
#define local_try_cmpxchg(l, po, n) atomic_long_try_cmpxchg((&(l)->a), (po), (n))
4546
#define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
4647
#define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
4748
#define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)

include/asm-generic/local64.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,16 @@ typedef struct {
4242
#define local64_sub_return(i, l) local_sub_return((i), (&(l)->a))
4343
#define local64_inc_return(l) local_inc_return(&(l)->a)
4444

45-
#define local64_cmpxchg(l, o, n) local_cmpxchg((&(l)->a), (o), (n))
45+
static inline s64 local64_cmpxchg(local64_t *l, s64 old, s64 new)
46+
{
47+
return local_cmpxchg(&l->a, old, new);
48+
}
49+
50+
static inline bool local64_try_cmpxchg(local64_t *l, s64 *old, s64 new)
51+
{
52+
return local_try_cmpxchg(&l->a, (long *)old, new);
53+
}
54+
4655
#define local64_xchg(l, n) local_xchg((&(l)->a), (n))
4756
#define local64_add_unless(l, _a, u) local_add_unless((&(l)->a), (_a), (u))
4857
#define local64_inc_not_zero(l) local_inc_not_zero(&(l)->a)
@@ -81,6 +90,7 @@ typedef struct {
8190
#define local64_inc_return(l) atomic64_inc_return(&(l)->a)
8291

8392
#define local64_cmpxchg(l, o, n) atomic64_cmpxchg((&(l)->a), (o), (n))
93+
#define local64_try_cmpxchg(l, po, n) atomic64_try_cmpxchg((&(l)->a), (po), (n))
8494
#define local64_xchg(l, n) atomic64_xchg((&(l)->a), (n))
8595
#define local64_add_unless(l, _a, u) atomic64_add_unless((&(l)->a), (_a), (u))
8696
#define local64_inc_not_zero(l) atomic64_inc_not_zero(&(l)->a)

0 commit comments

Comments
 (0)