add macros FC_ATOMIC_SET_LARGER/SMALLER
parent
9ca9592326
commit
ce2ee0f482
|
|
@ -36,6 +36,7 @@ extern "C" {
|
||||||
old_value = __sync_add_and_fetch(&var, 0); \
|
old_value = __sync_add_and_fetch(&var, 0); \
|
||||||
} while (new_value != old_value)
|
} while (new_value != old_value)
|
||||||
|
|
||||||
|
|
||||||
#define FC_ATOMIC_SET(var, new_value) \
|
#define FC_ATOMIC_SET(var, new_value) \
|
||||||
do { \
|
do { \
|
||||||
typeof(var) _old_value; \
|
typeof(var) _old_value; \
|
||||||
|
|
@ -48,6 +49,27 @@ extern "C" {
|
||||||
} while (new_value != _old_value); \
|
} while (new_value != _old_value); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
|
#define FC_ATOMIC_SET_BY_CONDITION(var, value, skip_operator) \
|
||||||
|
do { \
|
||||||
|
typeof(var) old; \
|
||||||
|
old = __sync_add_and_fetch(&var, 0); \
|
||||||
|
if (value skip_operator old) { \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
if (__sync_bool_compare_and_swap(&var, old, value)) { \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
} while (1)
|
||||||
|
|
||||||
|
|
||||||
|
#define FC_ATOMIC_SET_LARGER(var, value) \
|
||||||
|
FC_ATOMIC_SET_BY_CONDITION(var, value, <=)
|
||||||
|
|
||||||
|
#define FC_ATOMIC_SET_SMALLER(var, value) \
|
||||||
|
FC_ATOMIC_SET_BY_CONDITION(var, value, >=)
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue