[LTP] [PATCH v2 1/2] tst_atomic: Add tst_atomic_return_add()
Petr Vorel
pvorel@suse.cz
Thu Apr 2 22:55:33 CEST 2026
Combine atomic loading and adding.
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
https://lore.kernel.org/ltp/acqLzcXEo0uU0aSD@yuki.lan/
include/tst_atomic.h | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/include/tst_atomic.h b/include/tst_atomic.h
index 9d255bc448..196399db31 100644
--- a/include/tst_atomic.h
+++ b/include/tst_atomic.h
@@ -30,6 +30,11 @@ static inline void tst_atomic_store(int32_t i, tst_atomic_t *v)
__atomic_store_n(v, i, __ATOMIC_SEQ_CST);
}
+static inline int tst_atomic_return_add(int32_t i, tst_atomic_t *v)
+{
+ return __atomic_fetch_add(v, i, __ATOMIC_SEQ_CST);
+}
+
#elif HAVE_SYNC_ADD_AND_FETCH == 1
/* Use __sync built-ins (GCC >= 4.1), with explicit memory barriers. */
@@ -56,6 +61,11 @@ static inline void tst_atomic_store(int32_t i, tst_atomic_t *v)
__sync_synchronize();
}
+static inline int tst_atomic_return_add(int32_t i, tst_atomic_t *v)
+{
+ return __sync_fetch_and_add(v, i);
+}
+
#else
# error "Your compiler does not support atomic operations (__atomic or __sync)"
#endif
--
2.53.0
More information about the ltp
mailing list