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