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 atomic_flag_clear_explicit(volatile atomic_flag*, memory_order); 16 // void atomic_flag_clear_explicit(atomic_flag*, memory_order); 17 18 #include <atomic> 19 #include <cassert> 20 21 int main(int, char**) 22 { 23 { 24 std::atomic_flag f; // uninitialized first 25 atomic_flag_clear_explicit(&f, std::memory_order_relaxed); 26 assert(f.test_and_set() == 0); 27 atomic_flag_clear_explicit(&f, std::memory_order_relaxed); 28 assert(f.test_and_set() == 0); 29 } 30 { 31 std::atomic_flag f; 32 atomic_flag_clear_explicit(&f, std::memory_order_release); 33 assert(f.test_and_set() == 0); 34 atomic_flag_clear_explicit(&f, std::memory_order_release); 35 assert(f.test_and_set() == 0); 36 } 37 { 38 std::atomic_flag f; 39 atomic_flag_clear_explicit(&f, std::memory_order_seq_cst); 40 assert(f.test_and_set() == 0); 41 atomic_flag_clear_explicit(&f, std::memory_order_seq_cst); 42 assert(f.test_and_set() == 0); 43 } 44 { 45 volatile std::atomic_flag f; 46 atomic_flag_clear_explicit(&f, std::memory_order_relaxed); 47 assert(f.test_and_set() == 0); 48 atomic_flag_clear_explicit(&f, std::memory_order_relaxed); 49 assert(f.test_and_set() == 0); 50 } 51 { 52 volatile std::atomic_flag f; 53 atomic_flag_clear_explicit(&f, std::memory_order_release); 54 assert(f.test_and_set() == 0); 55 atomic_flag_clear_explicit(&f, std::memory_order_release); 56 assert(f.test_and_set() == 0); 57 } 58 { 59 volatile std::atomic_flag f; 60 atomic_flag_clear_explicit(&f, std::memory_order_seq_cst); 61 assert(f.test_and_set() == 0); 62 atomic_flag_clear_explicit(&f, std::memory_order_seq_cst); 63 assert(f.test_and_set() == 0); 64 } 65 66 return 0; 67 } 68