master
1/* <stdatomic.h> for the Aro C compiler */
2
3#pragma once
4
5#define __STDC_VERSION_STDATOMIC_H__ 202311L
6
7#if __STDC_HOSTED__ && __has_include_next(<stdatomic.h>)
8#include_next <stdatomic.h>
9#else
10
11#include <stddef.h>
12#include <stdint.h>
13
14#define ATOMIC_BOOL_LOCK_FREE __ATOMIC_BOOL_LOCK_FREE
15#define ATOMIC_CHAR_LOCK_FREE __ATOMIC_CHAR_LOCK_FREE
16#define ATOMIC_CHAR16_T_LOCK_FREE __ATOMIC_CHAR16_T_LOCK_FREE
17#define ATOMIC_CHAR32_T_LOCK_FREE __ATOMIC_CHAR32_T_LOCK_FREE
18#define ATOMIC_WCHAR_T_LOCK_FREE __ATOMIC_WCHAR_T_LOCK_FREE
19#define ATOMIC_SHORT_LOCK_FREE __ATOMIC_SHORT_LOCK_FREE
20#define ATOMIC_INT_LOCK_FREE __ATOMIC_INT_LOCK_FREE
21#define ATOMIC_LONG_LOCK_FREE __ATOMIC_LONG_LOCK_FREE
22#define ATOMIC_LLONG_LOCK_FREE __ATOMIC_LLONG_LOCK_FREE
23#define ATOMIC_POINTER_LOCK_FREE __ATOMIC_POINTER_LOCK_FREE
24#if defined(__ATOMIC_CHAR8_T_LOCK_FREE)
25#define ATOMIC_CHAR8_T_LOCK_FREE __ATOMIC_CHAR8_T_LOCK_FREE
26#endif
27
28#if __STDC_VERSION__ < 202311L
29/* ATOMIC_VAR_INIT was removed in C23 */
30#define ATOMIC_VAR_INIT(value) (value)
31#endif
32
33#define atomic_init __c11_atomic_init
34
35typedef enum memory_order {
36 memory_order_relaxed = __ATOMIC_RELAXED,
37 memory_order_consume = __ATOMIC_CONSUME,
38 memory_order_acquire = __ATOMIC_ACQUIRE,
39 memory_order_release = __ATOMIC_RELEASE,
40 memory_order_acq_rel = __ATOMIC_ACQ_REL,
41 memory_order_seq_cst = __ATOMIC_SEQ_CST
42} memory_order;
43
44#define kill_dependency(y) (y)
45
46void atomic_thread_fence(memory_order);
47void atomic_signal_fence(memory_order);
48
49#define atomic_thread_fence(order) __c11_atomic_thread_fence(order)
50#define atomic_signal_fence(order) __c11_atomic_signal_fence(order)
51
52#define atomic_is_lock_free(obj) __c11_atomic_is_lock_free(sizeof(*(obj)))
53
54typedef _Atomic(_Bool) atomic_bool;
55typedef _Atomic(char) atomic_char;
56typedef _Atomic(signed char) atomic_schar;
57typedef _Atomic(unsigned char) atomic_uchar;
58typedef _Atomic(short) atomic_short;
59typedef _Atomic(unsigned short) atomic_ushort;
60typedef _Atomic(int) atomic_int;
61typedef _Atomic(unsigned int) atomic_uint;
62typedef _Atomic(long) atomic_long;
63typedef _Atomic(unsigned long) atomic_ulong;
64typedef _Atomic(long long) atomic_llong;
65typedef _Atomic(unsigned long long) atomic_ullong;
66typedef _Atomic(uint_least16_t) atomic_char16_t;
67typedef _Atomic(uint_least32_t) atomic_char32_t;
68typedef _Atomic(wchar_t) atomic_wchar_t;
69typedef _Atomic(int_least8_t) atomic_int_least8_t;
70typedef _Atomic(uint_least8_t) atomic_uint_least8_t;
71typedef _Atomic(int_least16_t) atomic_int_least16_t;
72typedef _Atomic(uint_least16_t) atomic_uint_least16_t;
73typedef _Atomic(int_least32_t) atomic_int_least32_t;
74typedef _Atomic(uint_least32_t) atomic_uint_least32_t;
75typedef _Atomic(int_least64_t) atomic_int_least64_t;
76typedef _Atomic(uint_least64_t) atomic_uint_least64_t;
77typedef _Atomic(int_fast8_t) atomic_int_fast8_t;
78typedef _Atomic(uint_fast8_t) atomic_uint_fast8_t;
79typedef _Atomic(int_fast16_t) atomic_int_fast16_t;
80typedef _Atomic(uint_fast16_t) atomic_uint_fast16_t;
81typedef _Atomic(int_fast32_t) atomic_int_fast32_t;
82typedef _Atomic(uint_fast32_t) atomic_uint_fast32_t;
83typedef _Atomic(int_fast64_t) atomic_int_fast64_t;
84typedef _Atomic(uint_fast64_t) atomic_uint_fast64_t;
85typedef _Atomic(intptr_t) atomic_intptr_t;
86typedef _Atomic(uintptr_t) atomic_uintptr_t;
87typedef _Atomic(size_t) atomic_size_t;
88typedef _Atomic(ptrdiff_t) atomic_ptrdiff_t;
89typedef _Atomic(intmax_t) atomic_intmax_t;
90typedef _Atomic(uintmax_t) atomic_uintmax_t;
91
92#define atomic_store(object, desired) __c11_atomic_store(object, desired, __ATOMIC_SEQ_CST)
93#define atomic_store_explicit __c11_atomic_store
94
95#define atomic_load(object) __c11_atomic_load(object, __ATOMIC_SEQ_CST)
96#define atomic_load_explicit __c11_atomic_load
97
98#define atomic_exchange(object, desired) __c11_atomic_exchange(object, desired, __ATOMIC_SEQ_CST)
99#define atomic_exchange_explicit __c11_atomic_exchange
100
101#define atomic_compare_exchange_strong(object, expected, desired) __c11_atomic_compare_exchange_strong(object, expected, desired, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
102#define atomic_compare_exchange_strong_explicit __c11_atomic_compare_exchange_strong
103
104#define atomic_compare_exchange_weak(object, expected, desired) __c11_atomic_compare_exchange_weak(object, expected, desired, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
105#define atomic_compare_exchange_weak_explicit __c11_atomic_compare_exchange_weak
106
107#define atomic_fetch_add(object, operand) __c11_atomic_fetch_add(object, operand, __ATOMIC_SEQ_CST)
108#define atomic_fetch_add_explicit __c11_atomic_fetch_add
109
110#define atomic_fetch_sub(object, operand) __c11_atomic_fetch_sub(object, operand, __ATOMIC_SEQ_CST)
111#define atomic_fetch_sub_explicit __c11_atomic_fetch_sub
112
113#define atomic_fetch_or(object, operand) __c11_atomic_fetch_or(object, operand, __ATOMIC_SEQ_CST)
114#define atomic_fetch_or_explicit __c11_atomic_fetch_or
115
116#define atomic_fetch_xor(object, operand) __c11_atomic_fetch_xor(object, operand, __ATOMIC_SEQ_CST)
117#define atomic_fetch_xor_explicit __c11_atomic_fetch_xor
118
119#define atomic_fetch_and(object, operand) __c11_atomic_fetch_and(object, operand, __ATOMIC_SEQ_CST)
120#define atomic_fetch_and_explicit __c11_atomic_fetch_and
121
122typedef struct atomic_flag { atomic_bool _Value; } atomic_flag;
123
124#define ATOMIC_FLAG_INIT { 0 }
125
126_Bool atomic_flag_test_and_set(volatile atomic_flag *);
127_Bool atomic_flag_test_and_set_explicit(volatile atomic_flag *, memory_order);
128void atomic_flag_clear(volatile atomic_flag *);
129void atomic_flag_clear_explicit(volatile atomic_flag *, memory_order);
130
131#define atomic_flag_test_and_set(object) __c11_atomic_exchange(&(object)->_Value, 1, __ATOMIC_SEQ_CST)
132#define atomic_flag_test_and_set_explicit(object, order) __c11_atomic_exchange(&(object)->_Value, 1, order)
133
134#define atomic_flag_clear(object) __c11_atomic_store(&(object)->_Value, 0, __ATOMIC_SEQ_CST)
135#define atomic_flag_clear_explicit(object, order) __c11_atomic_store(&(object)->_Value, 0, order)
136
137
138#endif