blob: 92e57ecc03f867a94652ce9000461ea081232bd0 [file] [log] [blame]
Howard Hinnant79101ae2010-09-30 21:05:29 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-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 Hinnant79101ae2010-09-30 21:05:29 +00007//
8//===----------------------------------------------------------------------===//
Jonathan Roelofs8d86b2e2014-09-05 19:45:05 +00009//
10// UNSUPPORTED: libcpp-has-no-threads
Howard Hinnant79101ae2010-09-30 21:05:29 +000011
12// <atomic>
13
14// struct atomic_flag
15
16// void atomic_flag_clear_explicit(volatile atomic_flag*, memory_order);
17// void atomic_flag_clear_explicit(atomic_flag*, memory_order);
18
19#include <atomic>
20#include <cassert>
21
22int main()
23{
24 {
Dan Albert1d4a1ed2016-05-25 22:36:09 -070025 std::atomic_flag f = ATOMIC_FLAG_INIT;
Howard Hinnant79101ae2010-09-30 21:05:29 +000026 f.test_and_set();
27 atomic_flag_clear_explicit(&f, std::memory_order_relaxed);
28 assert(f.test_and_set() == 0);
29 }
30 {
Dan Albert1d4a1ed2016-05-25 22:36:09 -070031 std::atomic_flag f = ATOMIC_FLAG_INIT;
Howard Hinnant79101ae2010-09-30 21:05:29 +000032 f.test_and_set();
Howard Hinnant79101ae2010-09-30 21:05:29 +000033 atomic_flag_clear_explicit(&f, std::memory_order_release);
34 assert(f.test_and_set() == 0);
35 }
36 {
Dan Albert1d4a1ed2016-05-25 22:36:09 -070037 std::atomic_flag f = ATOMIC_FLAG_INIT;
Howard Hinnant79101ae2010-09-30 21:05:29 +000038 f.test_and_set();
39 atomic_flag_clear_explicit(&f, std::memory_order_seq_cst);
40 assert(f.test_and_set() == 0);
41 }
42 {
Dan Albert1d4a1ed2016-05-25 22:36:09 -070043 volatile std::atomic_flag f = ATOMIC_FLAG_INIT;
Howard Hinnant79101ae2010-09-30 21:05:29 +000044 f.test_and_set();
45 atomic_flag_clear_explicit(&f, std::memory_order_relaxed);
46 assert(f.test_and_set() == 0);
47 }
48 {
Dan Albert1d4a1ed2016-05-25 22:36:09 -070049 volatile std::atomic_flag f = ATOMIC_FLAG_INIT;
Howard Hinnant79101ae2010-09-30 21:05:29 +000050 f.test_and_set();
Howard Hinnant79101ae2010-09-30 21:05:29 +000051 atomic_flag_clear_explicit(&f, std::memory_order_release);
52 assert(f.test_and_set() == 0);
53 }
54 {
Dan Albert1d4a1ed2016-05-25 22:36:09 -070055 volatile std::atomic_flag f = ATOMIC_FLAG_INIT;
Howard Hinnant79101ae2010-09-30 21:05:29 +000056 f.test_and_set();
57 atomic_flag_clear_explicit(&f, std::memory_order_seq_cst);
58 assert(f.test_and_set() == 0);
59 }
60}