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