1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // UNSUPPORTED: libcpp-has-no-threads 10 11 // <atomic> 12 13 // struct atomic_flag 14 15 // void clear(memory_order = memory_order_seq_cst); 16 // void clear(memory_order = memory_order_seq_cst) volatile; 17 18 #include <atomic> 19 #include <cassert> 20 21 #include "test_macros.h" 22 main(int,char **)23int main(int, char**) 24 { 25 { 26 std::atomic_flag f; // uninitialized 27 f.clear(); 28 assert(f.test_and_set() == 0); 29 f.clear(); 30 assert(f.test_and_set() == 0); 31 } 32 { 33 std::atomic_flag f; 34 f.clear(std::memory_order_relaxed); 35 assert(f.test_and_set() == 0); 36 f.clear(std::memory_order_relaxed); 37 assert(f.test_and_set() == 0); 38 } 39 { 40 std::atomic_flag f; 41 f.clear(std::memory_order_release); 42 assert(f.test_and_set() == 0); 43 f.clear(std::memory_order_release); 44 assert(f.test_and_set() == 0); 45 } 46 { 47 std::atomic_flag f; 48 f.clear(std::memory_order_seq_cst); 49 assert(f.test_and_set() == 0); 50 f.clear(std::memory_order_seq_cst); 51 assert(f.test_and_set() == 0); 52 } 53 { 54 volatile std::atomic_flag f; 55 f.clear(); 56 assert(f.test_and_set() == 0); 57 f.clear(); 58 assert(f.test_and_set() == 0); 59 } 60 { 61 volatile std::atomic_flag f; 62 f.clear(std::memory_order_relaxed); 63 assert(f.test_and_set() == 0); 64 f.clear(std::memory_order_relaxed); 65 assert(f.test_and_set() == 0); 66 } 67 { 68 volatile std::atomic_flag f; 69 f.clear(std::memory_order_release); 70 assert(f.test_and_set() == 0); 71 f.clear(std::memory_order_release); 72 assert(f.test_and_set() == 0); 73 } 74 { 75 volatile std::atomic_flag f; 76 f.clear(std::memory_order_seq_cst); 77 assert(f.test_and_set() == 0); 78 f.clear(std::memory_order_seq_cst); 79 assert(f.test_and_set() == 0); 80 } 81 82 return 0; 83 } 84