1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // UNSUPPORTED: libcpp-has-no-threads 11 12 // <atomic> 13 14 // struct atomic_flag 15 16 // bool test_and_set(memory_order = memory_order_seq_cst); 17 // bool test_and_set(memory_order = memory_order_seq_cst) volatile; 18 19 #include <atomic> 20 #include <cassert> 21 main()22int main() 23 { 24 { 25 std::atomic_flag f; 26 f.clear(); 27 assert(f.test_and_set() == 0); 28 assert(f.test_and_set() == 1); 29 } 30 { 31 std::atomic_flag f; 32 f.clear(); 33 assert(f.test_and_set(std::memory_order_relaxed) == 0); 34 assert(f.test_and_set(std::memory_order_relaxed) == 1); 35 } 36 { 37 std::atomic_flag f; 38 f.clear(); 39 assert(f.test_and_set(std::memory_order_consume) == 0); 40 assert(f.test_and_set(std::memory_order_consume) == 1); 41 } 42 { 43 std::atomic_flag f; 44 f.clear(); 45 assert(f.test_and_set(std::memory_order_acquire) == 0); 46 assert(f.test_and_set(std::memory_order_acquire) == 1); 47 } 48 { 49 std::atomic_flag f; 50 f.clear(); 51 assert(f.test_and_set(std::memory_order_release) == 0); 52 assert(f.test_and_set(std::memory_order_release) == 1); 53 } 54 { 55 std::atomic_flag f; 56 f.clear(); 57 assert(f.test_and_set(std::memory_order_acq_rel) == 0); 58 assert(f.test_and_set(std::memory_order_acq_rel) == 1); 59 } 60 { 61 std::atomic_flag f; 62 f.clear(); 63 assert(f.test_and_set(std::memory_order_seq_cst) == 0); 64 assert(f.test_and_set(std::memory_order_seq_cst) == 1); 65 } 66 { 67 volatile std::atomic_flag f; 68 f.clear(); 69 assert(f.test_and_set() == 0); 70 assert(f.test_and_set() == 1); 71 } 72 { 73 volatile std::atomic_flag f; 74 f.clear(); 75 assert(f.test_and_set(std::memory_order_relaxed) == 0); 76 assert(f.test_and_set(std::memory_order_relaxed) == 1); 77 } 78 { 79 volatile std::atomic_flag f; 80 f.clear(); 81 assert(f.test_and_set(std::memory_order_consume) == 0); 82 assert(f.test_and_set(std::memory_order_consume) == 1); 83 } 84 { 85 volatile std::atomic_flag f; 86 f.clear(); 87 assert(f.test_and_set(std::memory_order_acquire) == 0); 88 assert(f.test_and_set(std::memory_order_acquire) == 1); 89 } 90 { 91 volatile std::atomic_flag f; 92 f.clear(); 93 assert(f.test_and_set(std::memory_order_release) == 0); 94 assert(f.test_and_set(std::memory_order_release) == 1); 95 } 96 { 97 volatile std::atomic_flag f; 98 f.clear(); 99 assert(f.test_and_set(std::memory_order_acq_rel) == 0); 100 assert(f.test_and_set(std::memory_order_acq_rel) == 1); 101 } 102 { 103 volatile std::atomic_flag f; 104 f.clear(); 105 assert(f.test_and_set(std::memory_order_seq_cst) == 0); 106 assert(f.test_and_set(std::memory_order_seq_cst) == 1); 107 } 108 } 109