Atomics: Add atomic_fetch_and_or_uint8() function
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 9 May 2016 09:45:43 +0000 (11:45 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 9 May 2016 09:45:43 +0000 (11:45 +0200)
Hopefully it compiles on all platforms still..

intern/atomic/atomic_ops.h

index 06eb8f21da6cdb62f714240ad065f0d3df52e9ad..dd1bdd2328d0a142d0371ae223e44e3db7e624d6 100644 (file)
@@ -91,6 +91,7 @@ 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_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 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);
 
 ATOMIC_INLINE size_t atomic_add_z(size_t *p, size_t x);
 ATOMIC_INLINE uint8_t atomic_fetch_and_and_uint8(uint8_t *p, uint8_t b);
 
 ATOMIC_INLINE size_t atomic_add_z(size_t *p, size_t x);
@@ -384,6 +385,11 @@ atomic_cas_uint32(uint32_t *v, uint32_t old, uint32_t _new)
 /* 8-bit operations. */
 #ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
 ATOMIC_INLINE uint8_t
 /* 8-bit operations. */
 #ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
 ATOMIC_INLINE uint8_t
+atomic_fetch_and_or_uint8(uint8_t *p, uint8_t b)
+{
+       return __sync_fetch_and_or(p, b);
+}
+ATOMIC_INLINE uint8_t
 atomic_fetch_and_and_uint8(uint8_t *p, uint8_t b)
 {
        return __sync_fetch_and_and(p, b);
 atomic_fetch_and_and_uint8(uint8_t *p, uint8_t b)
 {
        return __sync_fetch_and_and(p, b);
@@ -392,6 +398,15 @@ atomic_fetch_and_and_uint8(uint8_t *p, uint8_t b)
 #include <intrin.h>
 #pragma intrinsic(_InterlockedAnd8)
 ATOMIC_INLINE uint8_t
 #include <intrin.h>
 #pragma intrinsic(_InterlockedAnd8)
 ATOMIC_INLINE uint8_t
+atomic_fetch_and_or_uint8(uint8_t *p, uint8_t b)
+{
+#if (LG_SIZEOF_PTR == 3 || LG_SIZEOF_INT == 3)
+       return InterlockedOr8((char *)p, (char)b);
+#else
+       return _InterlockedOr8((char *)p, (char)b);
+#endif
+}
+ATOMIC_INLINE uint8_t
 atomic_fetch_and_and_uint8(uint8_t *p, uint8_t b)
 {
 #if (LG_SIZEOF_PTR == 3 || LG_SIZEOF_INT == 3)
 atomic_fetch_and_and_uint8(uint8_t *p, uint8_t b)
 {
 #if (LG_SIZEOF_PTR == 3 || LG_SIZEOF_INT == 3)
@@ -402,6 +417,11 @@ atomic_fetch_and_and_uint8(uint8_t *p, uint8_t b)
 }
 #elif defined(JE_FORCE_SYNC_COMPARE_AND_SWAP_1)
 ATOMIC_INLINE uint8_t
 }
 #elif defined(JE_FORCE_SYNC_COMPARE_AND_SWAP_1)
 ATOMIC_INLINE uint8_t
+atomic_fetch_and_or_uint8(uint8_t *p, uint8_t b)
+{
+       return __sync_fetch_and_or(p, b);
+}
+ATOMIC_INLINE uint8_t
 atomic_fetch_and_and_uint8(uint8_t *p, uint8_t b)
 {
        return __sync_fetch_and_and(p, b);
 atomic_fetch_and_and_uint8(uint8_t *p, uint8_t b)
 {
        return __sync_fetch_and_and(p, b);