atomic: add try_cmpxchg() fallback
authorMarek Szyprowski <m.szyprowski@samsung.com>
Tue, 19 Dec 2023 13:42:36 +0000 (14:42 +0100)
committerMarek Szyprowski <m.szyprowski@samsung.com>
Wed, 17 Jan 2024 17:15:54 +0000 (18:15 +0100)
Change-Id: I48abe90191d4f8e0adc2c6d191397b3b04418ff1
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
include/linux/atomic-fallback.h

index a7d240e..80e9b2f 100644 (file)
@@ -2291,5 +2291,16 @@ atomic64_dec_if_positive(atomic64_t *v)
 #define atomic64_cond_read_acquire(v, c) smp_cond_load_acquire(&(v)->counter, (c))
 #define atomic64_cond_read_relaxed(v, c) smp_cond_load_relaxed(&(v)->counter, (c))
 
+#ifndef try_cmpxchg
+#define try_cmpxchg(_ptr, _oldp, _new) \
+({ \
+        typeof(*(_ptr)) *___op = (_oldp), ___o = *___op, ___r; \
+        ___r = cmpxchg((_ptr), ___o, (_new)); \
+        if (unlikely(___r != ___o)) \
+                *___op = ___r; \
+        likely(___r == ___o); \
+})
+#endif /* try_cmpxchg */
+
 #endif /* _LINUX_ATOMIC_FALLBACK_H */
 // 25de4a2804d70f57e994fe3b419148658bb5378a