@@ -38,7 +38,7 @@ void util_mutex_destroy(os_mutex_t *mutex);
38
38
int util_mutex_lock (os_mutex_t * mutex );
39
39
int util_mutex_unlock (os_mutex_t * mutex );
40
40
41
- #if defined(_WIN32 )
41
+ #if defined(_WIN32 ) /* Windows part starts here */
42
42
static __inline unsigned char util_lssb_index (long long value ) {
43
43
unsigned long ret ;
44
44
_BitScanForward64 (& ret , value );
@@ -60,7 +60,14 @@ static __inline unsigned char util_mssb_index(long long value) {
60
60
InterlockedExchange64((LONG64 volatile *)object, (LONG64)desired)
61
61
#define util_atomic_increment (object ) \
62
62
InterlockedIncrement64((LONG64 volatile *)object)
63
- #else
63
+ #define util_atomic_decrement (object ) \
64
+ InterlockedDecrement64((LONG64 volatile *)object)
65
+ #define util_atomic_bool_compare_exchange (object , oldval , newval ) \
66
+ (InterlockedCompareExchange64((LONG64 volatile *)object, (LONG64)newval, \
67
+ (LONG64)oldval) == (LONG64)oldval)
68
+
69
+ #else /* NON-Windows part starts here */
70
+
64
71
#define util_lssb_index (x ) ((unsigned char)__builtin_ctzll(x))
65
72
#define util_mssb_index (x ) ((unsigned char)(63 - __builtin_clzll(x)))
66
73
#define util_atomic_load_acquire (object , dest ) \
@@ -69,6 +76,10 @@ static __inline unsigned char util_mssb_index(long long value) {
69
76
__atomic_store_n(object, desired, memory_order_release)
70
77
#define util_atomic_increment (object ) \
71
78
__atomic_add_fetch(object, 1, __ATOMIC_ACQ_REL)
79
+ #define util_atomic_decrement (object ) \
80
+ __atomic_sub_fetch(object, 1, __ATOMIC_ACQ_REL)
81
+ #define util_atomic_bool_compare_exchange (object , oldval , newval ) \
82
+ __sync_bool_compare_and_swap(object, oldval, newval)
72
83
#endif
73
84
74
85
#ifdef __cplusplus
0 commit comments