11 #ifndef MERCURY_ATOMIC_H
12 #define MERCURY_ATOMIC_H
14 #include "mercury_util_config.h"
19 #elif defined(__APPLE__)
20 #include <libkern/OSAtomic.h>
23 #include <opa_primitives.h>
37 static HG_UTIL_INLINE
void
40 #if defined(_WIN32) || defined(__APPLE__)
43 OPA_store_int(ptr, value);
54 static HG_UTIL_INLINE hg_util_int32_t
59 #if defined(_WIN32) || defined(__APPLE__)
62 ret = OPA_load_int(ptr);
75 static HG_UTIL_INLINE hg_util_int32_t
81 ret = InterlockedIncrement(&ptr->value);
82 #elif defined(__APPLE__)
83 ret = OSAtomicIncrement32(&ptr->value);
85 ret = OPA_fetch_and_incr_int(ptr) + 1;
98 static HG_UTIL_INLINE hg_util_int32_t
104 ret = InterlockedDecrement(&ptr->value);
105 #elif defined(__APPLE__)
106 ret = OSAtomicDecrement32(&ptr->value);
108 ret = OPA_fetch_and_decr_int(ptr) - 1;
124 static HG_UTIL_INLINE hg_util_bool_t
126 hg_util_int32_t swap_value)
131 ret = (compare_value == InterlockedCompareExchange(&ptr->value, swap_value,
133 #elif defined(__APPLE__)
134 ret = OSAtomicCompareAndSwap32(compare_value, swap_value, &ptr->value);
136 ret = (hg_util_bool_t) (compare_value == OPA_cas_int(ptr, compare_value, swap_value));
static HG_UTIL_INLINE hg_util_int32_t hg_atomic_get32(hg_atomic_int32_t *ptr)
Get atomic value (32-bit integer).
OPA_int_t hg_atomic_int32_t
static HG_UTIL_INLINE hg_util_int32_t hg_atomic_decr32(hg_atomic_int32_t *ptr)
Decrement atomic value (32-bit integer).
static HG_UTIL_INLINE void hg_atomic_set32(hg_atomic_int32_t *ptr, hg_util_int32_t value)
Set atomic value (32-bit integer).
static HG_UTIL_INLINE hg_util_bool_t hg_atomic_cas32(hg_atomic_int32_t *ptr, hg_util_int32_t compare_value, hg_util_int32_t swap_value)
Compare and swap values (32-bit integer).
static HG_UTIL_INLINE hg_util_int32_t hg_atomic_incr32(hg_atomic_int32_t *ptr)
Increment atomic value (32-bit integer).