Home | History | Annotate | Download | only in util.smartptr.shared.atomic
      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 // <memory>
     11 
     12 // shared_ptr
     13 
     14 // template <class T>
     15 // bool
     16 // atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v,
     17 //                              shared_ptr<T> w);
     18 
     19 #include <memory>
     20 #include <cassert>
     21 
     22 int main()
     23 {
     24 #if __has_feature(cxx_atomic)
     25     {
     26         std::shared_ptr<int> p(new int(4));
     27         std::shared_ptr<int> v(new int(3));
     28         std::shared_ptr<int> w(new int(2));
     29         bool b = std::atomic_compare_exchange_weak(&p, &v, w);
     30         assert(b == false);
     31         assert(*p == 4);
     32         assert(*v == 4);
     33         assert(*w == 2);
     34     }
     35     {
     36         std::shared_ptr<int> p(new int(4));
     37         std::shared_ptr<int> v = p;
     38         std::shared_ptr<int> w(new int(2));
     39         bool b = std::atomic_compare_exchange_weak(&p, &v, w);
     40         assert(b == true);
     41         assert(*p == 2);
     42         assert(*v == 4);
     43         assert(*w == 2);
     44     }
     45 #endif
     46 }
     47