diff mbox

[v5,01/13] atomic: introduce atomic_dec_fetch.

Message ID 1470158864-17651-2-git-send-email-alex.bennee@linaro.org
State New
Headers show

Commit Message

Alex Bennée Aug. 2, 2016, 5:27 p.m. UTC
Useful for counting down.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

Signed-off-by: Sergey Fedorov <sergey.fedorov@linaro.org>

---
 include/qemu/atomic.h | 4 ++++
 1 file changed, 4 insertions(+)

-- 
2.7.4
diff mbox

Patch

diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h
index 7e13fca..560b1af 100644
--- a/include/qemu/atomic.h
+++ b/include/qemu/atomic.h
@@ -160,6 +160,8 @@ 
 #define atomic_fetch_and(ptr, n) __atomic_fetch_and(ptr, n, __ATOMIC_SEQ_CST)
 #define atomic_fetch_or(ptr, n)  __atomic_fetch_or(ptr, n, __ATOMIC_SEQ_CST)
 
+#define atomic_dec_fetch(ptr)  __atomic_sub_fetch(ptr, 1, __ATOMIC_SEQ_CST)
+
 /* And even shorter names that return void.  */
 #define atomic_inc(ptr)    ((void) __atomic_fetch_add(ptr, 1, __ATOMIC_SEQ_CST))
 #define atomic_dec(ptr)    ((void) __atomic_fetch_sub(ptr, 1, __ATOMIC_SEQ_CST))
@@ -355,6 +357,8 @@ 
 #define atomic_fetch_or        __sync_fetch_and_or
 #define atomic_cmpxchg         __sync_val_compare_and_swap
 
+#define atomic_dec_fetch(ptr)  __sync_sub_and_fetch(ptr, 1)
+
 /* And even shorter names that return void.  */
 #define atomic_inc(ptr)        ((void) __sync_fetch_and_add(ptr, 1))
 #define atomic_dec(ptr)        ((void) __sync_fetch_and_add(ptr, -1))