• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // <atomic>
11 
12 // struct atomic_flag
13 
14 // void clear(memory_order = memory_order_seq_cst);
15 // void clear(memory_order = memory_order_seq_cst) volatile;
16 
17 #include <atomic>
18 #include <cassert>
19 
main()20 int main()
21 {
22     {
23         std::atomic_flag f;
24         f.test_and_set();
25         f.clear();
26         assert(f.test_and_set() == 0);
27     }
28     {
29         std::atomic_flag f;
30         f.test_and_set();
31         f.clear(std::memory_order_relaxed);
32         assert(f.test_and_set() == 0);
33     }
34     {
35         std::atomic_flag f;
36         f.test_and_set();
37         f.clear(std::memory_order_release);
38         assert(f.test_and_set() == 0);
39     }
40     {
41         std::atomic_flag f;
42         f.test_and_set();
43         f.clear(std::memory_order_seq_cst);
44         assert(f.test_and_set() == 0);
45     }
46     {
47         volatile std::atomic_flag f;
48         f.test_and_set();
49         f.clear();
50         assert(f.test_and_set() == 0);
51     }
52     {
53         volatile std::atomic_flag f;
54         f.test_and_set();
55         f.clear(std::memory_order_relaxed);
56         assert(f.test_and_set() == 0);
57     }
58     {
59         volatile std::atomic_flag f;
60         f.test_and_set();
61         f.clear(std::memory_order_release);
62         assert(f.test_and_set() == 0);
63     }
64     {
65         volatile std::atomic_flag f;
66         f.test_and_set();
67         f.clear(std::memory_order_seq_cst);
68         assert(f.test_and_set() == 0);
69     }
70 }
71