Howard Hinnant | 748a527 | 2010-09-30 21:05:29 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Howard Hinnant | 748a527 | 2010-09-30 21:05:29 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
Jonathan Roelofs | b3fcc67 | 2014-09-05 19:45:05 +0000 | [diff] [blame] | 8 | // |
| 9 | // UNSUPPORTED: libcpp-has-no-threads |
Howard Hinnant | 748a527 | 2010-09-30 21:05:29 +0000 | [diff] [blame] | 10 | |
| 11 | // <atomic> |
| 12 | |
| 13 | // struct atomic_flag |
| 14 | |
| 15 | // atomic_flag() = default; |
| 16 | |
| 17 | #include <atomic> |
Howard Hinnant | da9ca0b | 2013-05-02 20:18:43 +0000 | [diff] [blame] | 18 | #include <new> |
Howard Hinnant | 748a527 | 2010-09-30 21:05:29 +0000 | [diff] [blame] | 19 | #include <cassert> |
| 20 | |
Eric Fiselier | 6ce45e0 | 2016-10-12 10:19:48 +0000 | [diff] [blame] | 21 | #include "test_macros.h" |
| 22 | |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 23 | int main(int, char**) |
Howard Hinnant | 748a527 | 2010-09-30 21:05:29 +0000 | [diff] [blame] | 24 | { |
| 25 | std::atomic_flag f; |
Eric Fiselier | b67e689 | 2015-07-18 21:40:37 +0000 | [diff] [blame] | 26 | f.clear(); |
| 27 | assert(f.test_and_set() == 0); |
Howard Hinnant | da9ca0b | 2013-05-02 20:18:43 +0000 | [diff] [blame] | 28 | { |
| 29 | typedef std::atomic_flag A; |
Eric Fiselier | 6ce45e0 | 2016-10-12 10:19:48 +0000 | [diff] [blame] | 30 | TEST_ALIGNAS_TYPE(A) char storage[sizeof(A)] = {1}; |
Howard Hinnant | da9ca0b | 2013-05-02 20:18:43 +0000 | [diff] [blame] | 31 | A& zero = *new (storage) A(); |
| 32 | assert(!zero.test_and_set()); |
| 33 | zero.~A(); |
| 34 | } |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 35 | |
| 36 | return 0; |
Howard Hinnant | 748a527 | 2010-09-30 21:05:29 +0000 | [diff] [blame] | 37 | } |