blob: 33378e4bd87ff217a01062719a313276a45d73f9 [file] [log] [blame]
Howard Hinnant748a5272010-09-30 21:05:29 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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
Howard Hinnant748a5272010-09-30 21:05:29 +00006//
7//===----------------------------------------------------------------------===//
Jonathan Roelofsb3fcc672014-09-05 19:45:05 +00008//
9// UNSUPPORTED: libcpp-has-no-threads
Howard Hinnant748a5272010-09-30 21:05:29 +000010
11// <atomic>
12
13// struct atomic_flag
14
15// void clear(memory_order = memory_order_seq_cst);
16// void clear(memory_order = memory_order_seq_cst) volatile;
17
18#include <atomic>
19#include <cassert>
20
JF Bastien2df59c52019-02-04 20:31:13 +000021int main(int, char**)
Howard Hinnant748a5272010-09-30 21:05:29 +000022{
23 {
Eric Fiselier990952b2016-06-19 07:08:27 +000024 std::atomic_flag f; // uninitialized
25 f.clear();
26 assert(f.test_and_set() == 0);
Howard Hinnant748a5272010-09-30 21:05:29 +000027 f.clear();
28 assert(f.test_and_set() == 0);
29 }
30 {
Eric Fiselier15a29722016-05-03 02:12:26 +000031 std::atomic_flag f;
Eric Fiselier990952b2016-06-19 07:08:27 +000032 f.clear(std::memory_order_relaxed);
33 assert(f.test_and_set() == 0);
Howard Hinnant748a5272010-09-30 21:05:29 +000034 f.clear(std::memory_order_relaxed);
35 assert(f.test_and_set() == 0);
36 }
37 {
Eric Fiselier15a29722016-05-03 02:12:26 +000038 std::atomic_flag f;
Eric Fiselier990952b2016-06-19 07:08:27 +000039 f.clear(std::memory_order_release);
40 assert(f.test_and_set() == 0);
Howard Hinnant748a5272010-09-30 21:05:29 +000041 f.clear(std::memory_order_release);
42 assert(f.test_and_set() == 0);
43 }
44 {
Eric Fiselier15a29722016-05-03 02:12:26 +000045 std::atomic_flag f;
Eric Fiselier990952b2016-06-19 07:08:27 +000046 f.clear(std::memory_order_seq_cst);
47 assert(f.test_and_set() == 0);
Howard Hinnant748a5272010-09-30 21:05:29 +000048 f.clear(std::memory_order_seq_cst);
49 assert(f.test_and_set() == 0);
50 }
51 {
Eric Fiselier15a29722016-05-03 02:12:26 +000052 volatile std::atomic_flag f;
Eric Fiselier990952b2016-06-19 07:08:27 +000053 f.clear();
54 assert(f.test_and_set() == 0);
Howard Hinnant748a5272010-09-30 21:05:29 +000055 f.clear();
56 assert(f.test_and_set() == 0);
57 }
58 {
Eric Fiselier15a29722016-05-03 02:12:26 +000059 volatile std::atomic_flag f;
Eric Fiselier990952b2016-06-19 07:08:27 +000060 f.clear(std::memory_order_relaxed);
61 assert(f.test_and_set() == 0);
Howard Hinnant748a5272010-09-30 21:05:29 +000062 f.clear(std::memory_order_relaxed);
63 assert(f.test_and_set() == 0);
64 }
65 {
Eric Fiselier15a29722016-05-03 02:12:26 +000066 volatile std::atomic_flag f;
Eric Fiselier990952b2016-06-19 07:08:27 +000067 f.clear(std::memory_order_release);
68 assert(f.test_and_set() == 0);
Howard Hinnant748a5272010-09-30 21:05:29 +000069 f.clear(std::memory_order_release);
70 assert(f.test_and_set() == 0);
71 }
72 {
Eric Fiselier15a29722016-05-03 02:12:26 +000073 volatile std::atomic_flag f;
Eric Fiselier990952b2016-06-19 07:08:27 +000074 f.clear(std::memory_order_seq_cst);
75 assert(f.test_and_set() == 0);
Howard Hinnant748a5272010-09-30 21:05:29 +000076 f.clear(std::memory_order_seq_cst);
77 assert(f.test_and_set() == 0);
78 }
JF Bastien2df59c52019-02-04 20:31:13 +000079
80 return 0;
Howard Hinnant748a5272010-09-30 21:05:29 +000081}