blob: 9f46e6a858b9e0398a65e7de46f1bee9f30514c2 [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;
69 atomic_int i = ATOMIC_VAR_INIT(123);
70
Elliott Hughes5b5bab52024-10-17 16:38:05 +000071 i = kill_dependency(i);
Elliott Hughes5b5bab52024-10-17 16:38:05 +000072
73#if !defined(atomic_compare_exchange_strong)
74#error atomic_compare_exchange_strong
75#endif
76#if !defined(atomic_compare_exchange_strong_explicit)
77#error atomic_compare_exchange_strong_explicit
78#endif
79#if !defined(atomic_compare_exchange_weak)
80#error atomic_compare_exchange_weak
81#endif
82#if !defined(atomic_compare_exchange_weak_explicit)
83#error atomic_compare_exchange_weak_explicit
84#endif
85#if !defined(atomic_exchange)
86#error atomic_exchange
87#endif
88#if !defined(atomic_exchange_explicit)
89#error atomic_exchange_explicit
90#endif
91#if !defined(atomic_fetch_add)
92#error atomic_fetch_add
93#endif
94#if !defined(atomic_fetch_add_explicit)
95#error atomic_fetch_add_explicit
96#endif
97#if !defined(atomic_fetch_and)
98#error atomic_fetch_and
99#endif
100#if !defined(atomic_fetch_and_explicit)
101#error atomic_fetch_and_explicit
102#endif
103#if !defined(atomic_fetch_or)
104#error atomic_fetch_or
105#endif
106#if !defined(atomic_fetch_or_explicit)
107#error atomic_fetch_or_explicit
108#endif
109#if !defined(atomic_fetch_sub)
110#error atomic_fetch_sub
111#endif
112#if !defined(atomic_fetch_sub_explicit)
113#error atomic_fetch_sub_explicit
114#endif
115#if !defined(atomic_fetch_xor)
116#error atomic_fetch_xor
117#endif
118#if !defined(atomic_fetch_xor_explicit)
119#error atomic_fetch_xor_explicit
120#endif
121#if !defined(atomic_init)
122#error atomic_init
123#endif
124#if !defined(atomic_is_lock_free)
125#error atomic_is_lock_free
126#endif
127#if !defined(atomic_load)
128#error atomic_load
129#endif
130#if !defined(atomic_load_explicit)
131#error atomic_load_explicit
132#endif
133#if !defined(atomic_store)
134#error atomic_store
135#endif
136#if !defined(atomic_store_explicit)
137#error atomic_store_explicit
138#endif
139
140 FUNCTION(atomic_flag_clear, void (*f)(volatile atomic_flag*));
141 FUNCTION(atomic_flag_clear_explicit, void (*f)(volatile atomic_flag*, memory_order));
142 FUNCTION(atomic_flag_test_and_set, bool (*f)(volatile atomic_flag*));
143 FUNCTION(atomic_flag_test_and_set_explicit, bool (*f)(volatile atomic_flag*, memory_order));
144
145 FUNCTION(atomic_signal_fence, void (*f)(memory_order));
146 FUNCTION(atomic_thread_fence, void (*f)(memory_order));
147}