1 /* Test atomic_exchange routines for existence and proper execution on
2    4-byte values with each valid memory model.  */
3 /* { dg-do run } */
4 /* { dg-options "-std=c11 -pedantic-errors" } */
5 
6 #include <stdatomic.h>
7 
8 extern void abort (void);
9 
10 _Atomic int v;
11 int count, ret;
12 
13 int
main()14 main ()
15 {
16   v = 0;
17   count = 0;
18 
19   if (atomic_exchange_explicit (&v, count + 1, memory_order_relaxed) != count)
20     abort ();
21   count++;
22 
23   if (atomic_exchange_explicit (&v, count + 1, memory_order_acquire) != count)
24     abort ();
25   count++;
26 
27   if (atomic_exchange_explicit (&v, count + 1, memory_order_release) != count)
28     abort ();
29   count++;
30 
31   if (atomic_exchange_explicit (&v, count + 1, memory_order_acq_rel) != count)
32     abort ();
33   count++;
34 
35   if (atomic_exchange_explicit (&v, count + 1, memory_order_seq_cst) != count)
36     abort ();
37   count++;
38 
39   count++;
40 
41   ret = atomic_exchange (&v, count);
42   if (ret != count - 1 || v != count)
43     abort ();
44 
45   return 0;
46 }
47