Atomic ops: add 'fetch_and_add_uint32' op.
authorBastien Montagne <montagne29@wanadoo.fr>
Mon, 16 May 2016 13:56:39 +0000 (15:56 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Mon, 16 May 2016 13:56:39 +0000 (15:56 +0200)
Needed for next commit.

intern/atomic/atomic_ops.h
intern/atomic/intern/atomic_ops_msvc.h
intern/atomic/intern/atomic_ops_unix.h

index e4e1bdc1c09af42519772e1a0d2676409019c129..0bc7905aa074f5510b507c4e36b5488de78e0faa 100644 (file)
@@ -86,6 +86,8 @@ ATOMIC_INLINE uint32_t atomic_add_uint32(uint32_t *p, uint32_t x);
 ATOMIC_INLINE uint32_t atomic_sub_uint32(uint32_t *p, uint32_t x);
 ATOMIC_INLINE uint32_t atomic_cas_uint32(uint32_t *v, uint32_t old, uint32_t _new);
 
+ATOMIC_INLINE uint32_t atomic_fetch_and_add_uint32(uint32_t *p, uint32_t x);
+
 ATOMIC_INLINE uint8_t atomic_fetch_and_or_uint8(uint8_t *p, uint8_t b);
 ATOMIC_INLINE uint8_t atomic_fetch_and_and_uint8(uint8_t *p, uint8_t b);
 
index bd9186e7864331847951fb3a16571056487757a8..15ddda246d90c19be19ebfb3a78dc5863a255b93 100644 (file)
@@ -76,6 +76,11 @@ ATOMIC_INLINE uint32_t atomic_cas_uint32(uint32_t *v, uint32_t old, uint32_t _ne
        return InterlockedCompareExchange((long *)v, _new, old);
 }
 
+ATOMIC_INLINE uint32_t atomic_fetch_and_add_uint32(uint32_t *p, uint32_t x)
+{
+       return InterlockedExchangeAdd(p, x);
+}
+
 /******************************************************************************/
 /* 8-bit operations. */
 
index 05d0fbf18567c706d8608324ed231c10c5e57141..bf54750ea0deaac8e52cf9e22e562e6c0cab5c73 100644 (file)
@@ -162,6 +162,16 @@ ATOMIC_INLINE uint32_t atomic_cas_uint32(uint32_t *v, uint32_t old, uint32_t _ne
 #  error "Missing implementation for 32-bit atomic operations"
 #endif
 
+#if (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) || defined(JE_FORCE_SYNC_COMPARE_AND_SWAP_4))
+ATOMIC_INLINE uint32_t atomic_fetch_and_add_uint32(uint32_t *p, uint32_t x)
+{
+       return __sync_fetch_and_add(p, x);
+}
+
+#else
+#  error "Missing implementation for 32-bit atomic operations"
+#endif
+
 /******************************************************************************/
 /* 8-bit operations. */
 #if (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1) || defined(JE_FORCE_SYNC_COMPARE_AND_SWAP_1))