]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/smart_ptr/detail/sp_counted_base_acc_ia64.hpp
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / boost / boost / smart_ptr / detail / sp_counted_base_acc_ia64.hpp
1 #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_ACC_IA64_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_ACC_IA64_HPP_INCLUDED
3
4 //
5 // detail/sp_counted_base_acc_ia64.hpp - aC++ on HP-UX IA64
6 //
7 // Copyright 2007 Baruch Zilber
8 // Copyright 2007 Boris Gubenko
9 //
10 // Distributed under the Boost Software License, Version 1.0. (See
11 // accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
13 //
14 //
15 // Lock-free algorithm by Alexander Terekhov
16 //
17
18 #include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
19 #include <boost/smart_ptr/detail/sp_obsolete.hpp>
20 #include <boost/config.hpp>
21 #include <machine/sys/inline.h>
22
23 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
24
25 #include <boost/config/pragma_message.hpp>
26 BOOST_PRAGMA_MESSAGE("Using HP aCC++/HP-UX/IA64 sp_counted_base")
27
28 #endif
29
30 BOOST_SP_OBSOLETE()
31
32 namespace boost
33 {
34
35 namespace detail
36 {
37
38 inline void atomic_increment( int * pw )
39 {
40 // ++*pw;
41
42 _Asm_fetchadd(_FASZ_W, _SEM_REL, pw, +1, _LDHINT_NONE);
43 }
44
45 inline int atomic_decrement( int * pw )
46 {
47 // return --*pw;
48
49 int r = static_cast<int>(_Asm_fetchadd(_FASZ_W, _SEM_REL, pw, -1, _LDHINT_NONE));
50 if (1 == r)
51 {
52 _Asm_mf();
53 }
54
55 return r - 1;
56 }
57
58 inline int atomic_conditional_increment( int * pw )
59 {
60 // if( *pw != 0 ) ++*pw;
61 // return *pw;
62
63 int v = *pw;
64
65 for (;;)
66 {
67 if (0 == v)
68 {
69 return 0;
70 }
71
72 _Asm_mov_to_ar(_AREG_CCV,
73 v,
74 (_UP_CALL_FENCE | _UP_SYS_FENCE | _DOWN_CALL_FENCE | _DOWN_SYS_FENCE));
75 int r = static_cast<int>(_Asm_cmpxchg(_SZ_W, _SEM_ACQ, pw, v + 1, _LDHINT_NONE));
76 if (r == v)
77 {
78 return r + 1;
79 }
80
81 v = r;
82 }
83 }
84
85 class BOOST_SYMBOL_VISIBLE sp_counted_base
86 {
87 private:
88
89 sp_counted_base( sp_counted_base const & );
90 sp_counted_base & operator= ( sp_counted_base const & );
91
92 int use_count_; // #shared
93 int weak_count_; // #weak + (#shared != 0)
94
95 public:
96
97 sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
98 {
99 }
100
101 virtual ~sp_counted_base() // nothrow
102 {
103 }
104
105 // dispose() is called when use_count_ drops to zero, to release
106 // the resources managed by *this.
107
108 virtual void dispose() = 0; // nothrow
109
110 // destroy() is called when weak_count_ drops to zero.
111
112 virtual void destroy() // nothrow
113 {
114 delete this;
115 }
116
117 virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
118 virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
119 virtual void * get_untyped_deleter() = 0;
120
121 void add_ref_copy()
122 {
123 atomic_increment( &use_count_ );
124 }
125
126 bool add_ref_lock() // true on success
127 {
128 return atomic_conditional_increment( &use_count_ ) != 0;
129 }
130
131 void release() // nothrow
132 {
133 if( atomic_decrement( &use_count_ ) == 0 )
134 {
135 dispose();
136 weak_release();
137 }
138 }
139
140 void weak_add_ref() // nothrow
141 {
142 atomic_increment( &weak_count_ );
143 }
144
145 void weak_release() // nothrow
146 {
147 if( atomic_decrement( &weak_count_ ) == 0 )
148 {
149 destroy();
150 }
151 }
152
153 long use_count() const // nothrow
154 {
155 return static_cast<int const volatile &>( use_count_ ); // TODO use ld.acq here
156 }
157 };
158
159 } // namespace detail
160
161 } // namespace boost
162
163 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_ACC_IA64_HPP_INCLUDED