Home | History | Annotate | Download | only in atomics.types.operations.req
      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 32
     12 
     13 // <atomic>
     14 
     15 // template <class T>
     16 //     T
     17 //     atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m);
     18 //
     19 // template <class T>
     20 //     T
     21 //     atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m);
     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 {
     31   void operator()() const {
     32     typedef std::atomic<T> A;
     33     A t;
     34     std::atomic_init(&t, T(1));
     35     assert(std::atomic_exchange_explicit(&t, T(2), std::memory_order_seq_cst)
     36            == T(1));
     37     assert(t == T(2));
     38     volatile A vt;
     39     std::atomic_init(&vt, T(3));
     40     assert(std::atomic_exchange_explicit(&vt, T(4), std::memory_order_seq_cst)
     41            == T(3));
     42     assert(vt == T(4));
     43   }
     44 };
     45 
     46 
     47 int main()
     48 {
     49     TestEachAtomicType<TestFn>()();
     50 }
     51