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