da0f5c3de43bf3721a543e74220d563d8711f2eb
[llvm-toolchain-7.git] /
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 //  ... assertion fails line 34
12
13 // <atomic>
14
15 // template <class T>
16 //     bool
17 //     atomic_compare_exchange_weak(volatile atomic<T>* obj, T* expc, T desr);
18 //
19 // template <class T>
20 //     bool
21 //     atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr);
22
23 #include <atomic>
24 #include <type_traits>
25 #include <cassert>
26
27 #include <cmpxchg_loop.h>
28 #include "atomic_helpers.h"
29
30 template <class T>
31 struct TestFn {
32   void operator()() const {
33     {
34         typedef std::atomic<T> A;
35         A a;
36         T t(T(1));
37         std::atomic_init(&a, t);
38         assert(c_cmpxchg_weak_loop(&a, &t, T(2)) == true);
39         assert(a == T(2));
40         assert(t == T(1));
41         assert(std::atomic_compare_exchange_weak(&a, &t, T(3)) == false);
42         assert(a == T(2));
43         assert(t == T(2));
44     }
45     {
46         typedef std::atomic<T> A;
47         volatile A a;
48         T t(T(1));
49         std::atomic_init(&a, t);
50         assert(c_cmpxchg_weak_loop(&a, &t, T(2)) == true);
51         assert(a == T(2));
52         assert(t == T(1));
53         assert(std::atomic_compare_exchange_weak(&a, &t, T(3)) == false);
54         assert(a == T(2));
55         assert(t == T(2));
56     }
57   }
58 };
59
60 int main()
61 {
62     TestEachAtomicType<TestFn>()();
63 }