master
h 28 lines 1.12 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #ifndef NETDATA_ATOMIC_FLAGS_H
4 #define NETDATA_ATOMIC_FLAGS_H
5
6 #define atomic_flags_get(pvalue) \
7 __atomic_load_n((pvalue), __ATOMIC_ACQUIRE)
8
9 #define atomic_flags_check(pvalue, flag) \
10 (__atomic_load_n((pvalue), __ATOMIC_ACQUIRE) & (flag))
11
12 #define atomic_flags_set(pvalue, flag) \
13 __atomic_or_fetch((pvalue), (flag), __ATOMIC_RELEASE)
14
15 #define atomic_flags_clear(pvalue, flag) \
16 __atomic_and_fetch((pvalue), ~(flag), __ATOMIC_RELEASE)
17
18 // returns the old flags (before applying the changes)
19 #define atomic_flags_set_and_clear(pvalue, set, clear) ({ \
20 __typeof__(*pvalue) __old = *(pvalue), __new; \
21 do { \
22 __new = (__old | (set)) & ~(clear); \
23 } while(!__atomic_compare_exchange_n((pvalue), &__old, __new, \
24 false, __ATOMIC_RELEASE, __ATOMIC_RELAXED)); \
25 __old; \
26 })
27
28 #endif //NETDATA_ATOMIC_FLAGS_H