1*58b9f456SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 2*58b9f456SAndroid Build Coastguard Worker // 3*58b9f456SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure 4*58b9f456SAndroid Build Coastguard Worker // 5*58b9f456SAndroid Build Coastguard Worker // This file is dual licensed under the MIT and the University of Illinois Open 6*58b9f456SAndroid Build Coastguard Worker // Source Licenses. See LICENSE.TXT for details. 7*58b9f456SAndroid Build Coastguard Worker // 8*58b9f456SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 9*58b9f456SAndroid Build Coastguard Worker // 10*58b9f456SAndroid Build Coastguard Worker // UNSUPPORTED: libcpp-has-no-threads 11*58b9f456SAndroid Build Coastguard Worker 12*58b9f456SAndroid Build Coastguard Worker // <atomic> 13*58b9f456SAndroid Build Coastguard Worker 14*58b9f456SAndroid Build Coastguard Worker // struct atomic_flag 15*58b9f456SAndroid Build Coastguard Worker 16*58b9f456SAndroid Build Coastguard Worker // void clear(memory_order = memory_order_seq_cst); 17*58b9f456SAndroid Build Coastguard Worker // void clear(memory_order = memory_order_seq_cst) volatile; 18*58b9f456SAndroid Build Coastguard Worker 19*58b9f456SAndroid Build Coastguard Worker #include <atomic> 20*58b9f456SAndroid Build Coastguard Worker #include <cassert> 21*58b9f456SAndroid Build Coastguard Worker main()22*58b9f456SAndroid Build Coastguard Workerint main() 23*58b9f456SAndroid Build Coastguard Worker { 24*58b9f456SAndroid Build Coastguard Worker { 25*58b9f456SAndroid Build Coastguard Worker std::atomic_flag f; // uninitialized 26*58b9f456SAndroid Build Coastguard Worker f.clear(); 27*58b9f456SAndroid Build Coastguard Worker assert(f.test_and_set() == 0); 28*58b9f456SAndroid Build Coastguard Worker f.clear(); 29*58b9f456SAndroid Build Coastguard Worker assert(f.test_and_set() == 0); 30*58b9f456SAndroid Build Coastguard Worker } 31*58b9f456SAndroid Build Coastguard Worker { 32*58b9f456SAndroid Build Coastguard Worker std::atomic_flag f; 33*58b9f456SAndroid Build Coastguard Worker f.clear(std::memory_order_relaxed); 34*58b9f456SAndroid Build Coastguard Worker assert(f.test_and_set() == 0); 35*58b9f456SAndroid Build Coastguard Worker f.clear(std::memory_order_relaxed); 36*58b9f456SAndroid Build Coastguard Worker assert(f.test_and_set() == 0); 37*58b9f456SAndroid Build Coastguard Worker } 38*58b9f456SAndroid Build Coastguard Worker { 39*58b9f456SAndroid Build Coastguard Worker std::atomic_flag f; 40*58b9f456SAndroid Build Coastguard Worker f.clear(std::memory_order_release); 41*58b9f456SAndroid Build Coastguard Worker assert(f.test_and_set() == 0); 42*58b9f456SAndroid Build Coastguard Worker f.clear(std::memory_order_release); 43*58b9f456SAndroid Build Coastguard Worker assert(f.test_and_set() == 0); 44*58b9f456SAndroid Build Coastguard Worker } 45*58b9f456SAndroid Build Coastguard Worker { 46*58b9f456SAndroid Build Coastguard Worker std::atomic_flag f; 47*58b9f456SAndroid Build Coastguard Worker f.clear(std::memory_order_seq_cst); 48*58b9f456SAndroid Build Coastguard Worker assert(f.test_and_set() == 0); 49*58b9f456SAndroid Build Coastguard Worker f.clear(std::memory_order_seq_cst); 50*58b9f456SAndroid Build Coastguard Worker assert(f.test_and_set() == 0); 51*58b9f456SAndroid Build Coastguard Worker } 52*58b9f456SAndroid Build Coastguard Worker { 53*58b9f456SAndroid Build Coastguard Worker volatile std::atomic_flag f; 54*58b9f456SAndroid Build Coastguard Worker f.clear(); 55*58b9f456SAndroid Build Coastguard Worker assert(f.test_and_set() == 0); 56*58b9f456SAndroid Build Coastguard Worker f.clear(); 57*58b9f456SAndroid Build Coastguard Worker assert(f.test_and_set() == 0); 58*58b9f456SAndroid Build Coastguard Worker } 59*58b9f456SAndroid Build Coastguard Worker { 60*58b9f456SAndroid Build Coastguard Worker volatile std::atomic_flag f; 61*58b9f456SAndroid Build Coastguard Worker f.clear(std::memory_order_relaxed); 62*58b9f456SAndroid Build Coastguard Worker assert(f.test_and_set() == 0); 63*58b9f456SAndroid Build Coastguard Worker f.clear(std::memory_order_relaxed); 64*58b9f456SAndroid Build Coastguard Worker assert(f.test_and_set() == 0); 65*58b9f456SAndroid Build Coastguard Worker } 66*58b9f456SAndroid Build Coastguard Worker { 67*58b9f456SAndroid Build Coastguard Worker volatile std::atomic_flag f; 68*58b9f456SAndroid Build Coastguard Worker f.clear(std::memory_order_release); 69*58b9f456SAndroid Build Coastguard Worker assert(f.test_and_set() == 0); 70*58b9f456SAndroid Build Coastguard Worker f.clear(std::memory_order_release); 71*58b9f456SAndroid Build Coastguard Worker assert(f.test_and_set() == 0); 72*58b9f456SAndroid Build Coastguard Worker } 73*58b9f456SAndroid Build Coastguard Worker { 74*58b9f456SAndroid Build Coastguard Worker volatile std::atomic_flag f; 75*58b9f456SAndroid Build Coastguard Worker f.clear(std::memory_order_seq_cst); 76*58b9f456SAndroid Build Coastguard Worker assert(f.test_and_set() == 0); 77*58b9f456SAndroid Build Coastguard Worker f.clear(std::memory_order_seq_cst); 78*58b9f456SAndroid Build Coastguard Worker assert(f.test_and_set() == 0); 79*58b9f456SAndroid Build Coastguard Worker } 80*58b9f456SAndroid Build Coastguard Worker } 81