Debian Codegraph @

libatomic/testsuite/libatomic.c/atomic-generic.c

raw
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 #include <string.h>
13
14 extern void abort();
15
16 typedef struct test {
17 int array[10];
18 } test_struct;
19
20 test_struct zero = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
21 test_struct ones = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
22 test_struct a,b;
23
24 int size = sizeof (test_struct);
25 /* Test for consistency on sizes 1, 2, 4, 8, 16 and 32. */
26 int
27 main ()
28 {
29 test_struct c;
30
31 __atomic_store (&a, &zero, __ATOMIC_RELAXED);
32 if (memcmp (&a, &zero, size))
33 abort ();
34
35 __atomic_exchange (&a, &ones, &c, __ATOMIC_SEQ_CST);
36 if (memcmp (&c, &zero, size))
37 abort ();
38 if (memcmp (&a, &ones, size))
39 abort ();
40
41 __atomic_load (&a, &b, __ATOMIC_RELAXED);
42 if (memcmp (&b, &ones, size))
43 abort ();
44
45 if (!__atomic_compare_exchange (&a, &b, &zero, false, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE))
46 abort();
47 if (memcmp (&a, &zero, size))
48 abort ();
49
50 if (__atomic_compare_exchange (&a, &b, &ones, false, __ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE))
51 abort();
52 if (memcmp (&b, &zero, size))
53 abort ();
54
55 return 0;
56 }
57