blob: 255af8f176ea670d946714246951af0d9af6b96a [file] [log] [blame]
Howard Hinnant748a5272010-09-30 21:05:29 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnant412dbeb2010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant748a5272010-09-30 21:05:29 +00007//
8//===----------------------------------------------------------------------===//
Jonathan Roelofsb3fcc672014-09-05 19:45:05 +00009//
10// UNSUPPORTED: libcpp-has-no-threads
Howard Hinnant748a5272010-09-30 21:05:29 +000011
12// <atomic>
13
14// struct atomic_flag
15
16// void clear(memory_order = memory_order_seq_cst);
17// void clear(memory_order = memory_order_seq_cst) volatile;
18
19#include <atomic>
20#include <cassert>
21
22int main()
23{
24 {
Eric Fiselier990952b2016-06-19 07:08:27 +000025 std::atomic_flag f; // uninitialized
26 f.clear();
27 assert(f.test_and_set() == 0);
Howard Hinnant748a5272010-09-30 21:05:29 +000028 f.clear();
29 assert(f.test_and_set() == 0);
30 }
31 {
Eric Fiselier15a29722016-05-03 02:12:26 +000032 std::atomic_flag f;
Eric Fiselier990952b2016-06-19 07:08:27 +000033 f.clear(std::memory_order_relaxed);
34 assert(f.test_and_set() == 0);
Howard Hinnant748a5272010-09-30 21:05:29 +000035 f.clear(std::memory_order_relaxed);
36 assert(f.test_and_set() == 0);
37 }
38 {
Eric Fiselier15a29722016-05-03 02:12:26 +000039 std::atomic_flag f;
Eric Fiselier990952b2016-06-19 07:08:27 +000040 f.clear(std::memory_order_release);
41 assert(f.test_and_set() == 0);
Howard Hinnant748a5272010-09-30 21:05:29 +000042 f.clear(std::memory_order_release);
43 assert(f.test_and_set() == 0);
44 }
45 {
Eric Fiselier15a29722016-05-03 02:12:26 +000046 std::atomic_flag f;
Eric Fiselier990952b2016-06-19 07:08:27 +000047 f.clear(std::memory_order_seq_cst);
48 assert(f.test_and_set() == 0);
Howard Hinnant748a5272010-09-30 21:05:29 +000049 f.clear(std::memory_order_seq_cst);
50 assert(f.test_and_set() == 0);
51 }
52 {
Eric Fiselier15a29722016-05-03 02:12:26 +000053 volatile std::atomic_flag f;
Eric Fiselier990952b2016-06-19 07:08:27 +000054 f.clear();
55 assert(f.test_and_set() == 0);
Howard Hinnant748a5272010-09-30 21:05:29 +000056 f.clear();
57 assert(f.test_and_set() == 0);
58 }
59 {
Eric Fiselier15a29722016-05-03 02:12:26 +000060 volatile std::atomic_flag f;
Eric Fiselier990952b2016-06-19 07:08:27 +000061 f.clear(std::memory_order_relaxed);
62 assert(f.test_and_set() == 0);
Howard Hinnant748a5272010-09-30 21:05:29 +000063 f.clear(std::memory_order_relaxed);
64 assert(f.test_and_set() == 0);
65 }
66 {
Eric Fiselier15a29722016-05-03 02:12:26 +000067 volatile std::atomic_flag f;
Eric Fiselier990952b2016-06-19 07:08:27 +000068 f.clear(std::memory_order_release);
69 assert(f.test_and_set() == 0);
Howard Hinnant748a5272010-09-30 21:05:29 +000070 f.clear(std::memory_order_release);
71 assert(f.test_and_set() == 0);
72 }
73 {
Eric Fiselier15a29722016-05-03 02:12:26 +000074 volatile std::atomic_flag f;
Eric Fiselier990952b2016-06-19 07:08:27 +000075 f.clear(std::memory_order_seq_cst);
76 assert(f.test_and_set() == 0);
Howard Hinnant748a5272010-09-30 21:05:29 +000077 f.clear(std::memory_order_seq_cst);
78 assert(f.test_and_set() == 0);
79 }
80}