blob: d83bbf264de520a376876fef77b1d12ece3e7572 [file] [log] [blame]
Howard Hinnant91e2f262010-12-07 20:46:14 +00001//===----------------------------------------------------------------------===//
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 Roelofs8d86b2e2014-09-05 19:45:05 +00009//
10// UNSUPPORTED: libcpp-has-no-threads
Howard Hinnant91e2f262010-12-07 20:46:14 +000011
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 Smith9efdc0b2012-04-19 00:50:47 +000023#include <type_traits>
Howard Hinnant91e2f262010-12-07 20:46:14 +000024#include <cassert>
25
26template <class T>
Dan Albert1d4a1ed2016-05-25 22:36:09 -070027void
28test()
29{
Howard Hinnant91e2f262010-12-07 20:46:14 +000030 {
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 Albert1d4a1ed2016-05-25 22:36:09 -070046}
Howard Hinnant91e2f262010-12-07 20:46:14 +000047
48int main()
49{
Dan Albert1d4a1ed2016-05-25 22:36:09 -070050 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 Hinnant91e2f262010-12-07 20:46:14 +000066}