From 425c57802f6859976a4940b1d134c2a8d1be8c03 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Sat, 19 Oct 2024 11:23:02 -0400 Subject: atomic: Add compare_and_swap() Signed-off-by: Andrew Opalach --- include/al/atomic.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/al/atomic.h b/include/al/atomic.h index 7d070ab..594413c 100644 --- a/include/al/atomic.h +++ b/include/al/atomic.h @@ -18,6 +18,7 @@ #define al_atomic_store(T) _al_atomic_store_##T #define al_atomic_add(T) _al_atomic_add_##T #define al_atomic_sub(T) _al_atomic_sub_##T +#define al_atomic_compare_and_swap(T) _al_atomic_compare_and_swap_##T // Special case for pointers. #define _al_atomic_load_void(p, order) c89atomic_load_explicit_ptr((volatile void **)p, order) @@ -44,6 +45,10 @@ typedef f32 c89atomic_f32; static inline T al_atomic_sub(T)(atomic(T) *a, T value, int order) \ { \ return c89atomic_fetch_sub_explicit_##S(a, value, order); \ + } \ + static inline T al_atomic_compare_and_swap(T)(atomic(T) *a, T expected, T desired) \ + { \ + return c89atomic_compare_and_swap_##S(a, expected, desired); \ } #if defined C89ATOMIC_64BIT -- cgit v1.2.3-101-g0448