5 #ifndef RTE_STDATOMIC_H 6 #define RTE_STDATOMIC_H 14 #ifdef RTE_ENABLE_STDATOMIC 16 #ifdef __STDC_NO_ATOMICS__ 17 #error enable_stdatomic=true but atomics not supported by toolchain 21 #include <stdatomic.h> 26 #define RTE_ATOMIC(type) _Atomic(type) 31 #define __rte_atomic _Atomic 34 typedef memory_order rte_memory_order;
36 #define rte_memory_order_relaxed memory_order_relaxed 37 #ifdef __ATOMIC_RELAXED 38 static_assert(rte_memory_order_relaxed == __ATOMIC_RELAXED,
39 "rte_memory_order_relaxed == __ATOMIC_RELAXED");
42 #define rte_memory_order_consume memory_order_consume 43 #ifdef __ATOMIC_CONSUME 44 static_assert(rte_memory_order_consume == __ATOMIC_CONSUME,
45 "rte_memory_order_consume == __ATOMIC_CONSUME");
48 #define rte_memory_order_acquire memory_order_acquire 49 #ifdef __ATOMIC_ACQUIRE 50 static_assert(rte_memory_order_acquire == __ATOMIC_ACQUIRE,
51 "rte_memory_order_acquire == __ATOMIC_ACQUIRE");
54 #define rte_memory_order_release memory_order_release 55 #ifdef __ATOMIC_RELEASE 56 static_assert(rte_memory_order_release == __ATOMIC_RELEASE,
57 "rte_memory_order_release == __ATOMIC_RELEASE");
60 #define rte_memory_order_acq_rel memory_order_acq_rel 61 #ifdef __ATOMIC_ACQ_REL 62 static_assert(rte_memory_order_acq_rel == __ATOMIC_ACQ_REL,
63 "rte_memory_order_acq_rel == __ATOMIC_ACQ_REL");
66 #define rte_memory_order_seq_cst memory_order_seq_cst 67 #ifdef __ATOMIC_SEQ_CST 68 static_assert(rte_memory_order_seq_cst == __ATOMIC_SEQ_CST,
69 "rte_memory_order_seq_cst == __ATOMIC_SEQ_CST");
72 #define rte_atomic_load_explicit(ptr, memorder) \ 73 atomic_load_explicit(ptr, memorder) 75 #define rte_atomic_store_explicit(ptr, val, memorder) \ 76 atomic_store_explicit(ptr, val, memorder) 78 #define rte_atomic_exchange_explicit(ptr, val, memorder) \ 79 atomic_exchange_explicit(ptr, val, memorder) 81 #define rte_atomic_compare_exchange_strong_explicit(ptr, expected, desired, \ 82 succ_memorder, fail_memorder) \ 83 atomic_compare_exchange_strong_explicit(ptr, expected, desired, \ 84 succ_memorder, fail_memorder) 86 #define rte_atomic_compare_exchange_weak_explicit(ptr, expected, desired, \ 87 succ_memorder, fail_memorder) \ 88 atomic_compare_exchange_weak_explicit(ptr, expected, desired, \ 89 succ_memorder, fail_memorder) 91 #define rte_atomic_fetch_add_explicit(ptr, val, memorder) \ 92 atomic_fetch_add_explicit(ptr, val, memorder) 94 #define rte_atomic_fetch_sub_explicit(ptr, val, memorder) \ 95 atomic_fetch_sub_explicit(ptr, val, memorder) 97 #define rte_atomic_fetch_and_explicit(ptr, val, memorder) \ 98 atomic_fetch_and_explicit(ptr, val, memorder) 100 #define rte_atomic_fetch_xor_explicit(ptr, val, memorder) \ 101 atomic_fetch_xor_explicit(ptr, val, memorder) 103 #define rte_atomic_fetch_or_explicit(ptr, val, memorder) \ 104 atomic_fetch_or_explicit(ptr, val, memorder) 106 #define rte_atomic_fetch_nand_explicit(ptr, val, memorder) \ 107 atomic_fetch_nand_explicit(ptr, val, memorder) 109 #define rte_atomic_flag_test_and_set_explicit(ptr, memorder) \ 110 atomic_flag_test_and_set_explicit(ptr, memorder) 112 #define rte_atomic_flag_clear_explicit(ptr, memorder) \ 113 atomic_flag_clear_explicit(ptr, memorder) 118 #define __rte_atomic_thread_fence(memorder) \ 119 atomic_thread_fence(memorder) 123 #define RTE_ATOMIC(type) type 130 typedef int rte_memory_order;
132 #define rte_memory_order_relaxed __ATOMIC_RELAXED 133 #define rte_memory_order_consume __ATOMIC_CONSUME 134 #define rte_memory_order_acquire __ATOMIC_ACQUIRE 135 #define rte_memory_order_release __ATOMIC_RELEASE 136 #define rte_memory_order_acq_rel __ATOMIC_ACQ_REL 137 #define rte_memory_order_seq_cst __ATOMIC_SEQ_CST 139 #define rte_atomic_load_explicit(ptr, memorder) \ 140 __atomic_load_n(ptr, memorder) 142 #define rte_atomic_store_explicit(ptr, val, memorder) \ 143 __atomic_store_n(ptr, val, memorder) 145 #define rte_atomic_exchange_explicit(ptr, val, memorder) \ 146 __atomic_exchange_n(ptr, val, memorder) 148 #define rte_atomic_compare_exchange_strong_explicit(ptr, expected, desired, \ 149 succ_memorder, fail_memorder) \ 150 __atomic_compare_exchange_n(ptr, expected, desired, 0, \ 151 succ_memorder, fail_memorder) 153 #define rte_atomic_compare_exchange_weak_explicit(ptr, expected, desired, \ 154 succ_memorder, fail_memorder) \ 155 __atomic_compare_exchange_n(ptr, expected, desired, 1, \ 156 succ_memorder, fail_memorder) 158 #define rte_atomic_fetch_add_explicit(ptr, val, memorder) \ 159 __atomic_fetch_add(ptr, val, memorder) 161 #define rte_atomic_fetch_sub_explicit(ptr, val, memorder) \ 162 __atomic_fetch_sub(ptr, val, memorder) 164 #define rte_atomic_fetch_and_explicit(ptr, val, memorder) \ 165 __atomic_fetch_and(ptr, val, memorder) 167 #define rte_atomic_fetch_xor_explicit(ptr, val, memorder) \ 168 __atomic_fetch_xor(ptr, val, memorder) 170 #define rte_atomic_fetch_or_explicit(ptr, val, memorder) \ 171 __atomic_fetch_or(ptr, val, memorder) 173 #define rte_atomic_fetch_nand_explicit(ptr, val, memorder) \ 174 __atomic_fetch_nand(ptr, val, memorder) 176 #define rte_atomic_flag_test_and_set_explicit(ptr, memorder) \ 177 __atomic_test_and_set(ptr, memorder) 179 #define rte_atomic_flag_clear_explicit(ptr, memorder) \ 180 __atomic_clear(ptr, memorder) 185 #define __rte_atomic_thread_fence(memorder) \ 186 __atomic_thread_fence(memorder)