atomic-load-3.c 1.0 KB

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