aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-flag.c
blob: c1a63f1b3aae74753e63958b63cbd7e4d829b10d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* Test atomic_flag routines for existence and execution.  */
/* { dg-do run { xfail hppa*-*-hpux* } } */
/* { dg-options "-std=c11 -pedantic-errors" } */

#include <stdatomic.h>

extern void abort (void);
atomic_flag a = ATOMIC_FLAG_INIT;

int
main ()
{
  int b;

  if (!atomic_is_lock_free (&a))
    abort ();

  if (atomic_flag_test_and_set (&a))
    abort ();
  atomic_flag_clear_explicit (&a, memory_order_relaxed);
  if (atomic_flag_test_and_set (&a))
    abort ();
  atomic_flag_clear (&a);

  b = atomic_flag_test_and_set_explicit (&a, memory_order_seq_cst);
  if (!atomic_flag_test_and_set (&a) || b != 0)
    abort ();

  b = atomic_flag_test_and_set_explicit (&a, memory_order_acq_rel);
  if (!atomic_flag_test_and_set (&a) || b != 1)
    abort ();

  atomic_flag_clear_explicit (&a, memory_order_seq_cst);
  if (atomic_flag_test_and_set (&a))
    abort ();

  return 0;
}