[PATCH 1/5] asm-generic: atomic: implement atomic_inc/dec_return stubs

Ahmad Fatoum a.fatoum at pengutronix.de
Fri Apr 21 03:06:38 PDT 2023


We don't have forced preemption in barebox, so we can implement these
functions with normal increment/decrement operators.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 include/asm-generic/atomic.h | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
index 6e63b8e8e7b9..45fc5da57594 100644
--- a/include/asm-generic/atomic.h
+++ b/include/asm-generic/atomic.h
@@ -77,16 +77,19 @@ static inline void atomic_sub(int i, volatile atomic_t *v)
 	v->counter -= i;
 }
 
-static inline void atomic_inc(volatile atomic_t *v)
+static inline int atomic_inc_return(volatile atomic_t *v)
 {
-	v->counter += 1;
+	return ++v->counter;
 }
 
-static inline void atomic_dec(volatile atomic_t *v)
+static inline int atomic_dec_return(volatile atomic_t *v)
 {
-	v->counter -= 1;
+	return --v->counter;
 }
 
+#define atomic_inc(v) ((void)atomic_inc_return(v))
+#define atomic_dec(v) ((void)atomic_dec_return(v))
+
 static inline int atomic_dec_and_test(volatile atomic_t *v)
 {
 	int val;
-- 
2.39.2




More information about the barebox mailing list