v / thirdparty / libatomic_ops / atomic_ops / sysdeps / gcc / generic-small.h
632 lines · 544 sloc · 23.21 KB · 90d9b200f999f611a27b604e7b26c76843fb8b7b
Raw
1/*
2 * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
3 * Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
4 * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P.
5 *
6 *
7 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
9 *
10 * Permission is hereby granted to use or copy this program
11 * for any purpose, provided the above notices are retained on all copies.
12 * Permission to modify the code and to distribute modified code is granted,
13 * provided the above notices are retained, and a notice that the code was
14 * modified is included with the above copyright notice.
15 *
16 */
17
18#if !defined(AO_GCC_HAVE_char_SYNC_CAS) || !defined(AO_PREFER_GENERALIZED)
19
20AO_INLINE unsigned/**/char
21AO_char_load(const volatile unsigned/**/char *addr)
22{
23 return __atomic_load_n(addr, __ATOMIC_RELAXED);
24}
25#define AO_HAVE_char_load
26
27AO_INLINE unsigned/**/char
28AO_char_load_acquire(const volatile unsigned/**/char *addr)
29{
30 return __atomic_load_n(addr, __ATOMIC_ACQUIRE);
31}
32#define AO_HAVE_char_load_acquire
33
34/* char_load_read is defined using load and nop_read. */
35/* TODO: Map it to ACQUIRE. We should be strengthening the read and */
36/* write stuff to the more general acquire/release versions. It almost */
37/* never makes a difference and is much less error-prone. */
38
39/* char_load_full is generalized using load and nop_full. */
40/* TODO: Map it to SEQ_CST and clarify the documentation. */
41
42/* TODO: Map load_dd_acquire_read to ACQUIRE. Ideally it should be */
43/* mapped to CONSUME, but the latter is currently broken. */
44
45/* char_store_full definition is omitted similar to load_full reason. */
46
47/* TODO: Map store_write to RELEASE. */
48
49#ifndef AO_SKIPATOMIC_char_store
50 AO_INLINE void
51 AO_char_store(volatile unsigned/**/char *addr, unsigned/**/char value)
52 {
53 __atomic_store_n(addr, value, __ATOMIC_RELAXED);
54 }
55# define AO_HAVE_char_store
56#endif
57
58#ifndef AO_SKIPATOMIC_char_store_release
59 AO_INLINE void
60 AO_char_store_release(volatile unsigned/**/char *addr, unsigned/**/char value)
61 {
62 __atomic_store_n(addr, value, __ATOMIC_RELEASE);
63 }
64# define AO_HAVE_char_store_release
65#endif
66
67#endif /* !AO_GCC_HAVE_char_SYNC_CAS || !AO_PREFER_GENERALIZED */
68
69#ifdef AO_GCC_HAVE_char_SYNC_CAS
70
71 AO_INLINE unsigned/**/char
72 AO_char_fetch_compare_and_swap(volatile unsigned/**/char *addr,
73 unsigned/**/char old_val, unsigned/**/char new_val)
74 {
75 (void)__atomic_compare_exchange_n(addr,
76 &old_val /* p_expected */,
77 new_val /* desired */,
78 0 /* is_weak: false */,
79 __ATOMIC_RELAXED /* success */,
80 __ATOMIC_RELAXED /* failure */);
81 return old_val;
82 }
83# define AO_HAVE_char_fetch_compare_and_swap
84
85 AO_INLINE unsigned/**/char
86 AO_char_fetch_compare_and_swap_acquire(volatile unsigned/**/char *addr,
87 unsigned/**/char old_val, unsigned/**/char new_val)
88 {
89 (void)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
90 __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
91 return old_val;
92 }
93# define AO_HAVE_char_fetch_compare_and_swap_acquire
94
95 AO_INLINE unsigned/**/char
96 AO_char_fetch_compare_and_swap_release(volatile unsigned/**/char *addr,
97 unsigned/**/char old_val, unsigned/**/char new_val)
98 {
99 (void)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
100 __ATOMIC_RELEASE,
101 __ATOMIC_RELAXED /* failure */);
102 return old_val;
103 }
104# define AO_HAVE_char_fetch_compare_and_swap_release
105
106 AO_INLINE unsigned/**/char
107 AO_char_fetch_compare_and_swap_full(volatile unsigned/**/char *addr,
108 unsigned/**/char old_val, unsigned/**/char new_val)
109 {
110 (void)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
111 __ATOMIC_ACQ_REL,
112 __ATOMIC_ACQUIRE /* failure */);
113 return old_val;
114 }
115# define AO_HAVE_char_fetch_compare_and_swap_full
116
117# ifndef AO_GENERALIZE_ASM_BOOL_CAS
118 AO_INLINE int
119 AO_char_compare_and_swap(volatile unsigned/**/char *addr,
120 unsigned/**/char old_val, unsigned/**/char new_val)
121 {
122 return (int)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
123 __ATOMIC_RELAXED, __ATOMIC_RELAXED);
124 }
125# define AO_HAVE_char_compare_and_swap
126
127 AO_INLINE int
128 AO_char_compare_and_swap_acquire(volatile unsigned/**/char *addr,
129 unsigned/**/char old_val, unsigned/**/char new_val)
130 {
131 return (int)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
132 __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
133 }
134# define AO_HAVE_char_compare_and_swap_acquire
135
136 AO_INLINE int
137 AO_char_compare_and_swap_release(volatile unsigned/**/char *addr,
138 unsigned/**/char old_val, unsigned/**/char new_val)
139 {
140 return (int)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
141 __ATOMIC_RELEASE,
142 __ATOMIC_RELAXED /* failure */);
143 }
144# define AO_HAVE_char_compare_and_swap_release
145
146 AO_INLINE int
147 AO_char_compare_and_swap_full(volatile unsigned/**/char *addr,
148 unsigned/**/char old_val, unsigned/**/char new_val)
149 {
150 return (int)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
151 __ATOMIC_ACQ_REL,
152 __ATOMIC_ACQUIRE /* failure */);
153 }
154# define AO_HAVE_char_compare_and_swap_full
155
156# endif /* !AO_GENERALIZE_ASM_BOOL_CAS */
157
158#endif /* AO_GCC_HAVE_char_SYNC_CAS */
159/*
160 * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
161 * Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
162 * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P.
163 *
164 *
165 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
166 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
167 *
168 * Permission is hereby granted to use or copy this program
169 * for any purpose, provided the above notices are retained on all copies.
170 * Permission to modify the code and to distribute modified code is granted,
171 * provided the above notices are retained, and a notice that the code was
172 * modified is included with the above copyright notice.
173 *
174 */
175
176#if !defined(AO_GCC_HAVE_short_SYNC_CAS) || !defined(AO_PREFER_GENERALIZED)
177
178AO_INLINE unsigned/**/short
179AO_short_load(const volatile unsigned/**/short *addr)
180{
181 return __atomic_load_n(addr, __ATOMIC_RELAXED);
182}
183#define AO_HAVE_short_load
184
185AO_INLINE unsigned/**/short
186AO_short_load_acquire(const volatile unsigned/**/short *addr)
187{
188 return __atomic_load_n(addr, __ATOMIC_ACQUIRE);
189}
190#define AO_HAVE_short_load_acquire
191
192/* short_load_read is defined using load and nop_read. */
193/* TODO: Map it to ACQUIRE. We should be strengthening the read and */
194/* write stuff to the more general acquire/release versions. It almost */
195/* never makes a difference and is much less error-prone. */
196
197/* short_load_full is generalized using load and nop_full. */
198/* TODO: Map it to SEQ_CST and clarify the documentation. */
199
200/* TODO: Map load_dd_acquire_read to ACQUIRE. Ideally it should be */
201/* mapped to CONSUME, but the latter is currently broken. */
202
203/* short_store_full definition is omitted similar to load_full reason. */
204
205/* TODO: Map store_write to RELEASE. */
206
207#ifndef AO_SKIPATOMIC_short_store
208 AO_INLINE void
209 AO_short_store(volatile unsigned/**/short *addr, unsigned/**/short value)
210 {
211 __atomic_store_n(addr, value, __ATOMIC_RELAXED);
212 }
213# define AO_HAVE_short_store
214#endif
215
216#ifndef AO_SKIPATOMIC_short_store_release
217 AO_INLINE void
218 AO_short_store_release(volatile unsigned/**/short *addr, unsigned/**/short value)
219 {
220 __atomic_store_n(addr, value, __ATOMIC_RELEASE);
221 }
222# define AO_HAVE_short_store_release
223#endif
224
225#endif /* !AO_GCC_HAVE_short_SYNC_CAS || !AO_PREFER_GENERALIZED */
226
227#ifdef AO_GCC_HAVE_short_SYNC_CAS
228
229 AO_INLINE unsigned/**/short
230 AO_short_fetch_compare_and_swap(volatile unsigned/**/short *addr,
231 unsigned/**/short old_val, unsigned/**/short new_val)
232 {
233 (void)__atomic_compare_exchange_n(addr,
234 &old_val /* p_expected */,
235 new_val /* desired */,
236 0 /* is_weak: false */,
237 __ATOMIC_RELAXED /* success */,
238 __ATOMIC_RELAXED /* failure */);
239 return old_val;
240 }
241# define AO_HAVE_short_fetch_compare_and_swap
242
243 AO_INLINE unsigned/**/short
244 AO_short_fetch_compare_and_swap_acquire(volatile unsigned/**/short *addr,
245 unsigned/**/short old_val, unsigned/**/short new_val)
246 {
247 (void)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
248 __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
249 return old_val;
250 }
251# define AO_HAVE_short_fetch_compare_and_swap_acquire
252
253 AO_INLINE unsigned/**/short
254 AO_short_fetch_compare_and_swap_release(volatile unsigned/**/short *addr,
255 unsigned/**/short old_val, unsigned/**/short new_val)
256 {
257 (void)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
258 __ATOMIC_RELEASE,
259 __ATOMIC_RELAXED /* failure */);
260 return old_val;
261 }
262# define AO_HAVE_short_fetch_compare_and_swap_release
263
264 AO_INLINE unsigned/**/short
265 AO_short_fetch_compare_and_swap_full(volatile unsigned/**/short *addr,
266 unsigned/**/short old_val, unsigned/**/short new_val)
267 {
268 (void)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
269 __ATOMIC_ACQ_REL,
270 __ATOMIC_ACQUIRE /* failure */);
271 return old_val;
272 }
273# define AO_HAVE_short_fetch_compare_and_swap_full
274
275# ifndef AO_GENERALIZE_ASM_BOOL_CAS
276 AO_INLINE int
277 AO_short_compare_and_swap(volatile unsigned/**/short *addr,
278 unsigned/**/short old_val, unsigned/**/short new_val)
279 {
280 return (int)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
281 __ATOMIC_RELAXED, __ATOMIC_RELAXED);
282 }
283# define AO_HAVE_short_compare_and_swap
284
285 AO_INLINE int
286 AO_short_compare_and_swap_acquire(volatile unsigned/**/short *addr,
287 unsigned/**/short old_val, unsigned/**/short new_val)
288 {
289 return (int)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
290 __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
291 }
292# define AO_HAVE_short_compare_and_swap_acquire
293
294 AO_INLINE int
295 AO_short_compare_and_swap_release(volatile unsigned/**/short *addr,
296 unsigned/**/short old_val, unsigned/**/short new_val)
297 {
298 return (int)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
299 __ATOMIC_RELEASE,
300 __ATOMIC_RELAXED /* failure */);
301 }
302# define AO_HAVE_short_compare_and_swap_release
303
304 AO_INLINE int
305 AO_short_compare_and_swap_full(volatile unsigned/**/short *addr,
306 unsigned/**/short old_val, unsigned/**/short new_val)
307 {
308 return (int)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
309 __ATOMIC_ACQ_REL,
310 __ATOMIC_ACQUIRE /* failure */);
311 }
312# define AO_HAVE_short_compare_and_swap_full
313
314# endif /* !AO_GENERALIZE_ASM_BOOL_CAS */
315
316#endif /* AO_GCC_HAVE_short_SYNC_CAS */
317/*
318 * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
319 * Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
320 * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P.
321 *
322 *
323 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
324 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
325 *
326 * Permission is hereby granted to use or copy this program
327 * for any purpose, provided the above notices are retained on all copies.
328 * Permission to modify the code and to distribute modified code is granted,
329 * provided the above notices are retained, and a notice that the code was
330 * modified is included with the above copyright notice.
331 *
332 */
333
334#if !defined(AO_GCC_HAVE_int_SYNC_CAS) || !defined(AO_PREFER_GENERALIZED)
335
336AO_INLINE unsigned
337AO_int_load(const volatile unsigned *addr)
338{
339 return __atomic_load_n(addr, __ATOMIC_RELAXED);
340}
341#define AO_HAVE_int_load
342
343AO_INLINE unsigned
344AO_int_load_acquire(const volatile unsigned *addr)
345{
346 return __atomic_load_n(addr, __ATOMIC_ACQUIRE);
347}
348#define AO_HAVE_int_load_acquire
349
350/* int_load_read is defined using load and nop_read. */
351/* TODO: Map it to ACQUIRE. We should be strengthening the read and */
352/* write stuff to the more general acquire/release versions. It almost */
353/* never makes a difference and is much less error-prone. */
354
355/* int_load_full is generalized using load and nop_full. */
356/* TODO: Map it to SEQ_CST and clarify the documentation. */
357
358/* TODO: Map load_dd_acquire_read to ACQUIRE. Ideally it should be */
359/* mapped to CONSUME, but the latter is currently broken. */
360
361/* int_store_full definition is omitted similar to load_full reason. */
362
363/* TODO: Map store_write to RELEASE. */
364
365#ifndef AO_SKIPATOMIC_int_store
366 AO_INLINE void
367 AO_int_store(volatile unsigned *addr, unsigned value)
368 {
369 __atomic_store_n(addr, value, __ATOMIC_RELAXED);
370 }
371# define AO_HAVE_int_store
372#endif
373
374#ifndef AO_SKIPATOMIC_int_store_release
375 AO_INLINE void
376 AO_int_store_release(volatile unsigned *addr, unsigned value)
377 {
378 __atomic_store_n(addr, value, __ATOMIC_RELEASE);
379 }
380# define AO_HAVE_int_store_release
381#endif
382
383#endif /* !AO_GCC_HAVE_int_SYNC_CAS || !AO_PREFER_GENERALIZED */
384
385#ifdef AO_GCC_HAVE_int_SYNC_CAS
386
387 AO_INLINE unsigned
388 AO_int_fetch_compare_and_swap(volatile unsigned *addr,
389 unsigned old_val, unsigned new_val)
390 {
391 (void)__atomic_compare_exchange_n(addr,
392 &old_val /* p_expected */,
393 new_val /* desired */,
394 0 /* is_weak: false */,
395 __ATOMIC_RELAXED /* success */,
396 __ATOMIC_RELAXED /* failure */);
397 return old_val;
398 }
399# define AO_HAVE_int_fetch_compare_and_swap
400
401 AO_INLINE unsigned
402 AO_int_fetch_compare_and_swap_acquire(volatile unsigned *addr,
403 unsigned old_val, unsigned new_val)
404 {
405 (void)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
406 __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
407 return old_val;
408 }
409# define AO_HAVE_int_fetch_compare_and_swap_acquire
410
411 AO_INLINE unsigned
412 AO_int_fetch_compare_and_swap_release(volatile unsigned *addr,
413 unsigned old_val, unsigned new_val)
414 {
415 (void)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
416 __ATOMIC_RELEASE,
417 __ATOMIC_RELAXED /* failure */);
418 return old_val;
419 }
420# define AO_HAVE_int_fetch_compare_and_swap_release
421
422 AO_INLINE unsigned
423 AO_int_fetch_compare_and_swap_full(volatile unsigned *addr,
424 unsigned old_val, unsigned new_val)
425 {
426 (void)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
427 __ATOMIC_ACQ_REL,
428 __ATOMIC_ACQUIRE /* failure */);
429 return old_val;
430 }
431# define AO_HAVE_int_fetch_compare_and_swap_full
432
433# ifndef AO_GENERALIZE_ASM_BOOL_CAS
434 AO_INLINE int
435 AO_int_compare_and_swap(volatile unsigned *addr,
436 unsigned old_val, unsigned new_val)
437 {
438 return (int)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
439 __ATOMIC_RELAXED, __ATOMIC_RELAXED);
440 }
441# define AO_HAVE_int_compare_and_swap
442
443 AO_INLINE int
444 AO_int_compare_and_swap_acquire(volatile unsigned *addr,
445 unsigned old_val, unsigned new_val)
446 {
447 return (int)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
448 __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
449 }
450# define AO_HAVE_int_compare_and_swap_acquire
451
452 AO_INLINE int
453 AO_int_compare_and_swap_release(volatile unsigned *addr,
454 unsigned old_val, unsigned new_val)
455 {
456 return (int)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
457 __ATOMIC_RELEASE,
458 __ATOMIC_RELAXED /* failure */);
459 }
460# define AO_HAVE_int_compare_and_swap_release
461
462 AO_INLINE int
463 AO_int_compare_and_swap_full(volatile unsigned *addr,
464 unsigned old_val, unsigned new_val)
465 {
466 return (int)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
467 __ATOMIC_ACQ_REL,
468 __ATOMIC_ACQUIRE /* failure */);
469 }
470# define AO_HAVE_int_compare_and_swap_full
471
472# endif /* !AO_GENERALIZE_ASM_BOOL_CAS */
473
474#endif /* AO_GCC_HAVE_int_SYNC_CAS */
475/*
476 * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
477 * Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
478 * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P.
479 *
480 *
481 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
482 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
483 *
484 * Permission is hereby granted to use or copy this program
485 * for any purpose, provided the above notices are retained on all copies.
486 * Permission to modify the code and to distribute modified code is granted,
487 * provided the above notices are retained, and a notice that the code was
488 * modified is included with the above copyright notice.
489 *
490 */
491
492#if !defined(AO_GCC_HAVE_SYNC_CAS) || !defined(AO_PREFER_GENERALIZED)
493
494AO_INLINE AO_t
495AO_load(const volatile AO_t *addr)
496{
497 return __atomic_load_n(addr, __ATOMIC_RELAXED);
498}
499#define AO_HAVE_load
500
501AO_INLINE AO_t
502AO_load_acquire(const volatile AO_t *addr)
503{
504 return __atomic_load_n(addr, __ATOMIC_ACQUIRE);
505}
506#define AO_HAVE_load_acquire
507
508/* load_read is defined using load and nop_read. */
509/* TODO: Map it to ACQUIRE. We should be strengthening the read and */
510/* write stuff to the more general acquire/release versions. It almost */
511/* never makes a difference and is much less error-prone. */
512
513/* load_full is generalized using load and nop_full. */
514/* TODO: Map it to SEQ_CST and clarify the documentation. */
515
516/* TODO: Map load_dd_acquire_read to ACQUIRE. Ideally it should be */
517/* mapped to CONSUME, but the latter is currently broken. */
518
519/* store_full definition is omitted similar to load_full reason. */
520
521/* TODO: Map store_write to RELEASE. */
522
523#ifndef AO_SKIPATOMIC_store
524 AO_INLINE void
525 AO_store(volatile AO_t *addr, AO_t value)
526 {
527 __atomic_store_n(addr, value, __ATOMIC_RELAXED);
528 }
529# define AO_HAVE_store
530#endif
531
532#ifndef AO_SKIPATOMIC_store_release
533 AO_INLINE void
534 AO_store_release(volatile AO_t *addr, AO_t value)
535 {
536 __atomic_store_n(addr, value, __ATOMIC_RELEASE);
537 }
538# define AO_HAVE_store_release
539#endif
540
541#endif /* !AO_GCC_HAVE_SYNC_CAS || !AO_PREFER_GENERALIZED */
542
543#ifdef AO_GCC_HAVE_SYNC_CAS
544
545 AO_INLINE AO_t
546 AO_fetch_compare_and_swap(volatile AO_t *addr,
547 AO_t old_val, AO_t new_val)
548 {
549 (void)__atomic_compare_exchange_n(addr,
550 &old_val /* p_expected */,
551 new_val /* desired */,
552 0 /* is_weak: false */,
553 __ATOMIC_RELAXED /* success */,
554 __ATOMIC_RELAXED /* failure */);
555 return old_val;
556 }
557# define AO_HAVE_fetch_compare_and_swap
558
559 AO_INLINE AO_t
560 AO_fetch_compare_and_swap_acquire(volatile AO_t *addr,
561 AO_t old_val, AO_t new_val)
562 {
563 (void)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
564 __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
565 return old_val;
566 }
567# define AO_HAVE_fetch_compare_and_swap_acquire
568
569 AO_INLINE AO_t
570 AO_fetch_compare_and_swap_release(volatile AO_t *addr,
571 AO_t old_val, AO_t new_val)
572 {
573 (void)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
574 __ATOMIC_RELEASE,
575 __ATOMIC_RELAXED /* failure */);
576 return old_val;
577 }
578# define AO_HAVE_fetch_compare_and_swap_release
579
580 AO_INLINE AO_t
581 AO_fetch_compare_and_swap_full(volatile AO_t *addr,
582 AO_t old_val, AO_t new_val)
583 {
584 (void)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
585 __ATOMIC_ACQ_REL,
586 __ATOMIC_ACQUIRE /* failure */);
587 return old_val;
588 }
589# define AO_HAVE_fetch_compare_and_swap_full
590
591# ifndef AO_GENERALIZE_ASM_BOOL_CAS
592 AO_INLINE int
593 AO_compare_and_swap(volatile AO_t *addr,
594 AO_t old_val, AO_t new_val)
595 {
596 return (int)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
597 __ATOMIC_RELAXED, __ATOMIC_RELAXED);
598 }
599# define AO_HAVE_compare_and_swap
600
601 AO_INLINE int
602 AO_compare_and_swap_acquire(volatile AO_t *addr,
603 AO_t old_val, AO_t new_val)
604 {
605 return (int)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
606 __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
607 }
608# define AO_HAVE_compare_and_swap_acquire
609
610 AO_INLINE int
611 AO_compare_and_swap_release(volatile AO_t *addr,
612 AO_t old_val, AO_t new_val)
613 {
614 return (int)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
615 __ATOMIC_RELEASE,
616 __ATOMIC_RELAXED /* failure */);
617 }
618# define AO_HAVE_compare_and_swap_release
619
620 AO_INLINE int
621 AO_compare_and_swap_full(volatile AO_t *addr,
622 AO_t old_val, AO_t new_val)
623 {
624 return (int)__atomic_compare_exchange_n(addr, &old_val, new_val, 0,
625 __ATOMIC_ACQ_REL,
626 __ATOMIC_ACQUIRE /* failure */);
627 }
628# define AO_HAVE_compare_and_swap_full
629
630# endif /* !AO_GENERALIZE_ASM_BOOL_CAS */
631
632#endif /* AO_GCC_HAVE_SYNC_CAS */
633