blob: 270faaeb8132e8906eff67c8e5f62c1ee24be9cc [file] [log] [blame]
Elliott Hughes13da6002025-02-03 10:42:13 -08001// Copyright (C) 2024 The Android Open Source Project
2// SPDX-License-Identifier: BSD-2-Clause
Elliott Hughes5b5bab52024-10-17 16:38:05 +00003
4#include <stdatomic.h>
5
6#include "header_checks.h"
7
8static void stdatomic_h() {
9 TYPE(atomic_flag);
10 TYPE(atomic_bool);
11 TYPE(atomic_char);
12 TYPE(atomic_schar);
13 TYPE(atomic_uchar);
14 TYPE(atomic_short);
15 TYPE(atomic_ushort);
16 TYPE(atomic_int);
17 TYPE(atomic_uint);
18 TYPE(atomic_long);
19 TYPE(atomic_ulong);
20 TYPE(atomic_llong);
21 TYPE(atomic_ullong);
22#if !defined(__GLIBC__)
23 TYPE(atomic_char16_t);
24 TYPE(atomic_char32_t);
25#endif
26 TYPE(atomic_wchar_t);
27 TYPE(atomic_int_least8_t);
28 TYPE(atomic_uint_least8_t);
29 TYPE(atomic_int_least16_t);
30 TYPE(atomic_uint_least16_t);
31 TYPE(atomic_int_least32_t);
32 TYPE(atomic_uint_least32_t);
33 TYPE(atomic_int_least64_t);
34 TYPE(atomic_uint_least64_t);
35 TYPE(atomic_int_fast8_t);
36 TYPE(atomic_uint_fast8_t);
37 TYPE(atomic_int_fast16_t);
38 TYPE(atomic_uint_fast16_t);
39 TYPE(atomic_int_fast32_t);
40 TYPE(atomic_uint_fast32_t);
41 TYPE(atomic_int_fast64_t);
42 TYPE(atomic_uint_fast64_t);
43 TYPE(atomic_intptr_t);
44 TYPE(atomic_uintptr_t);
45 TYPE(atomic_size_t);
46 TYPE(atomic_ptrdiff_t);
47 TYPE(atomic_intmax_t);
48 TYPE(atomic_uintmax_t);
49
50 memory_order m1 = memory_order_relaxed;
51 memory_order m2 = memory_order_consume;
52 memory_order m3 = memory_order_acquire;
53 memory_order m4 = memory_order_release;
54 memory_order m5 = memory_order_acq_rel;
55 memory_order m6 = memory_order_seq_cst;
56
57 MACRO(ATOMIC_BOOL_LOCK_FREE);
58 MACRO(ATOMIC_CHAR_LOCK_FREE);
59 MACRO(ATOMIC_CHAR16_T_LOCK_FREE);
60 MACRO(ATOMIC_CHAR32_T_LOCK_FREE);
61 MACRO(ATOMIC_WCHAR_T_LOCK_FREE);
62 MACRO(ATOMIC_SHORT_LOCK_FREE);
63 MACRO(ATOMIC_INT_LOCK_FREE);
64 MACRO(ATOMIC_LONG_LOCK_FREE);
65 MACRO(ATOMIC_LLONG_LOCK_FREE);
66 MACRO(ATOMIC_POINTER_LOCK_FREE);
67
68 atomic_flag f = ATOMIC_FLAG_INIT;
Elliott Hughesa4bc8fd2025-03-05 09:39:41 -080069
70 // ATOMIC_VAR_INIT() has been removed from C23,
71 // but not from POSIX 2024.
Elliott Hughes5b5bab52024-10-17 16:38:05 +000072 atomic_int i = ATOMIC_VAR_INIT(123);
73
Elliott Hughes5b5bab52024-10-17 16:38:05 +000074 i = kill_dependency(i);
Elliott Hughes5b5bab52024-10-17 16:38:05 +000075
76#if !defined(atomic_compare_exchange_strong)
77#error atomic_compare_exchange_strong
78#endif
79#if !defined(atomic_compare_exchange_strong_explicit)
80#error atomic_compare_exchange_strong_explicit
81#endif
82#if !defined(atomic_compare_exchange_weak)
83#error atomic_compare_exchange_weak
84#endif
85#if !defined(atomic_compare_exchange_weak_explicit)
86#error atomic_compare_exchange_weak_explicit
87#endif
88#if !defined(atomic_exchange)
89#error atomic_exchange
90#endif
91#if !defined(atomic_exchange_explicit)
92#error atomic_exchange_explicit
93#endif
94#if !defined(atomic_fetch_add)
95#error atomic_fetch_add
96#endif
97#if !defined(atomic_fetch_add_explicit)
98#error atomic_fetch_add_explicit
99#endif
100#if !defined(atomic_fetch_and)
101#error atomic_fetch_and
102#endif
103#if !defined(atomic_fetch_and_explicit)
104#error atomic_fetch_and_explicit
105#endif
106#if !defined(atomic_fetch_or)
107#error atomic_fetch_or
108#endif
109#if !defined(atomic_fetch_or_explicit)
110#error atomic_fetch_or_explicit
111#endif
112#if !defined(atomic_fetch_sub)
113#error atomic_fetch_sub
114#endif
115#if !defined(atomic_fetch_sub_explicit)
116#error atomic_fetch_sub_explicit
117#endif
118#if !defined(atomic_fetch_xor)
119#error atomic_fetch_xor
120#endif
121#if !defined(atomic_fetch_xor_explicit)
122#error atomic_fetch_xor_explicit
123#endif
124#if !defined(atomic_init)
125#error atomic_init
126#endif
127#if !defined(atomic_is_lock_free)
128#error atomic_is_lock_free
129#endif
130#if !defined(atomic_load)
131#error atomic_load
132#endif
133#if !defined(atomic_load_explicit)
134#error atomic_load_explicit
135#endif
136#if !defined(atomic_store)
137#error atomic_store
138#endif
139#if !defined(atomic_store_explicit)
140#error atomic_store_explicit
141#endif
142
143 FUNCTION(atomic_flag_clear, void (*f)(volatile atomic_flag*));
144 FUNCTION(atomic_flag_clear_explicit, void (*f)(volatile atomic_flag*, memory_order));
145 FUNCTION(atomic_flag_test_and_set, bool (*f)(volatile atomic_flag*));
146 FUNCTION(atomic_flag_test_and_set_explicit, bool (*f)(volatile atomic_flag*, memory_order));
147
148 FUNCTION(atomic_signal_fence, void (*f)(memory_order));
149 FUNCTION(atomic_thread_fence, void (*f)(memory_order));
150}