atomic-generic.c 1.3 KB

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