#ifndef __FREESTND_C_HDRS_STDATOMIC_H
#define __FREESTND_C_HDRS_STDATOMIC_H

#define memory_order_relaxed __ATOMIC_RELAXED
#define memory_order_consume __ATOMIC_CONSUME
#define memory_order_acquire __ATOMIC_ACQUIRE
#define memory_order_release __ATOMIC_RELEASE
#define memory_order_acq_rel __ATOMIC_ACQ_REL
#define memory_order_seq_cst __ATOMIC_SEQ_CST

#define atomic_load_explicit __atomic_load_n
#define atomic_store_explicit __atomic_store_n

#define atomic_store(p, v) atomic_store_explicit(p, v, memory_order_seq_cst)
#define atomic_load(p) atomic_load_explicit(p, memory_order_seq_cst)

#define atomic_compare_exchange_weak(p, old, new) \
  __atomic_compare_exchange_n(p, old, new, true, memory_order_seq_cst, memory_order_seq_cst)

#define atomic_compare_exchange_strong(p, old, new) \
  __atomic_compare_exchange_n(p, old, new, false, memory_order_seq_cst, memory_order_seq_cst)

#define atomic_test_and_set_explicit(p, memory_order) \
  __atomic_test_and_set(p, memory_order)

#define atomic_clear_flag_explicit(p, memory_order) \
  __atomic_clear(p, memory_order)

#define atomic_inc_explicit(p, memory_order) \
  __atomic_fetch_add(p, 1, memory_order)

#define atomic_inc(p) \
  atomic_inc_explicit(p, memory_order_seq_cst)

#define atomic_dec_explicit(p, memory_order) \
  __atomic_fetch_sub(p, 1, memory_order)

#define atomic_dec(p) \
  atomic_dec_explicit(p, memory_order_seq_cst)

#define atomic_bool _Atomic(bool)
#define atomic_int _Atomic(int)
#define atomic_uint _Atomic(unsigned int)
#define atomic_int8_t _Atomic(int8_t)
#define atomic_uint8_t _Atomic(uint8_t)
#define atomic_int16_t _Atomic(int16_t)
#define atomic_uint16_t _Atomic(uint16_t)
#define atomic_int32_t _Atomic(int32_t)
#define atomic_uint32_t _Atomic(uint32_t)
#define atomic_int64_t _Atomic(int64_t)
#define atomic_uint64_t _Atomic(uint64_t)

#endif
