blob: 05be859e927aae34f09a976fc09b743758c0e71f [file] [log] [blame]
Elliott Hughes5b5bab52024-10-17 16:38:05 +00001/*
2 * Copyright (C) 2024 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <stdatomic.h>
30
31#include "header_checks.h"
32
33static void stdatomic_h() {
34 TYPE(atomic_flag);
35 TYPE(atomic_bool);
36 TYPE(atomic_char);
37 TYPE(atomic_schar);
38 TYPE(atomic_uchar);
39 TYPE(atomic_short);
40 TYPE(atomic_ushort);
41 TYPE(atomic_int);
42 TYPE(atomic_uint);
43 TYPE(atomic_long);
44 TYPE(atomic_ulong);
45 TYPE(atomic_llong);
46 TYPE(atomic_ullong);
47#if !defined(__GLIBC__)
48 TYPE(atomic_char16_t);
49 TYPE(atomic_char32_t);
50#endif
51 TYPE(atomic_wchar_t);
52 TYPE(atomic_int_least8_t);
53 TYPE(atomic_uint_least8_t);
54 TYPE(atomic_int_least16_t);
55 TYPE(atomic_uint_least16_t);
56 TYPE(atomic_int_least32_t);
57 TYPE(atomic_uint_least32_t);
58 TYPE(atomic_int_least64_t);
59 TYPE(atomic_uint_least64_t);
60 TYPE(atomic_int_fast8_t);
61 TYPE(atomic_uint_fast8_t);
62 TYPE(atomic_int_fast16_t);
63 TYPE(atomic_uint_fast16_t);
64 TYPE(atomic_int_fast32_t);
65 TYPE(atomic_uint_fast32_t);
66 TYPE(atomic_int_fast64_t);
67 TYPE(atomic_uint_fast64_t);
68 TYPE(atomic_intptr_t);
69 TYPE(atomic_uintptr_t);
70 TYPE(atomic_size_t);
71 TYPE(atomic_ptrdiff_t);
72 TYPE(atomic_intmax_t);
73 TYPE(atomic_uintmax_t);
74
75 memory_order m1 = memory_order_relaxed;
76 memory_order m2 = memory_order_consume;
77 memory_order m3 = memory_order_acquire;
78 memory_order m4 = memory_order_release;
79 memory_order m5 = memory_order_acq_rel;
80 memory_order m6 = memory_order_seq_cst;
81
82 MACRO(ATOMIC_BOOL_LOCK_FREE);
83 MACRO(ATOMIC_CHAR_LOCK_FREE);
84 MACRO(ATOMIC_CHAR16_T_LOCK_FREE);
85 MACRO(ATOMIC_CHAR32_T_LOCK_FREE);
86 MACRO(ATOMIC_WCHAR_T_LOCK_FREE);
87 MACRO(ATOMIC_SHORT_LOCK_FREE);
88 MACRO(ATOMIC_INT_LOCK_FREE);
89 MACRO(ATOMIC_LONG_LOCK_FREE);
90 MACRO(ATOMIC_LLONG_LOCK_FREE);
91 MACRO(ATOMIC_POINTER_LOCK_FREE);
92
93 atomic_flag f = ATOMIC_FLAG_INIT;
94 atomic_int i = ATOMIC_VAR_INIT(123);
95
96 // TODO: remove this #if after the next toolchain update (http://b/374104004).
97#if !defined(__GLIBC__)
98 i = kill_dependency(i);
99#endif
100
101#if !defined(atomic_compare_exchange_strong)
102#error atomic_compare_exchange_strong
103#endif
104#if !defined(atomic_compare_exchange_strong_explicit)
105#error atomic_compare_exchange_strong_explicit
106#endif
107#if !defined(atomic_compare_exchange_weak)
108#error atomic_compare_exchange_weak
109#endif
110#if !defined(atomic_compare_exchange_weak_explicit)
111#error atomic_compare_exchange_weak_explicit
112#endif
113#if !defined(atomic_exchange)
114#error atomic_exchange
115#endif
116#if !defined(atomic_exchange_explicit)
117#error atomic_exchange_explicit
118#endif
119#if !defined(atomic_fetch_add)
120#error atomic_fetch_add
121#endif
122#if !defined(atomic_fetch_add_explicit)
123#error atomic_fetch_add_explicit
124#endif
125#if !defined(atomic_fetch_and)
126#error atomic_fetch_and
127#endif
128#if !defined(atomic_fetch_and_explicit)
129#error atomic_fetch_and_explicit
130#endif
131#if !defined(atomic_fetch_or)
132#error atomic_fetch_or
133#endif
134#if !defined(atomic_fetch_or_explicit)
135#error atomic_fetch_or_explicit
136#endif
137#if !defined(atomic_fetch_sub)
138#error atomic_fetch_sub
139#endif
140#if !defined(atomic_fetch_sub_explicit)
141#error atomic_fetch_sub_explicit
142#endif
143#if !defined(atomic_fetch_xor)
144#error atomic_fetch_xor
145#endif
146#if !defined(atomic_fetch_xor_explicit)
147#error atomic_fetch_xor_explicit
148#endif
149#if !defined(atomic_init)
150#error atomic_init
151#endif
152#if !defined(atomic_is_lock_free)
153#error atomic_is_lock_free
154#endif
155#if !defined(atomic_load)
156#error atomic_load
157#endif
158#if !defined(atomic_load_explicit)
159#error atomic_load_explicit
160#endif
161#if !defined(atomic_store)
162#error atomic_store
163#endif
164#if !defined(atomic_store_explicit)
165#error atomic_store_explicit
166#endif
167
168 FUNCTION(atomic_flag_clear, void (*f)(volatile atomic_flag*));
169 FUNCTION(atomic_flag_clear_explicit, void (*f)(volatile atomic_flag*, memory_order));
170 FUNCTION(atomic_flag_test_and_set, bool (*f)(volatile atomic_flag*));
171 FUNCTION(atomic_flag_test_and_set_explicit, bool (*f)(volatile atomic_flag*, memory_order));
172
173 FUNCTION(atomic_signal_fence, void (*f)(memory_order));
174 FUNCTION(atomic_thread_fence, void (*f)(memory_order));
175}