diff options
Diffstat (limited to 'gcc/testsuite/gcc.dg/atomic/stdatomic-flag.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/atomic/stdatomic-flag.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/atomic/stdatomic-flag.c b/gcc/testsuite/gcc.dg/atomic/stdatomic-flag.c new file mode 100644 index 00000000000..32f9e9bb631 --- /dev/null +++ b/gcc/testsuite/gcc.dg/atomic/stdatomic-flag.c @@ -0,0 +1,38 @@ +/* Test atomic_flag routines for existence and execution. */ +/* { dg-do run } */ +/* { 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; +} |