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 // This test uses new symbols that were not defined in the libc++ shipped on
     11 // darwin11 and darwin12:
     12 // XFAIL: with_system_lib=x86_64-apple-darwin11
     13 // XFAIL: with_system_lib=x86_64-apple-darwin12
     14 
     15 // <memory>
     16 
     17 // shared_ptr
     18 
     19 // template <class T>
     20 // bool
     21 // atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
     22 //                                       shared_ptr<T> w, memory_order success,
     23 //                                       memory_order failure);
     24 
     25 #include <memory>
     26 #include <cassert>
     27 
     28 int main()
     29 {
     30 #if __has_feature(cxx_atomic)
     31     {
     32         std::shared_ptr<int> p(new int(4));
     33         std::shared_ptr<int> v(new int(3));
     34         std::shared_ptr<int> w(new int(2));
     35         bool b = std::atomic_compare_exchange_weak_explicit(&p, &v, w,
     36                                                             std::memory_order_seq_cst,
     37                                                             std::memory_order_seq_cst);
     38         assert(b == false);
     39         assert(*p == 4);
     40         assert(*v == 4);
     41         assert(*w == 2);
     42     }
     43     {
     44         std::shared_ptr<int> p(new int(4));
     45         std::shared_ptr<int> v = p;
     46         std::shared_ptr<int> w(new int(2));
     47         bool b = std::atomic_compare_exchange_weak_explicit(&p, &v, w,
     48                                                             std::memory_order_seq_cst,
     49                                                             std::memory_order_seq_cst);
     50         assert(b == true);
     51         assert(*p == 2);
     52         assert(*v == 4);
     53         assert(*w == 2);
     54     }
     55 #endif
     56 }
     57