Debian Codegraph @

libcxx/test/std/atomics/atomics.flag/atomic_flag_test.pass.cpp

raw
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(const volatile atomic_flag*);
14 // bool atomic_flag_test(const atomic_flag*);
15
16 #include <atomic>
17 #include <cassert>
18
19 #include "test_macros.h"
20
21 int main(int, char**)
22 {
23 {
24 std::atomic_flag f;
25 f.clear();
26 assert(std::atomic_flag_test(&f) == 0);
27 assert(f.test_and_set() == 0);
28 assert(std::atomic_flag_test(&f) == 1);
29 }
30 {
31 volatile std::atomic_flag f;
32 f.clear();
33 assert(std::atomic_flag_test(&f) == 0);
34 assert(f.test_and_set() == 0);
35 assert(std::atomic_flag_test(&f) == 1);
36 }
37
38 return 0;
39 }