Print this page
remove support for non-ANSI compilation
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/sys/atomic.h
+++ new/usr/src/uts/common/sys/atomic.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 + * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24 + *
23 25 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 26 * Use is subject to license terms.
25 27 */
26 28
27 29 #ifndef _SYS_ATOMIC_H
28 30 #define _SYS_ATOMIC_H
29 31
30 -#pragma ident "%Z%%M% %I% %E% SMI"
31 -
32 32 #include <sys/types.h>
33 33 #include <sys/inttypes.h>
34 34
35 35 #ifdef __cplusplus
36 36 extern "C" {
37 37 #endif
38 38
39 39 #if defined(_KERNEL) && defined(__GNUC__) && defined(_ASM_INLINES) && \
40 40 (defined(__i386) || defined(__amd64))
41 41 #include <asm/atomic.h>
42 42 #endif
43 43
44 -#if defined(_KERNEL) || defined(__STDC__)
45 44 /*
46 45 * Increment target.
47 46 */
48 47 extern void atomic_inc_8(volatile uint8_t *);
49 48 extern void atomic_inc_uchar(volatile uchar_t *);
50 49 extern void atomic_inc_16(volatile uint16_t *);
51 50 extern void atomic_inc_ushort(volatile ushort_t *);
52 51 extern void atomic_inc_32(volatile uint32_t *);
53 52 extern void atomic_inc_uint(volatile uint_t *);
54 53 extern void atomic_inc_ulong(volatile ulong_t *);
55 54 #if defined(_KERNEL) || defined(_INT64_TYPE)
56 55 extern void atomic_inc_64(volatile uint64_t *);
57 -#endif
58 56
59 57 /*
60 58 * Decrement target
61 59 */
62 60 extern void atomic_dec_8(volatile uint8_t *);
63 61 extern void atomic_dec_uchar(volatile uchar_t *);
64 62 extern void atomic_dec_16(volatile uint16_t *);
65 63 extern void atomic_dec_ushort(volatile ushort_t *);
66 64 extern void atomic_dec_32(volatile uint32_t *);
67 65 extern void atomic_dec_uint(volatile uint_t *);
68 66 extern void atomic_dec_ulong(volatile ulong_t *);
69 67 #if defined(_KERNEL) || defined(_INT64_TYPE)
70 68 extern void atomic_dec_64(volatile uint64_t *);
71 69 #endif
72 70
73 71 /*
74 72 * Add delta to target
75 73 */
76 74 extern void atomic_add_8(volatile uint8_t *, int8_t);
77 75 extern void atomic_add_char(volatile uchar_t *, signed char);
78 76 extern void atomic_add_16(volatile uint16_t *, int16_t);
79 77 extern void atomic_add_short(volatile ushort_t *, short);
80 78 extern void atomic_add_32(volatile uint32_t *, int32_t);
81 79 extern void atomic_add_int(volatile uint_t *, int);
82 80 extern void atomic_add_ptr(volatile void *, ssize_t);
83 81 extern void atomic_add_long(volatile ulong_t *, long);
84 82 #if defined(_KERNEL) || defined(_INT64_TYPE)
85 83 extern void atomic_add_64(volatile uint64_t *, int64_t);
86 84 #endif
87 85
88 86 /*
89 87 * logical OR bits with target
90 88 */
91 89 extern void atomic_or_8(volatile uint8_t *, uint8_t);
92 90 extern void atomic_or_uchar(volatile uchar_t *, uchar_t);
93 91 extern void atomic_or_16(volatile uint16_t *, uint16_t);
94 92 extern void atomic_or_ushort(volatile ushort_t *, ushort_t);
95 93 extern void atomic_or_32(volatile uint32_t *, uint32_t);
96 94 extern void atomic_or_uint(volatile uint_t *, uint_t);
97 95 extern void atomic_or_ulong(volatile ulong_t *, ulong_t);
98 96 #if defined(_KERNEL) || defined(_INT64_TYPE)
99 97 extern void atomic_or_64(volatile uint64_t *, uint64_t);
100 98 #endif
101 99
102 100 /*
103 101 * logical AND bits with target
104 102 */
105 103 extern void atomic_and_8(volatile uint8_t *, uint8_t);
106 104 extern void atomic_and_uchar(volatile uchar_t *, uchar_t);
107 105 extern void atomic_and_16(volatile uint16_t *, uint16_t);
108 106 extern void atomic_and_ushort(volatile ushort_t *, ushort_t);
109 107 extern void atomic_and_32(volatile uint32_t *, uint32_t);
110 108 extern void atomic_and_uint(volatile uint_t *, uint_t);
111 109 extern void atomic_and_ulong(volatile ulong_t *, ulong_t);
112 110 #if defined(_KERNEL) || defined(_INT64_TYPE)
113 111 extern void atomic_and_64(volatile uint64_t *, uint64_t);
114 112 #endif
115 113
116 114 /*
117 115 * As above, but return the new value. Note that these _nv() variants are
118 116 * substantially more expensive on some platforms than the no-return-value
119 117 * versions above, so don't use them unless you really need to know the
120 118 * new value *atomically* (e.g. when decrementing a reference count and
121 119 * checking whether it went to zero).
122 120 */
123 121
124 122 /*
125 123 * Increment target and return new value.
126 124 */
127 125 extern uint8_t atomic_inc_8_nv(volatile uint8_t *);
128 126 extern uchar_t atomic_inc_uchar_nv(volatile uchar_t *);
129 127 extern uint16_t atomic_inc_16_nv(volatile uint16_t *);
130 128 extern ushort_t atomic_inc_ushort_nv(volatile ushort_t *);
131 129 extern uint32_t atomic_inc_32_nv(volatile uint32_t *);
132 130 extern uint_t atomic_inc_uint_nv(volatile uint_t *);
133 131 extern ulong_t atomic_inc_ulong_nv(volatile ulong_t *);
134 132 #if defined(_KERNEL) || defined(_INT64_TYPE)
135 133 extern uint64_t atomic_inc_64_nv(volatile uint64_t *);
136 134 #endif
137 135
138 136 /*
139 137 * Decrement target and return new value.
140 138 */
141 139 extern uint8_t atomic_dec_8_nv(volatile uint8_t *);
142 140 extern uchar_t atomic_dec_uchar_nv(volatile uchar_t *);
143 141 extern uint16_t atomic_dec_16_nv(volatile uint16_t *);
144 142 extern ushort_t atomic_dec_ushort_nv(volatile ushort_t *);
145 143 extern uint32_t atomic_dec_32_nv(volatile uint32_t *);
146 144 extern uint_t atomic_dec_uint_nv(volatile uint_t *);
147 145 extern ulong_t atomic_dec_ulong_nv(volatile ulong_t *);
148 146 #if defined(_KERNEL) || defined(_INT64_TYPE)
149 147 extern uint64_t atomic_dec_64_nv(volatile uint64_t *);
150 148 #endif
151 149
152 150 /*
153 151 * Add delta to target
154 152 */
155 153 extern uint8_t atomic_add_8_nv(volatile uint8_t *, int8_t);
156 154 extern uchar_t atomic_add_char_nv(volatile uchar_t *, signed char);
157 155 extern uint16_t atomic_add_16_nv(volatile uint16_t *, int16_t);
158 156 extern ushort_t atomic_add_short_nv(volatile ushort_t *, short);
159 157 extern uint32_t atomic_add_32_nv(volatile uint32_t *, int32_t);
160 158 extern uint_t atomic_add_int_nv(volatile uint_t *, int);
161 159 extern void *atomic_add_ptr_nv(volatile void *, ssize_t);
162 160 extern ulong_t atomic_add_long_nv(volatile ulong_t *, long);
163 161 #if defined(_KERNEL) || defined(_INT64_TYPE)
164 162 extern uint64_t atomic_add_64_nv(volatile uint64_t *, int64_t);
165 163 #endif
166 164
167 165 /*
168 166 * logical OR bits with target and return new value.
169 167 */
170 168 extern uint8_t atomic_or_8_nv(volatile uint8_t *, uint8_t);
171 169 extern uchar_t atomic_or_uchar_nv(volatile uchar_t *, uchar_t);
172 170 extern uint16_t atomic_or_16_nv(volatile uint16_t *, uint16_t);
173 171 extern ushort_t atomic_or_ushort_nv(volatile ushort_t *, ushort_t);
174 172 extern uint32_t atomic_or_32_nv(volatile uint32_t *, uint32_t);
175 173 extern uint_t atomic_or_uint_nv(volatile uint_t *, uint_t);
176 174 extern ulong_t atomic_or_ulong_nv(volatile ulong_t *, ulong_t);
177 175 #if defined(_KERNEL) || defined(_INT64_TYPE)
178 176 extern uint64_t atomic_or_64_nv(volatile uint64_t *, uint64_t);
179 177 #endif
180 178
181 179 /*
182 180 * logical AND bits with target and return new value.
183 181 */
184 182 extern uint8_t atomic_and_8_nv(volatile uint8_t *, uint8_t);
185 183 extern uchar_t atomic_and_uchar_nv(volatile uchar_t *, uchar_t);
186 184 extern uint16_t atomic_and_16_nv(volatile uint16_t *, uint16_t);
187 185 extern ushort_t atomic_and_ushort_nv(volatile ushort_t *, ushort_t);
188 186 extern uint32_t atomic_and_32_nv(volatile uint32_t *, uint32_t);
189 187 extern uint_t atomic_and_uint_nv(volatile uint_t *, uint_t);
190 188 extern ulong_t atomic_and_ulong_nv(volatile ulong_t *, ulong_t);
191 189 #if defined(_KERNEL) || defined(_INT64_TYPE)
192 190 extern uint64_t atomic_and_64_nv(volatile uint64_t *, uint64_t);
193 191 #endif
194 192
195 193 /*
196 194 * If *arg1 == arg2, set *arg1 = arg3; return old value
197 195 */
198 196 extern uint8_t atomic_cas_8(volatile uint8_t *, uint8_t, uint8_t);
199 197 extern uchar_t atomic_cas_uchar(volatile uchar_t *, uchar_t, uchar_t);
200 198 extern uint16_t atomic_cas_16(volatile uint16_t *, uint16_t, uint16_t);
201 199 extern ushort_t atomic_cas_ushort(volatile ushort_t *, ushort_t, ushort_t);
202 200 extern uint32_t atomic_cas_32(volatile uint32_t *, uint32_t, uint32_t);
203 201 extern uint_t atomic_cas_uint(volatile uint_t *, uint_t, uint_t);
204 202 extern void *atomic_cas_ptr(volatile void *, void *, void *);
205 203 extern ulong_t atomic_cas_ulong(volatile ulong_t *, ulong_t, ulong_t);
206 204 #if defined(_KERNEL) || defined(_INT64_TYPE)
207 205 extern uint64_t atomic_cas_64(volatile uint64_t *, uint64_t, uint64_t);
208 206 #endif
209 207
210 208 /*
211 209 * Swap target and return old value
212 210 */
213 211 extern uint8_t atomic_swap_8(volatile uint8_t *, uint8_t);
214 212 extern uchar_t atomic_swap_uchar(volatile uchar_t *, uchar_t);
215 213 extern uint16_t atomic_swap_16(volatile uint16_t *, uint16_t);
216 214 extern ushort_t atomic_swap_ushort(volatile ushort_t *, ushort_t);
217 215 extern uint32_t atomic_swap_32(volatile uint32_t *, uint32_t);
218 216 extern uint_t atomic_swap_uint(volatile uint_t *, uint_t);
219 217 extern void *atomic_swap_ptr(volatile void *, void *);
220 218 extern ulong_t atomic_swap_ulong(volatile ulong_t *, ulong_t);
221 219 #if defined(_KERNEL) || defined(_INT64_TYPE)
222 220 extern uint64_t atomic_swap_64(volatile uint64_t *, uint64_t);
223 221 #endif
224 222
225 223 /*
226 224 * Perform an exclusive atomic bit set/clear on a target.
227 225 * Returns 0 if bit was sucessfully set/cleared, or -1
228 226 * if the bit was already set/cleared.
229 227 */
230 228 extern int atomic_set_long_excl(volatile ulong_t *, uint_t);
231 229 extern int atomic_clear_long_excl(volatile ulong_t *, uint_t);
232 230
233 231 /*
234 232 * Generic memory barrier used during lock entry, placed after the
235 233 * memory operation that acquires the lock to guarantee that the lock
236 234 * protects its data. No stores from after the memory barrier will
237 235 * reach visibility, and no loads from after the barrier will be
238 236 * resolved, before the lock acquisition reaches global visibility.
239 237 */
240 238 extern void membar_enter(void);
241 239
242 240 /*
243 241 * Generic memory barrier used during lock exit, placed before the
244 242 * memory operation that releases the lock to guarantee that the lock
245 243 * protects its data. All loads and stores issued before the barrier
246 244 * will be resolved before the subsequent lock update reaches visibility.
247 245 */
248 246 extern void membar_exit(void);
249 247
250 248 /*
251 249 * Arrange that all stores issued before this point in the code reach
252 250 * global visibility before any stores that follow; useful in producer
253 251 * modules that update a data item, then set a flag that it is available.
254 252 * The memory barrier guarantees that the available flag is not visible
255 253 * earlier than the updated data, i.e. it imposes store ordering.
256 254 */
257 255 extern void membar_producer(void);
258 256
↓ open down ↓ |
191 lines elided |
↑ open up ↑ |
259 257 /*
260 258 * Arrange that all loads issued before this point in the code are
261 259 * completed before any subsequent loads; useful in consumer modules
262 260 * that check to see if data is available and read the data.
263 261 * The memory barrier guarantees that the data is not sampled until
264 262 * after the available flag has been seen, i.e. it imposes load ordering.
265 263 */
266 264 extern void membar_consumer(void);
267 265 #endif
268 266
269 -#if !defined(_KERNEL) && !defined(__STDC__)
270 -extern void atomic_inc_8();
271 -extern void atomic_inc_uchar();
272 -extern void atomic_inc_16();
273 -extern void atomic_inc_ushort();
274 -extern void atomic_inc_32();
275 -extern void atomic_inc_uint();
276 -extern void atomic_inc_ulong();
277 -#if defined(_INT64_TYPE)
278 -extern void atomic_inc_64();
279 -#endif /* defined(_INT64_TYPE) */
280 -extern void atomic_dec_8();
281 -extern void atomic_dec_uchar();
282 -extern void atomic_dec_16();
283 -extern void atomic_dec_ushort();
284 -extern void atomic_dec_32();
285 -extern void atomic_dec_uint();
286 -extern void atomic_dec_ulong();
287 -#if defined(_INT64_TYPE)
288 -extern void atomic_dec_64();
289 -#endif /* defined(_INT64_TYPE) */
290 -extern void atomic_add_8();
291 -extern void atomic_add_char();
292 -extern void atomic_add_16();
293 -extern void atomic_add_short();
294 -extern void atomic_add_32();
295 -extern void atomic_add_int();
296 -extern void atomic_add_ptr();
297 -extern void atomic_add_long();
298 -#if defined(_INT64_TYPE)
299 -extern void atomic_add_64();
300 -#endif /* defined(_INT64_TYPE) */
301 -extern void atomic_or_8();
302 -extern void atomic_or_uchar();
303 -extern void atomic_or_16();
304 -extern void atomic_or_ushort();
305 -extern void atomic_or_32();
306 -extern void atomic_or_uint();
307 -extern void atomic_or_ulong();
308 -#if defined(_INT64_TYPE)
309 -extern void atomic_or_64();
310 -#endif /* defined(_INT64_TYPE) */
311 -extern void atomic_and_8();
312 -extern void atomic_and_uchar();
313 -extern void atomic_and_16();
314 -extern void atomic_and_ushort();
315 -extern void atomic_and_32();
316 -extern void atomic_and_uint();
317 -extern void atomic_and_ulong();
318 -#if defined(_INT64_TYPE)
319 -extern void atomic_and_64();
320 -#endif /* defined(_INT64_TYPE) */
321 -extern uint8_t atomic_inc_8_nv();
322 -extern uchar_t atomic_inc_uchar_nv();
323 -extern uint16_t atomic_inc_16_nv();
324 -extern ushort_t atomic_inc_ushort_nv();
325 -extern uint32_t atomic_inc_32_nv();
326 -extern uint_t atomic_inc_uint_nv();
327 -extern ulong_t atomic_inc_ulong_nv();
328 -#if defined(_INT64_TYPE)
329 -extern uint64_t atomic_inc_64_nv();
330 -#endif /* defined(_INT64_TYPE) */
331 -extern uint8_t atomic_dec_8_nv();
332 -extern uchar_t atomic_dec_uchar_nv();
333 -extern uint16_t atomic_dec_16_nv();
334 -extern ushort_t atomic_dec_ushort_nv();
335 -extern uint32_t atomic_dec_32_nv();
336 -extern uint_t atomic_dec_uint_nv();
337 -extern ulong_t atomic_dec_ulong_nv();
338 -#if defined(_INT64_TYPE)
339 -extern uint64_t atomic_dec_64_nv();
340 -#endif /* defined(_INT64_TYPE) */
341 -extern uint8_t atomic_add_8_nv();
342 -extern uchar_t atomic_add_char_nv();
343 -extern uint16_t atomic_add_16_nv();
344 -extern ushort_t atomic_add_short_nv();
345 -extern uint32_t atomic_add_32_nv();
346 -extern uint_t atomic_add_int_nv();
347 -extern void *atomic_add_ptr_nv();
348 -extern ulong_t atomic_add_long_nv();
349 -#if defined(_INT64_TYPE)
350 -extern uint64_t atomic_add_64_nv();
351 -#endif /* defined(_INT64_TYPE) */
352 -extern uint8_t atomic_or_8_nv();
353 -extern uchar_t atomic_or_uchar_nv();
354 -extern uint16_t atomic_or_16_nv();
355 -extern ushort_t atomic_or_ushort_nv();
356 -extern uint32_t atomic_or_32_nv();
357 -extern uint_t atomic_or_uint_nv();
358 -extern ulong_t atomic_or_ulong_nv();
359 -#if defined(_INT64_TYPE)
360 -extern uint64_t atomic_or_64_nv();
361 -#endif /* defined(_INT64_TYPE) */
362 -extern uint8_t atomic_and_8_nv();
363 -extern uchar_t atomic_and_uchar_nv();
364 -extern uint16_t atomic_and_16_nv();
365 -extern ushort_t atomic_and_ushort_nv();
366 -extern uint32_t atomic_and_32_nv();
367 -extern uint_t atomic_and_uint_nv();
368 -extern ulong_t atomic_and_ulong_nv();
369 -#if defined(_INT64_TYPE)
370 -extern uint64_t atomic_and_64_nv();
371 -#endif /* defined(_INT64_TYPE) */
372 -extern uint8_t atomic_cas_8();
373 -extern uchar_t atomic_cas_uchar();
374 -extern uint16_t atomic_cas_16();
375 -extern ushort_t atomic_cas_ushort();
376 -extern uint32_t atomic_cas_32();
377 -extern uint_t atomic_cas_uint();
378 -extern void *atomic_cas_ptr();
379 -extern ulong_t atomic_cas_ulong();
380 -#if defined(_INT64_TYPE)
381 -extern uint64_t atomic_cas_64();
382 -#endif /* defined(_INT64_TYPE) */
383 -extern uint8_t atomic_swap_8();
384 -extern uchar_t atomic_swap_uchar();
385 -extern uint16_t atomic_swap_16();
386 -extern ushort_t atomic_swap_ushort();
387 -extern uint32_t atomic_swap_32();
388 -extern uint_t atomic_swap_uint();
389 -extern void *atomic_swap_ptr();
390 -extern ulong_t atomic_swap_ulong();
391 -#if defined(_INT64_TYPE)
392 -extern uint64_t atomic_swap_64();
393 -#endif /* defined(_INT64_TYPE) */
394 -
395 -
396 -extern int atomic_set_long_excl();
397 -extern int atomic_clear_long_excl();
398 -
399 -extern void membar_enter();
400 -extern void membar_exit();
401 -extern void membar_producer();
402 -extern void membar_consumer();
403 -
404 -#endif
405 -
406 267 #if defined(_KERNEL)
407 268
408 269 #if defined(_LP64) || defined(_ILP32)
409 270 #define atomic_add_ip atomic_add_long
410 271 #define atomic_add_ip_nv atomic_add_long_nv
411 272 #define casip atomic_cas_ulong
412 273 #endif
413 274
414 275 #if defined(__sparc)
415 276 extern uint8_t ldstub(uint8_t *);
416 277 #endif
417 278
418 279 /*
419 280 * Legacy kernel interfaces; they will go away (eventually).
420 281 */
421 282 extern uint8_t cas8(uint8_t *, uint8_t, uint8_t);
422 283 extern uint32_t cas32(uint32_t *, uint32_t, uint32_t);
423 284 extern uint64_t cas64(uint64_t *, uint64_t, uint64_t);
424 285 extern ulong_t caslong(ulong_t *, ulong_t, ulong_t);
425 286 extern void *casptr(void *, void *, void *);
426 287 extern void atomic_and_long(ulong_t *, ulong_t);
427 288 extern void atomic_or_long(ulong_t *, ulong_t);
428 289 #if defined(__sparc)
429 290 extern uint32_t swapl(uint32_t *, uint32_t);
430 291 #endif
431 292
432 293 #endif /* _KERNEL */
433 294
434 295 #ifdef __cplusplus
435 296 }
436 297 #endif
437 298
438 299 #endif /* _SYS_ATOMIC_H */
↓ open down ↓ |
23 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX