atomic-store-1.c 871 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* Test __atomic routines for existence and proper execution on 1 byte
  2. values with each valid memory model. */
  3. /* { dg-do run } */
  4. /* Test the execution of the __atomic_store_n builtin for a char. */
  5. extern void abort(void);
  6. char v, count;
  7. int
  8. main ()
  9. {
  10. v = 0;
  11. count = 0;
  12. __atomic_store_n (&v, count + 1, __ATOMIC_RELAXED);
  13. if (v != ++count)
  14. abort ();
  15. __atomic_store_n (&v, count + 1, __ATOMIC_RELEASE);
  16. if (v != ++count)
  17. abort ();
  18. __atomic_store_n (&v, count + 1, __ATOMIC_SEQ_CST);
  19. if (v != ++count)
  20. abort ();
  21. /* Now test the generic variant. */
  22. count++;
  23. __atomic_store (&v, &count, __ATOMIC_RELAXED);
  24. if (v != count++)
  25. abort ();
  26. __atomic_store (&v, &count, __ATOMIC_RELEASE);
  27. if (v != count++)
  28. abort ();
  29. __atomic_store (&v, &count, __ATOMIC_SEQ_CST);
  30. if (v != count)
  31. abort ();
  32. return 0;
  33. }