[Mesa-dev] [PATCH 09/14] gallium/auxiliary: add inc and dec alternative with return

David Heidelberger david.heidelberger at ixit.cz
Mon Oct 20 05:37:52 PDT 2014


From: Christoph Bumiller <christoph.bumiller at speed.at>

They're useful for Gallium Nine.

Signed-off-by: David Heidelberger <david.heidelberger at ixit.cz>
---
 src/gallium/auxiliary/util/u_atomic.h | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/src/gallium/auxiliary/util/u_atomic.h b/src/gallium/auxiliary/util/u_atomic.h
index 951a01a..6271736 100644
--- a/src/gallium/auxiliary/util/u_atomic.h
+++ b/src/gallium/auxiliary/util/u_atomic.h
@@ -157,6 +157,12 @@ p_atomic_inc(int32_t *v)
    (void) __sync_add_and_fetch(v, 1);
 }
 
+static INLINE int32_t
+p_atomic_inc_return(int32_t *v)
+{
+   return __sync_add_and_fetch(v, 1);
+}
+
 static INLINE void
 p_atomic_dec(int32_t *v)
 {
@@ -164,6 +170,12 @@ p_atomic_dec(int32_t *v)
 }
 
 static INLINE int32_t
+p_atomic_dec_return(int32_t *v)
+{
+   return __sync_sub_and_fetch(v, 1);
+}
+
+static INLINE int32_t
 p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
 {
    return __sync_val_compare_and_swap(v, old, _new);
@@ -189,6 +201,8 @@ p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
 #define p_atomic_dec_zero(_v) ((boolean) --(*(_v)))
 #define p_atomic_inc(_v) ((void) (*(_v))++)
 #define p_atomic_dec(_v) ((void) (*(_v))--)
+#define p_atomic_inc_return(_v) ((*(_v))++)
+#define p_atomic_dec_return(_v) ((*(_v))--)
 #define p_atomic_cmpxchg(_v, old, _new) (*(_v) == old ? *(_v) = (_new) : *(_v))
 
 #endif
@@ -291,6 +305,12 @@ p_atomic_inc(int32_t *v)
    _InterlockedIncrement((long *)v);
 }
 
+static INLINE int32_t
+p_atomic_inc_return(int32_t *v)
+{
+   return _InterlockedIncrement((long *)v);
+}
+
 static INLINE void
 p_atomic_dec(int32_t *v)
 {
@@ -298,6 +318,12 @@ p_atomic_dec(int32_t *v)
 }
 
 static INLINE int32_t
+p_atomic_dec_return(int32_t *v)
+{
+   return _InterlockedDecrement((long *)v);
+}
+
+static INLINE int32_t
 p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
 {
    return _InterlockedCompareExchange((long *)v, _new, old);
-- 
2.1.2



More information about the mesa-dev mailing list