voron

experimental ARM OS
git clone git://git.2f30.org/voron.git
Log | Files | Refs | LICENSE

commit 9933ed07832f27117618960b54dcd7a46d91cd63
parent a116d94e7f69f4757bc1cb8c178df0af06215645
Author: oblique <psyberbits@gmail.com>
Date:   Wed Oct 31 23:53:12 +0200

add uatomic_add_return()

Diffstat:
include/atomic.h | 23+++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/include/atomic.h b/include/atomic.h @@ -7,8 +7,9 @@ typedef struct { u32 counter; } uatomic_t; -#define UATOMIC_INIT(i) { (i) } -#define uatomic_read(v) (__uatomic_read(v).counter) +#define UATOMIC_INIT(i) { (i) } +#define uatomic_read(v) (__uatomic_read(v).counter) +#define uatomic_add_return(i, v) (__uatomic_add_return(i, v).counter) static inline uatomic_t __uatomic_read(uatomic_t *v) @@ -61,4 +62,22 @@ uatomic_add(u32 i, uatomic_t *v) ); } +static inline uatomic_t +__uatomic_add_return(u32 i, uatomic_t *v) +{ + uatomic_t r; + asm volatile ( + "1: \n\t" + "ldrex %0, [%2] \n\t" + "add %0, %0, %1 \n\t" + "strex v1, %0, [%2] \n\t" + "teq v1, #0 \n\t" + "bne 1b \n\t" + : "=&r" (r) + : "r" (i), "r" (v) + : "v1", "memory" + ); + return r; +} + #endif /* __ATOMIC_H */