36 #ifndef _ENV_ATOMIC_H_
37 #define _ENV_ATOMIC_H_
39 #pragma GCC visibility push(default)
46 } ENV_ALIGNED(
sizeof(uint32_t));
50 } ENV_ALIGNED(
sizeof(uint64_t));
61 __atomic_store_n(&atom->
a32, 0, __ATOMIC_SEQ_CST);
67 __atomic_store_n(&atom->
a32, new_val, __ATOMIC_SEQ_CST);
70 static inline uint32_t
73 return __atomic_load_n(&atom->
a32, __ATOMIC_SEQ_CST);
79 (void)__atomic_fetch_sub(&atom->
a32, 1, __ATOMIC_SEQ_CST);
85 (void)__atomic_fetch_add(&atom->
a32, 1, __ATOMIC_SEQ_CST);
91 (void)__atomic_fetch_add(&atom->
a32, add_val, __ATOMIC_SEQ_CST);
97 (void)__atomic_fetch_sub(&atom->
a32, sub_val, __ATOMIC_SEQ_CST);
100 static inline uint32_t
103 return __atomic_add_fetch(&atom->
a32, add_val, __ATOMIC_SEQ_CST);
106 static inline uint32_t
109 return __atomic_fetch_add(&atom->
a32, add_val, __ATOMIC_SEQ_CST);
112 static inline uint32_t
115 return __atomic_sub_fetch(&atom->
a32, sub_val, __ATOMIC_SEQ_CST);
118 static inline uint32_t
121 return __atomic_fetch_sub(&atom->
a32, sub_val, __ATOMIC_SEQ_CST);
125 env_atomic32_cmpset(
env_atomic32_t *atom, uint32_t expected, uint32_t desired)
127 return __atomic_compare_exchange_n(&atom->
a32, &expected, desired,
128 0 , __ATOMIC_SEQ_CST,
132 static inline uint32_t
135 return __atomic_exchange_n(&atom->
a32, new_val, __ATOMIC_SEQ_CST);
146 old_val = env_atomic32_get(atom);
147 new_val = old_val | bit_mask;
148 ret = env_atomic32_cmpset(atom, old_val, new_val);
160 old_val = env_atomic32_get(atom);
161 new_val = old_val & (~bit_mask);
162 ret = env_atomic32_cmpset(atom, old_val, new_val);
169 return __builtin_popcount(env_atomic32_get(atom));
178 __atomic_store_n(&atom->
a64, 0, __ATOMIC_SEQ_CST);
184 __atomic_store_n(&atom->
a64, new_val, __ATOMIC_SEQ_CST);
187 static inline uint64_t
190 return __atomic_load_n(&atom->
a64, __ATOMIC_SEQ_CST);
196 (void)__atomic_fetch_sub(&atom->
a64, 1, __ATOMIC_SEQ_CST);
202 (void)__atomic_fetch_add(&atom->
a64, 1, __ATOMIC_SEQ_CST);
208 (void)__atomic_fetch_add(&atom->
a64, add_val, __ATOMIC_SEQ_CST);
214 (void)__atomic_fetch_sub(&atom->
a64, sub_val, __ATOMIC_SEQ_CST);
217 static inline uint64_t
220 return __atomic_add_fetch(&atom->
a64, add_val, __ATOMIC_SEQ_CST);
223 static inline uint64_t
226 return __atomic_fetch_add(&atom->
a64, add_val, __ATOMIC_SEQ_CST);
229 static inline uint64_t
232 return __atomic_sub_fetch(&atom->
a64, sub_val, __ATOMIC_SEQ_CST);
235 static inline uint64_t
238 return __atomic_fetch_sub(&atom->
a64, sub_val, __ATOMIC_SEQ_CST);
242 env_atomic64_cmpset(
env_atomic64_t *atom, uint64_t expected, uint64_t desired)
244 return __atomic_compare_exchange_n(&atom->
a64, &expected, desired,
245 0 , __ATOMIC_SEQ_CST,
249 static inline uint64_t
252 return __atomic_exchange_n(&atom->
a64, new_val, __ATOMIC_SEQ_CST);
263 old_val = env_atomic64_get(atom);
264 new_val = old_val | bit_mask;
265 ret = env_atomic64_cmpset(atom, old_val, new_val);
277 old_val = env_atomic64_get(atom);
278 new_val = old_val & (~bit_mask);
279 ret = env_atomic64_cmpset(atom, old_val, new_val);
286 return __builtin_popcountll(env_atomic64_get(atom));
289 #pragma GCC visibility pop