1 /* Test atomic_flag routines for existence and execution. */ 2 /* The test needs a lockless atomic implementation. */ 3 /* { dg-do run { xfail hppa*-*-hpux* } } */ 4 /* { dg-options "-std=c11 -pedantic-errors" } */ 5 6 #include <stdatomic.h> 7 8 extern void abort (void); 9 atomic_flag a = ATOMIC_FLAG_INIT; 10 11 int main()12main () 13 { 14 int b; 15 16 if (!atomic_is_lock_free (&a)) 17 abort (); 18 19 if (atomic_flag_test_and_set (&a)) 20 abort (); 21 atomic_flag_clear_explicit (&a, memory_order_relaxed); 22 if (atomic_flag_test_and_set (&a)) 23 abort (); 24 atomic_flag_clear (&a); 25 26 b = atomic_flag_test_and_set_explicit (&a, memory_order_seq_cst); 27 if (!atomic_flag_test_and_set (&a) || b != 0) 28 abort (); 29 30 b = atomic_flag_test_and_set_explicit (&a, memory_order_acq_rel); 31 if (!atomic_flag_test_and_set (&a) || b != 1) 32 abort (); 33 34 atomic_flag_clear_explicit (&a, memory_order_seq_cst); 35 if (atomic_flag_test_and_set (&a)) 36 abort (); 37 38 return 0; 39 } 40