File indexing completed on 2025-01-18 09:51:42
0001 #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_ACC_IA64_HPP_INCLUDED
0002 #define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_ACC_IA64_HPP_INCLUDED
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
0019 #include <boost/smart_ptr/detail/sp_obsolete.hpp>
0020 #include <boost/config.hpp>
0021 #include <machine/sys/inline.h>
0022
0023 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
0024
0025 #include <boost/config/pragma_message.hpp>
0026 BOOST_PRAGMA_MESSAGE("Using HP aCC++/HP-UX/IA64 sp_counted_base")
0027
0028 #endif
0029
0030 BOOST_SP_OBSOLETE()
0031
0032 namespace boost
0033 {
0034
0035 namespace detail
0036 {
0037
0038 inline void atomic_increment( int * pw )
0039 {
0040
0041
0042 _Asm_fetchadd(_FASZ_W, _SEM_REL, pw, +1, _LDHINT_NONE);
0043 }
0044
0045 inline int atomic_decrement( int * pw )
0046 {
0047
0048
0049 int r = static_cast<int>(_Asm_fetchadd(_FASZ_W, _SEM_REL, pw, -1, _LDHINT_NONE));
0050 if (1 == r)
0051 {
0052 _Asm_mf();
0053 }
0054
0055 return r - 1;
0056 }
0057
0058 inline int atomic_conditional_increment( int * pw )
0059 {
0060
0061
0062
0063 int v = *pw;
0064
0065 for (;;)
0066 {
0067 if (0 == v)
0068 {
0069 return 0;
0070 }
0071
0072 _Asm_mov_to_ar(_AREG_CCV,
0073 v,
0074 (_UP_CALL_FENCE | _UP_SYS_FENCE | _DOWN_CALL_FENCE | _DOWN_SYS_FENCE));
0075 int r = static_cast<int>(_Asm_cmpxchg(_SZ_W, _SEM_ACQ, pw, v + 1, _LDHINT_NONE));
0076 if (r == v)
0077 {
0078 return r + 1;
0079 }
0080
0081 v = r;
0082 }
0083 }
0084
0085 class BOOST_SYMBOL_VISIBLE sp_counted_base
0086 {
0087 private:
0088
0089 sp_counted_base( sp_counted_base const & );
0090 sp_counted_base & operator= ( sp_counted_base const & );
0091
0092 int use_count_;
0093 int weak_count_;
0094
0095 public:
0096
0097 sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
0098 {
0099 }
0100
0101 virtual ~sp_counted_base()
0102 {
0103 }
0104
0105
0106
0107
0108 virtual void dispose() = 0;
0109
0110
0111
0112 virtual void destroy()
0113 {
0114 delete this;
0115 }
0116
0117 virtual void * get_deleter( sp_typeinfo_ const & ti ) = 0;
0118 virtual void * get_local_deleter( sp_typeinfo_ const & ti ) = 0;
0119 virtual void * get_untyped_deleter() = 0;
0120
0121 void add_ref_copy()
0122 {
0123 atomic_increment( &use_count_ );
0124 }
0125
0126 bool add_ref_lock()
0127 {
0128 return atomic_conditional_increment( &use_count_ ) != 0;
0129 }
0130
0131 void release()
0132 {
0133 if( atomic_decrement( &use_count_ ) == 0 )
0134 {
0135 dispose();
0136 weak_release();
0137 }
0138 }
0139
0140 void weak_add_ref()
0141 {
0142 atomic_increment( &weak_count_ );
0143 }
0144
0145 void weak_release()
0146 {
0147 if( atomic_decrement( &weak_count_ ) == 0 )
0148 {
0149 destroy();
0150 }
0151 }
0152
0153 long use_count() const
0154 {
0155 return static_cast<int const volatile &>( use_count_ );
0156 }
0157 };
0158
0159 }
0160
0161 }
0162
0163 #endif