| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // UNSUPPORTED: no-threads |
| 10 | |
| 11 | // <memory> |
| 12 | |
| 13 | // shared_ptr |
| 14 | |
| 15 | // template <class T> |
| 16 | // bool |
| 17 | // atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v, |
| 18 | // shared_ptr<T> w, memory_order success, |
| 19 | // memory_order failure); |
| 20 | |
| 21 | // UNSUPPORTED: c++03 |
| 22 | |
| 23 | #include <memory> |
| 24 | |
| 25 | #include <atomic> |
| 26 | #include <cassert> |
| 27 | |
| 28 | #include "test_macros.h" |
| 29 | |
| 30 | int main(int, char**) |
| 31 | { |
| 32 | { |
| 33 | std::shared_ptr<int> p(new int(4)); |
| 34 | std::shared_ptr<int> v(new int(3)); |
| 35 | std::shared_ptr<int> w(new int(2)); |
| 36 | bool b = std::atomic_compare_exchange_weak_explicit(&p, &v, w, |
| 37 | std::memory_order_seq_cst, |
| 38 | std::memory_order_seq_cst); |
| 39 | assert(b == false); |
| 40 | assert(*p == 4); |
| 41 | assert(*v == 4); |
| 42 | assert(*w == 2); |
| 43 | } |
| 44 | { |
| 45 | std::shared_ptr<int> p(new int(4)); |
| 46 | std::shared_ptr<int> v = p; |
| 47 | std::shared_ptr<int> w(new int(2)); |
| 48 | bool b = std::atomic_compare_exchange_weak_explicit(&p, &v, w, |
| 49 | std::memory_order_seq_cst, |
| 50 | std::memory_order_seq_cst); |
| 51 | assert(b == true); |
| 52 | assert(*p == 2); |
| 53 | assert(*v == 4); |
| 54 | assert(*w == 2); |
| 55 | } |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |