atomic-store-2.c 872 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* Test __atomic routines for existence and proper execution on 2 byte
  2. values with each valid memory model. */
  3. /* { dg-do run } */
  4. /* Test the execution of the __atomic_store_n builtin for a short. */
  5. extern void abort(void);
  6. short 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. }