Howard Hinnant | 748a527 | 2010-09-30 21:05:29 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | 412dbeb | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | 748a527 | 2010-09-30 21:05:29 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Jonathan Roelofs | b3fcc67 | 2014-09-05 19:45:05 +0000 | [diff] [blame] | 9 | // |
| 10 | // UNSUPPORTED: libcpp-has-no-threads |
Howard Hinnant | 748a527 | 2010-09-30 21:05:29 +0000 | [diff] [blame] | 11 | |
| 12 | // <atomic> |
| 13 | |
| 14 | // struct atomic_flag |
| 15 | |
| 16 | // atomic_flag() = default; |
| 17 | |
| 18 | #include <atomic> |
Howard Hinnant | da9ca0b | 2013-05-02 20:18:43 +0000 | [diff] [blame] | 19 | #include <new> |
Howard Hinnant | 748a527 | 2010-09-30 21:05:29 +0000 | [diff] [blame] | 20 | #include <cassert> |
| 21 | |
Eric Fiselier | 6ce45e0 | 2016-10-12 10:19:48 +0000 | [diff] [blame] | 22 | #include "test_macros.h" |
| 23 | |
Howard Hinnant | 748a527 | 2010-09-30 21:05:29 +0000 | [diff] [blame] | 24 | int main() |
| 25 | { |
| 26 | std::atomic_flag f; |
Eric Fiselier | b67e689 | 2015-07-18 21:40:37 +0000 | [diff] [blame] | 27 | f.clear(); |
| 28 | assert(f.test_and_set() == 0); |
Howard Hinnant | da9ca0b | 2013-05-02 20:18:43 +0000 | [diff] [blame] | 29 | { |
| 30 | typedef std::atomic_flag A; |
Eric Fiselier | 6ce45e0 | 2016-10-12 10:19:48 +0000 | [diff] [blame] | 31 | TEST_ALIGNAS_TYPE(A) char storage[sizeof(A)] = {1}; |
Howard Hinnant | da9ca0b | 2013-05-02 20:18:43 +0000 | [diff] [blame] | 32 | A& zero = *new (storage) A(); |
| 33 | assert(!zero.test_and_set()); |
| 34 | zero.~A(); |
| 35 | } |
Howard Hinnant | 748a527 | 2010-09-30 21:05:29 +0000 | [diff] [blame] | 36 | } |