blob: ea5ae45ae99a0e384d3f30b25c171ed0c18deaa6 [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 Fiselier749adeb2015-08-19 17:21:46 +000025 std::atomic_flag f(false);
Howard Hinnant748a5272010-09-30 21:05:29 +000026 f.test_and_set();
27 f.clear();
28 assert(f.test_and_set() == 0);
29 }
30 {
Eric Fiselier749adeb2015-08-19 17:21:46 +000031 std::atomic_flag f(false);
Howard Hinnant748a5272010-09-30 21:05:29 +000032 f.test_and_set();
33 f.clear(std::memory_order_relaxed);
34 assert(f.test_and_set() == 0);
35 }
36 {
Eric Fiselier749adeb2015-08-19 17:21:46 +000037 std::atomic_flag f(false);
Howard Hinnant748a5272010-09-30 21:05:29 +000038 f.test_and_set();
Howard Hinnant748a5272010-09-30 21:05:29 +000039 f.clear(std::memory_order_release);
40 assert(f.test_and_set() == 0);
41 }
42 {
Eric Fiselier749adeb2015-08-19 17:21:46 +000043 std::atomic_flag f(false);
Howard Hinnant748a5272010-09-30 21:05:29 +000044 f.test_and_set();
45 f.clear(std::memory_order_seq_cst);
46 assert(f.test_and_set() == 0);
47 }
48 {
Eric Fiselier749adeb2015-08-19 17:21:46 +000049 volatile std::atomic_flag f(false);
Howard Hinnant748a5272010-09-30 21:05:29 +000050 f.test_and_set();
51 f.clear();
52 assert(f.test_and_set() == 0);
53 }
54 {
Eric Fiselier749adeb2015-08-19 17:21:46 +000055 volatile std::atomic_flag f(false);
Howard Hinnant748a5272010-09-30 21:05:29 +000056 f.test_and_set();
57 f.clear(std::memory_order_relaxed);
58 assert(f.test_and_set() == 0);
59 }
60 {
Eric Fiselier749adeb2015-08-19 17:21:46 +000061 volatile std::atomic_flag f(false);
Howard Hinnant748a5272010-09-30 21:05:29 +000062 f.test_and_set();
Howard Hinnant748a5272010-09-30 21:05:29 +000063 f.clear(std::memory_order_release);
64 assert(f.test_and_set() == 0);
65 }
66 {
Eric Fiselier749adeb2015-08-19 17:21:46 +000067 volatile std::atomic_flag f(false);
Howard Hinnant748a5272010-09-30 21:05:29 +000068 f.test_and_set();
69 f.clear(std::memory_order_seq_cst);
70 assert(f.test_and_set() == 0);
71 }
72}