1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: libcpp-has-no-threads
11 // ... assertion fails line 38
17 // atomic_compare_exchange_weak_explicit(volatile atomic<T>* obj, T* expc,
19 // memory_order s, memory_order f);
23 // atomic_compare_exchange_weak_explicit(atomic<T>* obj, T* expc, T desr,
24 // memory_order s, memory_order f);
27 #include <type_traits>
30 #include <cmpxchg_loop.h>
32 #include "atomic_helpers.h"
36 void operator()() const {
38 typedef std::atomic<T> A;
41 std::atomic_init(&a, t);
42 assert(c_cmpxchg_weak_loop(&a, &t, T(2),
43 std::memory_order_seq_cst, std::memory_order_seq_cst) == true);
46 assert(std::atomic_compare_exchange_weak_explicit(&a, &t, T(3),
47 std::memory_order_seq_cst, std::memory_order_seq_cst) == false);
52 typedef std::atomic<T> A;
55 std::atomic_init(&a, t);
56 assert(c_cmpxchg_weak_loop(&a, &t, T(2),
57 std::memory_order_seq_cst, std::memory_order_seq_cst) == true);
60 assert(std::atomic_compare_exchange_weak_explicit(&a, &t, T(3),
61 std::memory_order_seq_cst, std::memory_order_seq_cst) == false);
70 TestEachAtomicType<TestFn>()();