Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Jonathan Roelofs | 8d86b2e | 2014-09-05 19:45:05 +0000 | [diff] [blame] | 9 | // |
| 10 | // UNSUPPORTED: libcpp-has-no-threads |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 11 | |
| 12 | // <atomic> |
| 13 | |
| 14 | // template <class Integral> |
| 15 | // Integral |
| 16 | // atomic_fetch_and_explicit(volatile atomic<Integral>* obj, Integral op); |
| 17 | // |
| 18 | // template <class Integral> |
| 19 | // Integral |
| 20 | // atomic_fetch_and_explicit(atomic<Integral>* obj, Integral op); |
| 21 | |
| 22 | #include <atomic> |
Richard Smith | 9efdc0b | 2012-04-19 00:50:47 +0000 | [diff] [blame] | 23 | #include <type_traits> |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 24 | #include <cassert> |
| 25 | |
| 26 | template <class T> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 27 | void |
| 28 | test() |
| 29 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 30 | { |
| 31 | typedef std::atomic<T> A; |
| 32 | A t; |
| 33 | std::atomic_init(&t, T(1)); |
| 34 | assert(std::atomic_fetch_and_explicit(&t, T(2), |
| 35 | std::memory_order_seq_cst) == T(1)); |
| 36 | assert(t == T(0)); |
| 37 | } |
| 38 | { |
| 39 | typedef std::atomic<T> A; |
| 40 | volatile A t; |
| 41 | std::atomic_init(&t, T(3)); |
| 42 | assert(std::atomic_fetch_and_explicit(&t, T(2), |
| 43 | std::memory_order_seq_cst) == T(3)); |
| 44 | assert(t == T(2)); |
| 45 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 46 | } |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 47 | |
| 48 | int main() |
| 49 | { |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 50 | test<char>(); |
| 51 | test<signed char>(); |
| 52 | test<unsigned char>(); |
| 53 | test<short>(); |
| 54 | test<unsigned short>(); |
| 55 | test<int>(); |
| 56 | test<unsigned int>(); |
| 57 | test<long>(); |
| 58 | test<unsigned long>(); |
| 59 | test<long long>(); |
| 60 | test<unsigned long long>(); |
| 61 | test<wchar_t>(); |
| 62 | #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS |
| 63 | test<char16_t>(); |
| 64 | test<char32_t>(); |
| 65 | #endif // _LIBCPP_HAS_NO_UNICODE_CHARS |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 66 | } |