atomic-exchange-4.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* Test __atomic routines for existence and proper execution on 8 byte
  2. values with each valid memory model. */
  3. /* { dg-do run } */
  4. /* { dg-options "" } */
  5. /* Test the execution of the __atomic_X builtin for a long_long. */
  6. extern void abort(void);
  7. long long v, count, ret;
  8. int
  9. main ()
  10. {
  11. v = 0;
  12. count = 0;
  13. if (__atomic_exchange_n (&v, count + 1, __ATOMIC_RELAXED) != count)
  14. abort ();
  15. count++;
  16. if (__atomic_exchange_n (&v, count + 1, __ATOMIC_ACQUIRE) != count)
  17. abort ();
  18. count++;
  19. if (__atomic_exchange_n (&v, count + 1, __ATOMIC_RELEASE) != count)
  20. abort ();
  21. count++;
  22. if (__atomic_exchange_n (&v, count + 1, __ATOMIC_ACQ_REL) != count)
  23. abort ();
  24. count++;
  25. if (__atomic_exchange_n (&v, count + 1, __ATOMIC_SEQ_CST) != count)
  26. abort ();
  27. count++;
  28. /* Now test the generic version. */
  29. count++;
  30. __atomic_exchange (&v, &count, &ret, __ATOMIC_RELAXED);
  31. if (ret != count - 1 || v != count)
  32. abort ();
  33. count++;
  34. __atomic_exchange (&v, &count, &ret, __ATOMIC_ACQUIRE);
  35. if (ret != count - 1 || v != count)
  36. abort ();
  37. count++;
  38. __atomic_exchange (&v, &count, &ret, __ATOMIC_RELEASE);
  39. if (ret != count - 1 || v != count)
  40. abort ();
  41. count++;
  42. __atomic_exchange (&v, &count, &ret, __ATOMIC_ACQ_REL);
  43. if (ret != count - 1 || v != count)
  44. abort ();
  45. count++;
  46. __atomic_exchange (&v, &count, &ret, __ATOMIC_SEQ_CST);
  47. if (ret != count - 1 || v != count)
  48. abort ();
  49. count++;
  50. return 0;
  51. }