Attachment 'C11stdatomic.patch'
Download 1 * ginclude/stdatomic.h: New header file for C11 atomics.
2
3 Index: ginclude/stdatomic.h
4 ===================================================================
5 *** ginclude/stdatomic.h (revision 0)
6 --- ginclude/stdatomic.h (working copy)
7 ***************
8 *** 0 ****
9 --- 1,217 ----
10 + /* Copyright (C) 2013 Free Software Foundation, Inc.
11 + *
12 + * This file is part of GCC.
13 + *
14 + * GCC is free software; you can redistribute it and/or modify
15 + * it under the terms of the GNU General Public License as published by
16 + * the Free Software Foundation; either version 3, or (at your option)
17 + * any later version.
18 + *
19 + * GCC is distributed in the hope that it will be useful,
20 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 + * GNU General Public License for more details.
23 + *
24 + * Under Section 7 of GPL version 3, you are granted additional
25 + * permissions described in the GCC Runtime Library Exception, version
26 + * 3.1, as published by the Free Software Foundation.
27 + *
28 + * You should have received a copy of the GNU General Public License and
29 + * a copy of the GCC Runtime Library Exception along with this program;
30 + * see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
31 + * <http://www.gnu.org/licenses/>. */
32 +
33 + /*
34 + * * ISO C11 Standard: 7.17 Atomics <stdatomic.h>
35 + * */
36 +
37 + #ifndef _STDATOMIC_H
38 + #define _STDATOMIC_H
39 +
40 +
41 + typedef enum memory_order
42 + {
43 + memory_order_relaxed,
44 + memory_order_consume,
45 + memory_order_acquire,
46 + memory_order_release,
47 + memory_order_acq_rel,
48 + memory_order_seq_cst
49 + } memory_order;
50 +
51 +
52 + typedef _Atomic _Bool atomic_bool;
53 + typedef _Atomic char atomic_char
54 + typedef _Atomic schar atomic_schar
55 + typedef _Atomic uchar atomic_uchar
56 + typedef _Atomic short atomic_short
57 + typedef _Atomic ushort atomic_ushort
58 + typedef _Atomic int atomic_int
59 + typedef _Atomic uint atomic_uint
60 + typedef _Atomic long atomic_long
61 + typedef _Atomic ulong atomic_ulong
62 + typedef _Atomic llong atomic_llong
63 + typedef _Atomic ullong atomic_ullong
64 + typedef _Atomic char16_t atomic_char16_t
65 + typedef _Atomic char32_t atomic_char32_t
66 + typedef _Atomic wchar_t atomic_wchar_t
67 + typedef _Atomic int_least8_t atomic_int_least8_t
68 + typedef _Atomic uint_least8_t atomic_uint_least8_t
69 + typedef _Atomic int_least16_t atomic_int_least16_t
70 + typedef _Atomic uint_least16_t atomic_uint_least16_t
71 + typedef _Atomic int_least32_t atomic_int_least32_t
72 + typedef _Atomic uint_least32_t atomic_uint_least32_t
73 + typedef _Atomic int_least64_t atomic_int_least64_t
74 + typedef _Atomic uint_least64_t atomic_uint_least64_t
75 + typedef _Atomic int_fast8_t atomic_int_fast8_t
76 + typedef _Atomic uint_fast8_t atomic_uint_fast8_t
77 + typedef _Atomic int_fast16_t atomic_int_fast16_t
78 + typedef _Atomic uint_fast16_t atomic_uint_fast16_t
79 + typedef _Atomic int_fast32_t atomic_int_fast32_t
80 + typedef _Atomic uint_fast32_t atomic_uint_fast32_t
81 + typedef _Atomic int_fast64_t atomic_int_fast64_t
82 + typedef _Atomic uint_fast64_t atomic_uint_fast64_t
83 + typedef _Atomic intptr_t atomic_intptr_t
84 + typedef _Atomic uintptr_t atomic_uintptr_t
85 + typedef _Atomic size_t atomic_size_t
86 + typedef _Atomic ptrdiff_t atomic_ptrdiff_t
87 + typedef _Atomic intmax_t atomic_intmax_t
88 + typedef _Atomic uintmax_t atomic_uintmax_t
89 +
90 +
91 + #define ATOMIC_VAR_INIT(VALUE) (VALUE)
92 + #define atomic_init(PTR, VAL) { *(PTR) = (VAL); }
93 +
94 + /* TODO actually kill the dependancy. */
95 + #define kill_dependency(Y) (Y)
96 +
97 + #define atomic_thread_fence __atomic_thread_fence
98 + #define atomic_signal_fence __atomic_signal_fence
99 + #define atomic_is_lock_free(OBJ) __atomic_is_lock_free (sizeof (*(OBJ)), NULL)
100 +
101 + #define ATOMIC_BOOL_LOCK_FREE \
102 + __atomic_is_lock_free (sizeof (atomic_bool), NULL)
103 + #define ATOMIC_CHAR_LOCK_FREE \
104 + __atomic_is_lock_free (sizeof (atomic_char), NULL)
105 + #define ATOMIC_CHAR16_T_LOCK_FREE \
106 + __atomic_is_lock_free (sizeof (atomic_char16_t), NULL)
107 + #define ATOMIC_CHAR32_T_LOCK_FREE \
108 + __atomic_is_lock_free (sizeof (atomic_char32_t), NULL)
109 + #define ATOMIC_WCHAR_T_LOCK_FREE \
110 + __atomic_is_lock_free (sizeof (atomic_wchar_t), NULL)
111 + #define ATOMIC_SHORT_LOCK_FREE \
112 + __atomic_is_lock_free (sizeof (atomic_short), NULL)
113 + #define ATOMIC_INT_LOCK_FREE \
114 + __atomic_is_lock_free (sizeof (atomic_int), NULL)
115 + #define ATOMIC_LONG_LOCK_FREE \
116 + __atomic_is_lock_free (sizeof (atomic_long), NULL)
117 + #define ATOMIC_LLONG_LOCK_FREE \
118 + __atomic_is_lock_free (sizeof (atomic_llong), NULL)
119 + #define ATOMIC_POINTER_LOCK_FREE \
120 + __atomic_is_lock_free (sizeof (_Atomic void *), NULL)
121 +
122 +
123 + /* TODO: Note this required the __typeof__ definition to drops the atomic
124 + qualifier, which means __typeof__ (atomic type) return the underlying
125 + non-atomic type.
126 + I think this makes sense, as most meaningful uses of __typeof__ of an atomic
127 + object would want the non-atomic version to be useful, as it is above.
128 +
129 + If we dont want to change that meaning, we'll need to implement a __typeof__
130 + variant which does this.
131 +
132 + Also note that the header file uses the generic form of __atomic builtins,
133 + which requires the address to be taken of the value parameter, and then
134 + we pass that value on. This allows the macros to work for any type,
135 + and the compiler is smart enough to convert these to lock-free _N
136 + variants if possible, and throw away the temps. */
137 +
138 + #define atomic_store_explicit(PTR, VAL, MO) ({ \
139 + __typeof__ (*(PTR)) __tmp = (VAL); \
140 + __atomic_store ((PTR), &__tmp, (MO)); })
141 +
142 + #define atomic_store(PTR, VAL) \
143 + atomic_store_explicit (PTR, VAL, __ATOMIC_SEQ_CST)
144 +
145 +
146 + #define atomic_load_explicit(PTR, MO) ({ \
147 + __typeof__ (*(PTR)) __tmp; \
148 + __atomic)load ((PTR), &__tmp, __ATOMIC_SEQ_CST); \
149 + __tmp; })
150 +
151 + #define atomic_load(PTR) atomic_load_explicit (PTR, __ATOMIC_SEQ_CST)
152 +
153 +
154 + #define atomic_exchange_explicit(PTR, VAL, MO) ({ \
155 + __typeof__ (*(PTR)) __tmp = (VAL); \
156 + __atomic_exchange_n ((PTR), (VAL), (MO)); \
157 + __tmp; })
158 +
159 + #define atomic_exchange(PTR, VAL) \
160 + atomic_exchange_explicit(PTR, VAL, __ATOMIC_SEQ_CST)
161 +
162 +
163 + #define atomic_compare_exchange_strong_explicit(PTR, VAL, DES, SUC, FAIL) ({ \
164 + __typeof__ (*(PTR)) __tmp = (DES); \
165 + __atomic_compare_exchange_n ((PTR), (VAL), &__tmp, 0, (SUC), (FAIL)); })
166 +
167 + #define atomic_compare_exchange_strong(PTR, VAL, DES) \
168 + atomic_compare_exchange_strong_explicit(PTR, VAL, DES, __ATOMIC_SEQ_CST, \
169 + __ATOMIC_SEQ_CST)
170 +
171 + #define atomic_compare_exchange_weak_explicit(PTR, VAL, DES, SUC, FAIL) ({ \
172 + __typeof__ (*(PTR)) __tmp = (DES); \
173 + __atomic_compare_exchange_n ((PTR), (VAL), &__tmp, 1, (SUC), (FAIL)); })
174 +
175 + #define atomic_compare_exchange_weak(PTR, VAL, DES) \
176 + atomic_compare_exchange_weak_explicit(PTR, VAL, DES, __ATOMIC_SEQ_CST, \
177 + __ATOMIC_SEQ_CST)
178 +
179 +
180 +
181 + #define atomic_fetch_add(PTR, VAL) __atomic_fetch_add ((PTR), (VAL), \
182 + __ATOMIC_SEQ_CST)
183 + #define atomic_fetch_add_explicit(PTR, VAL, MO) \
184 + __atomic_fetch_add ((PTR), (VAL), (MO))
185 +
186 + #define atomic_fetch_sub(PTR, VAL) __atomic_fetch_sub ((PTR), (VAL), \
187 + __ATOMIC_SEQ_CST)
188 + #define atomic_fetch_sub_explicit(PTR, VAL, MO) \
189 + __atomic_fetch_sub ((PTR), (VAL), (MO))
190 +
191 + #define atomic_fetch_or(PTR, VAL) __atomic_fetch_or ((PTR), (VAL), \
192 + __ATOMIC_SEQ_CST)
193 + #define atomic_fetch_or_explicit(PTR, VAL, MO) \
194 + __atomic_fetch_or ((PTR), (VAL), (MO))
195 +
196 + #define atomic_fetch_xor(PTR, VAL) __atomic_fetch_xor ((PTR), (VAL), \
197 + __ATOMIC_SEQ_CST)
198 + #define atomic_fetch_xor_explicit(PTR, VAL, MO) \
199 + __atomic_fetch_xor ((PTR), (VAL), (MO))
200 +
201 + #define atomic_fetch_and(PTR, VAL) __atomic_fetch_and ((PTR), (VAL), \
202 + __ATOMIC_SEQ_CST)
203 + #define atomic_fetch_and_explicit(PTR, VAL, MO) \
204 + __atomic_fetch_and ((PTR), (VAL), (MO))
205 +
206 +
207 + #if __GCC_ATOMIC_TEST_AND_SET_TRUEVAL == 1
208 + typedef bool atomic_flag;
209 + #else
210 + typedef unsigned char atomic_flag;
211 + #endif
212 +
213 + #define ATOMIC_FLAG_INIT 0
214 +
215 +
216 + #define atomic_flag_test_and_set(PTR) \
217 + __atomic_flag_test_and_set ((PTR), __ATOMIC_SEQ_CST)
218 + #define atomic_flag_test_and_set_explicit(PTR, MO) \
219 + __atomic_flag_test_and_set ((PTR), (MO))
220 +
221 + #define atomic_flag_clear(PTR) __atomic_flag_clear ((PTR), __ATOMIC_SEQ_CST)
222 + #define atomic_flag_clear_explicit(PTR, MO) __atomic_flag_clear ((PTR), (MO))
223 +
224 +
225 +
226 + #endif /* _STDATOMIC_H */
227
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.