atomic-exchange-2.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_X builtin for a short. */
  5. extern void abort(void);
  6. short v, count, ret;
  7. int
  8. main ()
  9. {
  10. v = 0;
  11. count = 0;
  12. if (__atomic_exchange_n (&v, count + 1, __ATOMIC_RELAXED) != count)
  13. abort ();
  14. count++;
  15. if (__atomic_exchange_n (&v, count + 1, __ATOMIC_ACQUIRE) != count)
  16. abort ();
  17. count++;
  18. if (__atomic_exchange_n (&v, count + 1, __ATOMIC_RELEASE) != count)
  19. abort ();
  20. count++;
  21. if (__atomic_exchange_n (&v, count + 1, __ATOMIC_ACQ_REL) != count)
  22. abort ();
  23. count++;
  24. if (__atomic_exchange_n (&v, count + 1, __ATOMIC_SEQ_CST) != count)
  25. abort ();
  26. count++;
  27. /* Now test the generic version. */
  28. count++;
  29. __atomic_exchange (&v, &count, &ret, __ATOMIC_RELAXED);
  30. if (ret != count - 1 || v != count)
  31. abort ();
  32. count++;
  33. __atomic_exchange (&v, &count, &ret, __ATOMIC_ACQUIRE);
  34. if (ret != count - 1 || v != count)
  35. abort ();
  36. count++;
  37. __atomic_exchange (&v, &count, &ret, __ATOMIC_RELEASE);
  38. if (ret != count - 1 || v != count)
  39. abort ();
  40. count++;
  41. __atomic_exchange (&v, &count, &ret, __ATOMIC_ACQ_REL);
  42. if (ret != count - 1 || v != count)
  43. abort ();
  44. count++;
  45. __atomic_exchange (&v, &count, &ret, __ATOMIC_SEQ_CST);
  46. if (ret != count - 1 || v != count)
  47. abort ();
  48. count++;
  49. return 0;
  50. }