(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
atomic-exchange-2.c
       1  /* Test __atomic routines for existence and proper execution on 2 byte 
       2     values with each valid memory model.  */
       3  /* { dg-do run } */
       4  /* { dg-require-effective-target sync_char_short } */
       5  
       6  /* Test the execution of the __atomic_X builtin for a short.  */
       7  
       8  extern void abort(void);
       9  
      10  short v, count, ret;
      11  
      12  int
      13  main ()
      14  {
      15    v = 0;
      16    count = 0;
      17  
      18    if (__atomic_exchange_n (&v, count + 1, __ATOMIC_RELAXED) != count)
      19      abort ();
      20    count++;
      21  
      22    if (__atomic_exchange_n (&v, count + 1, __ATOMIC_ACQUIRE) != count)
      23      abort ();
      24    count++;
      25  
      26    if (__atomic_exchange_n (&v, count + 1, __ATOMIC_RELEASE) != count)
      27      abort ();
      28    count++;
      29  
      30    if (__atomic_exchange_n (&v, count + 1, __ATOMIC_ACQ_REL) != count)
      31      abort ();
      32    count++;
      33  
      34    if (__atomic_exchange_n (&v, count + 1, __ATOMIC_SEQ_CST) != count)
      35      abort ();
      36    count++;
      37  
      38    /* Now test the generic version.  */
      39  
      40    count++;
      41  
      42    __atomic_exchange (&v, &count, &ret, __ATOMIC_RELAXED);
      43    if (ret != count - 1 || v != count)
      44      abort ();
      45    count++;
      46  
      47    __atomic_exchange (&v, &count, &ret, __ATOMIC_ACQUIRE);
      48    if (ret != count - 1 || v != count)
      49      abort ();
      50    count++;
      51  
      52    __atomic_exchange (&v, &count, &ret, __ATOMIC_RELEASE);
      53    if (ret != count - 1 || v != count)
      54      abort ();
      55    count++;
      56  
      57    __atomic_exchange (&v, &count, &ret, __ATOMIC_ACQ_REL);
      58    if (ret != count - 1 || v != count)
      59      abort ();
      60    count++;
      61  
      62    __atomic_exchange (&v, &count, &ret, __ATOMIC_SEQ_CST);
      63    if (ret != count - 1 || v != count)
      64      abort ();
      65    count++;
      66  
      67    return 0;
      68  }