~ubuntu-branches/ubuntu/saucy/libc++/saucy-proposed

« back to all changes in this revision

Viewing changes to libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_strong_explicit.pass.cpp

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru, Andrej Belym
  • Date: 2012-08-01 10:38:08 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120801103808-n4qy15hxyhj3vxgi
Tags: 1.0~svn161106-1~exp1
* New snapshot release

[ Andrej Belym ]
* Multiarch support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
 
17
//                                         shared_ptr<T> w, memory_order success,
 
18
//                                         memory_order failure);
 
19
 
 
20
#include <memory>
 
21
#include <cassert>
 
22
 
 
23
int main()
 
24
{
 
25
#if __has_feature(cxx_atomic)
 
26
    {
 
27
        std::shared_ptr<int> p(new int(4));
 
28
        std::shared_ptr<int> v(new int(3));
 
29
        std::shared_ptr<int> w(new int(2));
 
30
        bool b = std::atomic_compare_exchange_strong_explicit(&p, &v, w,
 
31
                                                              std::memory_order_seq_cst,
 
32
                                                              std::memory_order_seq_cst);
 
33
        assert(b == false);
 
34
        assert(*p == 4);
 
35
        assert(*v == 4);
 
36
        assert(*w == 2);
 
37
    }
 
38
    {
 
39
        std::shared_ptr<int> p(new int(4));
 
40
        std::shared_ptr<int> v = p;
 
41
        std::shared_ptr<int> w(new int(2));
 
42
        bool b = std::atomic_compare_exchange_strong_explicit(&p, &v, w,
 
43
                                                              std::memory_order_seq_cst,
 
44
                                                              std::memory_order_seq_cst);
 
45
        assert(b == true);
 
46
        assert(*p == 2);
 
47
        assert(*v == 4);
 
48
        assert(*w == 2);
 
49
    }
 
50
#endif
 
51
}