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 //===----------------------------------------------------------------------===//
9 //
10 // UNSUPPORTED: libcpp-has-no-threads
11 //  ... fails assertion line 31
12 
13 // <atomic>
14 
15 // template <class T>
16 //     T
17 //     atomic_exchange(volatile atomic<T>* obj, T desr);
18 //
19 // template <class T>
20 //     T
21 //     atomic_exchange(atomic<T>* obj, T desr);
22 
23 #include <atomic>
24 #include <type_traits>
25 #include <cassert>
26 
27 #include "atomic_helpers.h"
28 
29 template <class T>
30 struct TestFn {
operator ()TestFn31   void operator()() const {
32     typedef std::atomic<T> A;
33     A t;
34     std::atomic_init(&t, T(1));
35     assert(std::atomic_exchange(&t, T(2)) == T(1));
36     assert(t == T(2));
37     volatile A vt;
38     std::atomic_init(&vt, T(3));
39     assert(std::atomic_exchange(&vt, T(4)) == T(3));
40     assert(vt == T(4));
41   }
42 };
43 
44 
main()45 int main()
46 {
47     TestEachAtomicType<TestFn>()();
48 }
49