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 // <atomic>
10
11 // struct atomic_flag
12
13 // bool atomic_flag_test_and_set_explicit(volatile atomic_flag*, memory_order);
14 // bool atomic_flag_test_and_set_explicit(atomic_flag*, memory_order);
15
16 #include <atomic>
17 #include <cassert>
18
19 #include "test_macros.h"
20
main(int,char **)21 int main(int, char**)
22 {
23 {
24 std::atomic_flag f;
25 f.clear();
26 assert(std::atomic_flag_test_and_set_explicit(&f, std::memory_order_relaxed) == 0);
27 assert(f.test_and_set() == 1);
28 }
29 {
30 std::atomic_flag f;
31 f.clear();
32 assert(std::atomic_flag_test_and_set_explicit(&f, std::memory_order_consume) == 0);
33 assert(f.test_and_set() == 1);
34 }
35 {
36 std::atomic_flag f;
37 f.clear();
38 assert(std::atomic_flag_test_and_set_explicit(&f, std::memory_order_acquire) == 0);
39 assert(f.test_and_set() == 1);
40 }
41 {
42 std::atomic_flag f;
43 f.clear();
44 assert(std::atomic_flag_test_and_set_explicit(&f, std::memory_order_release) == 0);
45 assert(f.test_and_set() == 1);
46 }
47 {
48 std::atomic_flag f;
49 f.clear();
50 assert(std::atomic_flag_test_and_set_explicit(&f, std::memory_order_acq_rel) == 0);
51 assert(f.test_and_set() == 1);
52 }
53 {
54 std::atomic_flag f;
55 f.clear();
56 assert(std::atomic_flag_test_and_set_explicit(&f, std::memory_order_seq_cst) == 0);
57 assert(f.test_and_set() == 1);
58 }
59 {
60 volatile std::atomic_flag f;
61 f.clear();
62 assert(std::atomic_flag_test_and_set_explicit(&f, std::memory_order_relaxed) == 0);
63 assert(f.test_and_set() == 1);
64 }
65 {
66 volatile std::atomic_flag f;
67 f.clear();
68 assert(std::atomic_flag_test_and_set_explicit(&f, std::memory_order_consume) == 0);
69 assert(f.test_and_set() == 1);
70 }
71 {
72 volatile std::atomic_flag f;
73 f.clear();
74 assert(std::atomic_flag_test_and_set_explicit(&f, std::memory_order_acquire) == 0);
75 assert(f.test_and_set() == 1);
76 }
77 {
78 volatile std::atomic_flag f;
79 f.clear();
80 assert(std::atomic_flag_test_and_set_explicit(&f, std::memory_order_release) == 0);
81 assert(f.test_and_set() == 1);
82 }
83 {
84 volatile std::atomic_flag f;
85 f.clear();
86 assert(std::atomic_flag_test_and_set_explicit(&f, std::memory_order_acq_rel) == 0);
87 assert(f.test_and_set() == 1);
88 }
89 {
90 volatile std::atomic_flag f;
91 f.clear();
92 assert(std::atomic_flag_test_and_set_explicit(&f, std::memory_order_seq_cst) == 0);
93 assert(f.test_and_set() == 1);
94 }
95
96 return 0;
97 }
98