10#ifdef RTE_ENABLE_STDATOMIC
12#ifdef __STDC_NO_ATOMICS__
13#error enable_stdatomic=true but atomics not supported by toolchain
22#define RTE_ATOMIC(type) _Atomic(type)
27#define __rte_atomic _Atomic
30typedef memory_order rte_memory_order;
32#define rte_memory_order_relaxed memory_order_relaxed
33#ifdef __ATOMIC_RELAXED
34static_assert(rte_memory_order_relaxed == __ATOMIC_RELAXED,
35 "rte_memory_order_relaxed == __ATOMIC_RELAXED");
38#define rte_memory_order_consume memory_order_consume
39#ifdef __ATOMIC_CONSUME
40static_assert(rte_memory_order_consume == __ATOMIC_CONSUME,
41 "rte_memory_order_consume == __ATOMIC_CONSUME");
44#define rte_memory_order_acquire memory_order_acquire
45#ifdef __ATOMIC_ACQUIRE
46static_assert(rte_memory_order_acquire == __ATOMIC_ACQUIRE,
47 "rte_memory_order_acquire == __ATOMIC_ACQUIRE");
50#define rte_memory_order_release memory_order_release
51#ifdef __ATOMIC_RELEASE
52static_assert(rte_memory_order_release == __ATOMIC_RELEASE,
53 "rte_memory_order_release == __ATOMIC_RELEASE");
56#define rte_memory_order_acq_rel memory_order_acq_rel
57#ifdef __ATOMIC_ACQ_REL
58static_assert(rte_memory_order_acq_rel == __ATOMIC_ACQ_REL,
59 "rte_memory_order_acq_rel == __ATOMIC_ACQ_REL");
62#define rte_memory_order_seq_cst memory_order_seq_cst
63#ifdef __ATOMIC_SEQ_CST
64static_assert(rte_memory_order_seq_cst == __ATOMIC_SEQ_CST,
65 "rte_memory_order_seq_cst == __ATOMIC_SEQ_CST");
68#define rte_atomic_load_explicit(ptr, memorder) \
69 atomic_load_explicit(ptr, memorder)
71#define rte_atomic_store_explicit(ptr, val, memorder) \
72 atomic_store_explicit(ptr, val, memorder)
74#define rte_atomic_exchange_explicit(ptr, val, memorder) \
75 atomic_exchange_explicit(ptr, val, memorder)
77#define rte_atomic_compare_exchange_strong_explicit(ptr, expected, desired, \
78 succ_memorder, fail_memorder) \
79 atomic_compare_exchange_strong_explicit(ptr, expected, desired, \
80 succ_memorder, fail_memorder)
82#define rte_atomic_compare_exchange_weak_explicit(ptr, expected, desired, \
83 succ_memorder, fail_memorder) \
84 atomic_compare_exchange_weak_explicit(ptr, expected, desired, \
85 succ_memorder, fail_memorder)
87#define rte_atomic_fetch_add_explicit(ptr, val, memorder) \
88 atomic_fetch_add_explicit(ptr, val, memorder)
90#define rte_atomic_fetch_sub_explicit(ptr, val, memorder) \
91 atomic_fetch_sub_explicit(ptr, val, memorder)
93#define rte_atomic_fetch_and_explicit(ptr, val, memorder) \
94 atomic_fetch_and_explicit(ptr, val, memorder)
96#define rte_atomic_fetch_xor_explicit(ptr, val, memorder) \
97 atomic_fetch_xor_explicit(ptr, val, memorder)
99#define rte_atomic_fetch_or_explicit(ptr, val, memorder) \
100 atomic_fetch_or_explicit(ptr, val, memorder)
102#define rte_atomic_fetch_nand_explicit(ptr, val, memorder) \
103 atomic_fetch_nand_explicit(ptr, val, memorder)
105#define rte_atomic_flag_test_and_set_explicit(ptr, memorder) \
106 atomic_flag_test_and_set_explicit(ptr, memorder)
108#define rte_atomic_flag_clear_explicit(ptr, memorder) \
109 atomic_flag_clear_explicit(ptr, memorder)
114#define __rte_atomic_thread_fence(memorder) \
115 atomic_thread_fence(memorder)
119#define RTE_ATOMIC(type) type
126typedef int rte_memory_order;
128#define rte_memory_order_relaxed __ATOMIC_RELAXED
129#define rte_memory_order_consume __ATOMIC_CONSUME
130#define rte_memory_order_acquire __ATOMIC_ACQUIRE
131#define rte_memory_order_release __ATOMIC_RELEASE
132#define rte_memory_order_acq_rel __ATOMIC_ACQ_REL
133#define rte_memory_order_seq_cst __ATOMIC_SEQ_CST
135#define rte_atomic_load_explicit(ptr, memorder) \
136 __atomic_load_n(ptr, memorder)
138#define rte_atomic_store_explicit(ptr, val, memorder) \
139 __atomic_store_n(ptr, val, memorder)
141#define rte_atomic_exchange_explicit(ptr, val, memorder) \
142 __atomic_exchange_n(ptr, val, memorder)
144#define rte_atomic_compare_exchange_strong_explicit(ptr, expected, desired, \
145 succ_memorder, fail_memorder) \
146 __atomic_compare_exchange_n(ptr, expected, desired, 0, \
147 succ_memorder, fail_memorder)
149#define rte_atomic_compare_exchange_weak_explicit(ptr, expected, desired, \
150 succ_memorder, fail_memorder) \
151 __atomic_compare_exchange_n(ptr, expected, desired, 1, \
152 succ_memorder, fail_memorder)
154#define rte_atomic_fetch_add_explicit(ptr, val, memorder) \
155 __atomic_fetch_add(ptr, val, memorder)
157#define rte_atomic_fetch_sub_explicit(ptr, val, memorder) \
158 __atomic_fetch_sub(ptr, val, memorder)
160#define rte_atomic_fetch_and_explicit(ptr, val, memorder) \
161 __atomic_fetch_and(ptr, val, memorder)
163#define rte_atomic_fetch_xor_explicit(ptr, val, memorder) \
164 __atomic_fetch_xor(ptr, val, memorder)
166#define rte_atomic_fetch_or_explicit(ptr, val, memorder) \
167 __atomic_fetch_or(ptr, val, memorder)
169#define rte_atomic_fetch_nand_explicit(ptr, val, memorder) \
170 __atomic_fetch_nand(ptr, val, memorder)
172#define rte_atomic_flag_test_and_set_explicit(ptr, memorder) \
173 __atomic_test_and_set(ptr, memorder)
175#define rte_atomic_flag_clear_explicit(ptr, memorder) \
176 __atomic_clear(ptr, memorder)
181#define __rte_atomic_thread_fence(memorder) \
182 __atomic_thread_fence(memorder)