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 34
     12 
     13 // <atomic>
     14 
     15 // template <class T>
     16 //     bool
     17 //     atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr);
     18 //
     19 // template <class T>
     20 //     bool
     21 //     atomic_compare_exchange_strong(atomic<T>* obj, T* expc, 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 {
     31   void operator()() const {
     32     {
     33         typedef std::atomic<T> A;
     34         A a;
     35         T t(T(1));
     36         std::atomic_init(&a, t);
     37         assert(std::atomic_compare_exchange_strong(&a, &t, T(2)) == true);
     38         assert(a == T(2));
     39         assert(t == T(1));
     40         assert(std::atomic_compare_exchange_strong(&a, &t, T(3)) == false);
     41         assert(a == T(2));
     42         assert(t == T(2));
     43     }
     44     {
     45         typedef std::atomic<T> A;
     46         volatile A a;
     47         T t(T(1));
     48         std::atomic_init(&a, t);
     49         assert(std::atomic_compare_exchange_strong(&a, &t, T(2)) == true);
     50         assert(a == T(2));
     51         assert(t == T(1));
     52         assert(std::atomic_compare_exchange_strong(&a, &t, T(3)) == false);
     53         assert(a == T(2));
     54         assert(t == T(2));
     55     }
     56   }
     57 };
     58 
     59 int main()
     60 {
     61     TestEachAtomicType<TestFn>()();
     62 }
     63