111
|
1 /* Test generic __atomic routines for proper function calling.
|
|
2 memory model. */
|
|
3 /* { dg-options "-w" } */
|
|
4 /* { dg-do run } */
|
|
5
|
|
6 /* Test that the generioc atomic builtins execute as expected..
|
|
7 sync-mem-generic-aux.c supplies a functional external entry point for
|
|
8 the 4 generic functions. */
|
|
9
|
|
10 #include <stdlib.h>
|
|
11 #include <stdbool.h>
|
|
12
|
|
13 extern void abort();
|
|
14
|
|
15 typedef struct test {
|
|
16 int array[10];
|
|
17 } test_struct;
|
|
18
|
|
19 test_struct zero = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
20 test_struct ones = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
|
|
21 test_struct a,b;
|
|
22
|
|
23 int size = sizeof (test_struct);
|
|
24 /* Test for consistency on sizes 1, 2, 4, 8, 16 and 32. */
|
|
25 int
|
|
26 main ()
|
|
27 {
|
|
28 test_struct c;
|
|
29
|
|
30 __atomic_store (&a, &zero, __ATOMIC_RELAXED);
|
|
31 if (memcmp (&a, &zero, size))
|
|
32 abort ();
|
|
33
|
|
34 __atomic_exchange (&a, &ones, &c, __ATOMIC_SEQ_CST);
|
|
35 if (memcmp (&c, &zero, size))
|
|
36 abort ();
|
|
37 if (memcmp (&a, &ones, size))
|
|
38 abort ();
|
|
39
|
|
40 __atomic_load (&a, &b, __ATOMIC_RELAXED);
|
|
41 if (memcmp (&b, &ones, size))
|
|
42 abort ();
|
|
43
|
|
44 if (!__atomic_compare_exchange (&a, &b, &zero, false, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE))
|
|
45 abort();
|
|
46 if (memcmp (&a, &zero, size))
|
|
47 abort ();
|
|
48
|
|
49 if (__atomic_compare_exchange (&a, &b, &ones, false, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE))
|
|
50 abort();
|
|
51 if (memcmp (&b, &zero, size))
|
|
52 abort ();
|
|
53
|
|
54 return 0;
|
|
55 }
|
|
56
|