annotate gcc/ginclude/stdatomic.h @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Copyright (C) 2013-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
2
kono
parents:
diff changeset
3 This file is part of GCC.
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 GCC is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
7 the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
8 any later version.
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 GCC is distributed in the hope that it will be useful,
kono
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
13 GNU General Public License for more details.
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
16 permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
17 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19 You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
20 a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
21 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
22 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 /* ISO C11 Standard: 7.17 Atomics <stdatomic.h>. */
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 #ifndef _STDATOMIC_H
kono
parents:
diff changeset
27 #define _STDATOMIC_H
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 typedef enum
kono
parents:
diff changeset
30 {
kono
parents:
diff changeset
31 memory_order_relaxed = __ATOMIC_RELAXED,
kono
parents:
diff changeset
32 memory_order_consume = __ATOMIC_CONSUME,
kono
parents:
diff changeset
33 memory_order_acquire = __ATOMIC_ACQUIRE,
kono
parents:
diff changeset
34 memory_order_release = __ATOMIC_RELEASE,
kono
parents:
diff changeset
35 memory_order_acq_rel = __ATOMIC_ACQ_REL,
kono
parents:
diff changeset
36 memory_order_seq_cst = __ATOMIC_SEQ_CST
kono
parents:
diff changeset
37 } memory_order;
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 typedef _Atomic _Bool atomic_bool;
kono
parents:
diff changeset
41 typedef _Atomic char atomic_char;
kono
parents:
diff changeset
42 typedef _Atomic signed char atomic_schar;
kono
parents:
diff changeset
43 typedef _Atomic unsigned char atomic_uchar;
kono
parents:
diff changeset
44 typedef _Atomic short atomic_short;
kono
parents:
diff changeset
45 typedef _Atomic unsigned short atomic_ushort;
kono
parents:
diff changeset
46 typedef _Atomic int atomic_int;
kono
parents:
diff changeset
47 typedef _Atomic unsigned int atomic_uint;
kono
parents:
diff changeset
48 typedef _Atomic long atomic_long;
kono
parents:
diff changeset
49 typedef _Atomic unsigned long atomic_ulong;
kono
parents:
diff changeset
50 typedef _Atomic long long atomic_llong;
kono
parents:
diff changeset
51 typedef _Atomic unsigned long long atomic_ullong;
kono
parents:
diff changeset
52 typedef _Atomic __CHAR16_TYPE__ atomic_char16_t;
kono
parents:
diff changeset
53 typedef _Atomic __CHAR32_TYPE__ atomic_char32_t;
kono
parents:
diff changeset
54 typedef _Atomic __WCHAR_TYPE__ atomic_wchar_t;
kono
parents:
diff changeset
55 typedef _Atomic __INT_LEAST8_TYPE__ atomic_int_least8_t;
kono
parents:
diff changeset
56 typedef _Atomic __UINT_LEAST8_TYPE__ atomic_uint_least8_t;
kono
parents:
diff changeset
57 typedef _Atomic __INT_LEAST16_TYPE__ atomic_int_least16_t;
kono
parents:
diff changeset
58 typedef _Atomic __UINT_LEAST16_TYPE__ atomic_uint_least16_t;
kono
parents:
diff changeset
59 typedef _Atomic __INT_LEAST32_TYPE__ atomic_int_least32_t;
kono
parents:
diff changeset
60 typedef _Atomic __UINT_LEAST32_TYPE__ atomic_uint_least32_t;
kono
parents:
diff changeset
61 typedef _Atomic __INT_LEAST64_TYPE__ atomic_int_least64_t;
kono
parents:
diff changeset
62 typedef _Atomic __UINT_LEAST64_TYPE__ atomic_uint_least64_t;
kono
parents:
diff changeset
63 typedef _Atomic __INT_FAST8_TYPE__ atomic_int_fast8_t;
kono
parents:
diff changeset
64 typedef _Atomic __UINT_FAST8_TYPE__ atomic_uint_fast8_t;
kono
parents:
diff changeset
65 typedef _Atomic __INT_FAST16_TYPE__ atomic_int_fast16_t;
kono
parents:
diff changeset
66 typedef _Atomic __UINT_FAST16_TYPE__ atomic_uint_fast16_t;
kono
parents:
diff changeset
67 typedef _Atomic __INT_FAST32_TYPE__ atomic_int_fast32_t;
kono
parents:
diff changeset
68 typedef _Atomic __UINT_FAST32_TYPE__ atomic_uint_fast32_t;
kono
parents:
diff changeset
69 typedef _Atomic __INT_FAST64_TYPE__ atomic_int_fast64_t;
kono
parents:
diff changeset
70 typedef _Atomic __UINT_FAST64_TYPE__ atomic_uint_fast64_t;
kono
parents:
diff changeset
71 typedef _Atomic __INTPTR_TYPE__ atomic_intptr_t;
kono
parents:
diff changeset
72 typedef _Atomic __UINTPTR_TYPE__ atomic_uintptr_t;
kono
parents:
diff changeset
73 typedef _Atomic __SIZE_TYPE__ atomic_size_t;
kono
parents:
diff changeset
74 typedef _Atomic __PTRDIFF_TYPE__ atomic_ptrdiff_t;
kono
parents:
diff changeset
75 typedef _Atomic __INTMAX_TYPE__ atomic_intmax_t;
kono
parents:
diff changeset
76 typedef _Atomic __UINTMAX_TYPE__ atomic_uintmax_t;
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 #define ATOMIC_VAR_INIT(VALUE) (VALUE)
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 /* Initialize an atomic object pointed to by PTR with VAL. */
kono
parents:
diff changeset
82 #define atomic_init(PTR, VAL) \
kono
parents:
diff changeset
83 atomic_store_explicit (PTR, VAL, __ATOMIC_RELAXED)
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 #define kill_dependency(Y) \
kono
parents:
diff changeset
86 __extension__ \
kono
parents:
diff changeset
87 ({ \
kono
parents:
diff changeset
88 __auto_type __kill_dependency_tmp = (Y); \
kono
parents:
diff changeset
89 __kill_dependency_tmp; \
kono
parents:
diff changeset
90 })
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 extern void atomic_thread_fence (memory_order);
kono
parents:
diff changeset
93 #define atomic_thread_fence(MO) __atomic_thread_fence (MO)
kono
parents:
diff changeset
94 extern void atomic_signal_fence (memory_order);
kono
parents:
diff changeset
95 #define atomic_signal_fence(MO) __atomic_signal_fence (MO)
kono
parents:
diff changeset
96 #define atomic_is_lock_free(OBJ) __atomic_is_lock_free (sizeof (*(OBJ)), (OBJ))
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 #define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE
kono
parents:
diff changeset
99 #define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE
kono
parents:
diff changeset
100 #define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE
kono
parents:
diff changeset
101 #define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE
kono
parents:
diff changeset
102 #define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE
kono
parents:
diff changeset
103 #define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE
kono
parents:
diff changeset
104 #define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE
kono
parents:
diff changeset
105 #define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE
kono
parents:
diff changeset
106 #define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
kono
parents:
diff changeset
107 #define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 /* Note that these macros require __typeof__ and __auto_type to remove
kono
parents:
diff changeset
111 _Atomic qualifiers (and const qualifiers, if those are valid on
kono
parents:
diff changeset
112 macro operands).
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 Also note that the header file uses the generic form of __atomic
kono
parents:
diff changeset
115 builtins, which requires the address to be taken of the value
kono
parents:
diff changeset
116 parameter, and then we pass that value on. This allows the macros
kono
parents:
diff changeset
117 to work for any type, and the compiler is smart enough to convert
kono
parents:
diff changeset
118 these to lock-free _N variants if possible, and throw away the
kono
parents:
diff changeset
119 temps. */
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 #define atomic_store_explicit(PTR, VAL, MO) \
kono
parents:
diff changeset
122 __extension__ \
kono
parents:
diff changeset
123 ({ \
kono
parents:
diff changeset
124 __auto_type __atomic_store_ptr = (PTR); \
kono
parents:
diff changeset
125 __typeof__ (*__atomic_store_ptr) __atomic_store_tmp = (VAL); \
kono
parents:
diff changeset
126 __atomic_store (__atomic_store_ptr, &__atomic_store_tmp, (MO)); \
kono
parents:
diff changeset
127 })
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 #define atomic_store(PTR, VAL) \
kono
parents:
diff changeset
130 atomic_store_explicit (PTR, VAL, __ATOMIC_SEQ_CST)
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 #define atomic_load_explicit(PTR, MO) \
kono
parents:
diff changeset
134 __extension__ \
kono
parents:
diff changeset
135 ({ \
kono
parents:
diff changeset
136 __auto_type __atomic_load_ptr = (PTR); \
kono
parents:
diff changeset
137 __typeof__ (*__atomic_load_ptr) __atomic_load_tmp; \
kono
parents:
diff changeset
138 __atomic_load (__atomic_load_ptr, &__atomic_load_tmp, (MO)); \
kono
parents:
diff changeset
139 __atomic_load_tmp; \
kono
parents:
diff changeset
140 })
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 #define atomic_load(PTR) atomic_load_explicit (PTR, __ATOMIC_SEQ_CST)
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 #define atomic_exchange_explicit(PTR, VAL, MO) \
kono
parents:
diff changeset
146 __extension__ \
kono
parents:
diff changeset
147 ({ \
kono
parents:
diff changeset
148 __auto_type __atomic_exchange_ptr = (PTR); \
kono
parents:
diff changeset
149 __typeof__ (*__atomic_exchange_ptr) __atomic_exchange_val = (VAL); \
kono
parents:
diff changeset
150 __typeof__ (*__atomic_exchange_ptr) __atomic_exchange_tmp; \
kono
parents:
diff changeset
151 __atomic_exchange (__atomic_exchange_ptr, &__atomic_exchange_val, \
kono
parents:
diff changeset
152 &__atomic_exchange_tmp, (MO)); \
kono
parents:
diff changeset
153 __atomic_exchange_tmp; \
kono
parents:
diff changeset
154 })
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 #define atomic_exchange(PTR, VAL) \
kono
parents:
diff changeset
157 atomic_exchange_explicit (PTR, VAL, __ATOMIC_SEQ_CST)
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 #define atomic_compare_exchange_strong_explicit(PTR, VAL, DES, SUC, FAIL) \
kono
parents:
diff changeset
161 __extension__ \
kono
parents:
diff changeset
162 ({ \
kono
parents:
diff changeset
163 __auto_type __atomic_compare_exchange_ptr = (PTR); \
kono
parents:
diff changeset
164 __typeof__ (*__atomic_compare_exchange_ptr) __atomic_compare_exchange_tmp \
kono
parents:
diff changeset
165 = (DES); \
kono
parents:
diff changeset
166 __atomic_compare_exchange (__atomic_compare_exchange_ptr, (VAL), \
kono
parents:
diff changeset
167 &__atomic_compare_exchange_tmp, 0, \
kono
parents:
diff changeset
168 (SUC), (FAIL)); \
kono
parents:
diff changeset
169 })
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 #define atomic_compare_exchange_strong(PTR, VAL, DES) \
kono
parents:
diff changeset
172 atomic_compare_exchange_strong_explicit (PTR, VAL, DES, __ATOMIC_SEQ_CST, \
kono
parents:
diff changeset
173 __ATOMIC_SEQ_CST)
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 #define atomic_compare_exchange_weak_explicit(PTR, VAL, DES, SUC, FAIL) \
kono
parents:
diff changeset
176 __extension__ \
kono
parents:
diff changeset
177 ({ \
kono
parents:
diff changeset
178 __auto_type __atomic_compare_exchange_ptr = (PTR); \
kono
parents:
diff changeset
179 __typeof__ (*__atomic_compare_exchange_ptr) __atomic_compare_exchange_tmp \
kono
parents:
diff changeset
180 = (DES); \
kono
parents:
diff changeset
181 __atomic_compare_exchange (__atomic_compare_exchange_ptr, (VAL), \
kono
parents:
diff changeset
182 &__atomic_compare_exchange_tmp, 1, \
kono
parents:
diff changeset
183 (SUC), (FAIL)); \
kono
parents:
diff changeset
184 })
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 #define atomic_compare_exchange_weak(PTR, VAL, DES) \
kono
parents:
diff changeset
187 atomic_compare_exchange_weak_explicit (PTR, VAL, DES, __ATOMIC_SEQ_CST, \
kono
parents:
diff changeset
188 __ATOMIC_SEQ_CST)
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 #define atomic_fetch_add(PTR, VAL) __atomic_fetch_add ((PTR), (VAL), \
kono
parents:
diff changeset
193 __ATOMIC_SEQ_CST)
kono
parents:
diff changeset
194 #define atomic_fetch_add_explicit(PTR, VAL, MO) \
kono
parents:
diff changeset
195 __atomic_fetch_add ((PTR), (VAL), (MO))
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197 #define atomic_fetch_sub(PTR, VAL) __atomic_fetch_sub ((PTR), (VAL), \
kono
parents:
diff changeset
198 __ATOMIC_SEQ_CST)
kono
parents:
diff changeset
199 #define atomic_fetch_sub_explicit(PTR, VAL, MO) \
kono
parents:
diff changeset
200 __atomic_fetch_sub ((PTR), (VAL), (MO))
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 #define atomic_fetch_or(PTR, VAL) __atomic_fetch_or ((PTR), (VAL), \
kono
parents:
diff changeset
203 __ATOMIC_SEQ_CST)
kono
parents:
diff changeset
204 #define atomic_fetch_or_explicit(PTR, VAL, MO) \
kono
parents:
diff changeset
205 __atomic_fetch_or ((PTR), (VAL), (MO))
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 #define atomic_fetch_xor(PTR, VAL) __atomic_fetch_xor ((PTR), (VAL), \
kono
parents:
diff changeset
208 __ATOMIC_SEQ_CST)
kono
parents:
diff changeset
209 #define atomic_fetch_xor_explicit(PTR, VAL, MO) \
kono
parents:
diff changeset
210 __atomic_fetch_xor ((PTR), (VAL), (MO))
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 #define atomic_fetch_and(PTR, VAL) __atomic_fetch_and ((PTR), (VAL), \
kono
parents:
diff changeset
213 __ATOMIC_SEQ_CST)
kono
parents:
diff changeset
214 #define atomic_fetch_and_explicit(PTR, VAL, MO) \
kono
parents:
diff changeset
215 __atomic_fetch_and ((PTR), (VAL), (MO))
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 typedef _Atomic struct
kono
parents:
diff changeset
219 {
kono
parents:
diff changeset
220 #if __GCC_ATOMIC_TEST_AND_SET_TRUEVAL == 1
kono
parents:
diff changeset
221 _Bool __val;
kono
parents:
diff changeset
222 #else
kono
parents:
diff changeset
223 unsigned char __val;
kono
parents:
diff changeset
224 #endif
kono
parents:
diff changeset
225 } atomic_flag;
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 #define ATOMIC_FLAG_INIT { 0 }
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229
kono
parents:
diff changeset
230 extern _Bool atomic_flag_test_and_set (volatile atomic_flag *);
kono
parents:
diff changeset
231 #define atomic_flag_test_and_set(PTR) \
kono
parents:
diff changeset
232 __atomic_test_and_set ((PTR), __ATOMIC_SEQ_CST)
kono
parents:
diff changeset
233 extern _Bool atomic_flag_test_and_set_explicit (volatile atomic_flag *,
kono
parents:
diff changeset
234 memory_order);
kono
parents:
diff changeset
235 #define atomic_flag_test_and_set_explicit(PTR, MO) \
kono
parents:
diff changeset
236 __atomic_test_and_set ((PTR), (MO))
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 extern void atomic_flag_clear (volatile atomic_flag *);
kono
parents:
diff changeset
239 #define atomic_flag_clear(PTR) __atomic_clear ((PTR), __ATOMIC_SEQ_CST)
kono
parents:
diff changeset
240 extern void atomic_flag_clear_explicit (volatile atomic_flag *, memory_order);
kono
parents:
diff changeset
241 #define atomic_flag_clear_explicit(PTR, MO) __atomic_clear ((PTR), (MO))
kono
parents:
diff changeset
242
kono
parents:
diff changeset
243 #endif /* _STDATOMIC_H */