]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/smart_ptr/detail/sp_counted_base_acc_ia64.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / smart_ptr / detail / sp_counted_base_acc_ia64.hpp
CommitLineData
7c673cae
FG
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
92f5a8d4
TL
18#include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
19#include <boost/config.hpp>
7c673cae
FG
20#include <machine/sys/inline.h>
21
22namespace boost
23{
24
25namespace detail
26{
27
28inline void atomic_increment( int * pw )
29{
30 // ++*pw;
31
32 _Asm_fetchadd(_FASZ_W, _SEM_REL, pw, +1, _LDHINT_NONE);
33}
34
35inline int atomic_decrement( int * pw )
36{
37 // return --*pw;
38
39 int r = static_cast<int>(_Asm_fetchadd(_FASZ_W, _SEM_REL, pw, -1, _LDHINT_NONE));
40 if (1 == r)
41 {
42 _Asm_mf();
43 }
44
45 return r - 1;
46}
47
48inline int atomic_conditional_increment( int * pw )
49{
50 // if( *pw != 0 ) ++*pw;
51 // return *pw;
52
53 int v = *pw;
54
55 for (;;)
56 {
57 if (0 == v)
58 {
59 return 0;
60 }
61
62 _Asm_mov_to_ar(_AREG_CCV,
63 v,
64 (_UP_CALL_FENCE | _UP_SYS_FENCE | _DOWN_CALL_FENCE | _DOWN_SYS_FENCE));
65 int r = static_cast<int>(_Asm_cmpxchg(_SZ_W, _SEM_ACQ, pw, v + 1, _LDHINT_NONE));
66 if (r == v)
67 {
68 return r + 1;
69 }
70
71 v = r;
72 }
73}
74
92f5a8d4 75class BOOST_SYMBOL_VISIBLE sp_counted_base
7c673cae
FG
76{
77private:
78
79 sp_counted_base( sp_counted_base const & );
80 sp_counted_base & operator= ( sp_counted_base const & );
81
82 int use_count_; // #shared
83 int weak_count_; // #weak + (#shared != 0)
84
85public:
86
87 sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
88 {
89 }
90
91 virtual ~sp_counted_base() // nothrow
92 {
93 }
94
95 // dispose() is called when use_count_ drops to zero, to release
96 // the resources managed by *this.
97
98 virtual void dispose() = 0; // nothrow
99
100 // destroy() is called when weak_count_ drops to zero.
101
102 virtual void destroy() // nothrow
103 {
104 delete this;
105 }
106
92f5a8d4
TL
107 virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
108 virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
7c673cae
FG
109 virtual void * get_untyped_deleter() = 0;
110
111 void add_ref_copy()
112 {
113 atomic_increment( &use_count_ );
114 }
115
116 bool add_ref_lock() // true on success
117 {
118 return atomic_conditional_increment( &use_count_ ) != 0;
119 }
120
121 void release() // nothrow
122 {
123 if( atomic_decrement( &use_count_ ) == 0 )
124 {
125 dispose();
126 weak_release();
127 }
128 }
129
130 void weak_add_ref() // nothrow
131 {
132 atomic_increment( &weak_count_ );
133 }
134
135 void weak_release() // nothrow
136 {
137 if( atomic_decrement( &weak_count_ ) == 0 )
138 {
139 destroy();
140 }
141 }
142
143 long use_count() const // nothrow
144 {
145 return static_cast<int const volatile &>( use_count_ ); // TODO use ld.acq here
146 }
147};
148
149} // namespace detail
150
151} // namespace boost
152
153#endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_ACC_IA64_HPP_INCLUDED