Go to the documentation of this file.00001 #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_ACC_IA64_HPP_INCLUDED
00002 #define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_ACC_IA64_HPP_INCLUDED
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <boost/detail/sp_typeinfo.hpp>
00019 #include <machine/sys/inline.h>
00020
00021 namespace boost
00022 {
00023
00024 namespace detail
00025 {
00026
00027 inline void atomic_increment( int * pw )
00028 {
00029
00030
00031 _Asm_fetchadd(_FASZ_W, _SEM_REL, pw, +1, _LDHINT_NONE);
00032 }
00033
00034 inline int atomic_decrement( int * pw )
00035 {
00036
00037
00038 int r = static_cast<int>(_Asm_fetchadd(_FASZ_W, _SEM_REL, pw, -1, _LDHINT_NONE));
00039 if (1 == r)
00040 {
00041 _Asm_mf();
00042 }
00043
00044 return r - 1;
00045 }
00046
00047 inline int atomic_conditional_increment( int * pw )
00048 {
00049
00050
00051
00052 int v = *pw;
00053
00054 for (;;)
00055 {
00056 if (0 == v)
00057 {
00058 return 0;
00059 }
00060
00061 _Asm_mov_to_ar(_AREG_CCV,
00062 v,
00063 (_UP_CALL_FENCE | _UP_SYS_FENCE | _DOWN_CALL_FENCE | _DOWN_SYS_FENCE));
00064 int r = static_cast<int>(_Asm_cmpxchg(_SZ_W, _SEM_ACQ, pw, v + 1, _LDHINT_NONE));
00065 if (r == v)
00066 {
00067 return r + 1;
00068 }
00069
00070 v = r;
00071 }
00072 }
00073
00074 class sp_counted_base
00075 {
00076 private:
00077
00078 sp_counted_base( sp_counted_base const & );
00079 sp_counted_base & operator= ( sp_counted_base const & );
00080
00081 int use_count_;
00082 int weak_count_;
00083
00084 public:
00085
00086 sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
00087 {
00088 }
00089
00090 virtual ~sp_counted_base()
00091 {
00092 }
00093
00094
00095
00096
00097 virtual void dispose() = 0;
00098
00099
00100
00101 virtual void destroy()
00102 {
00103 delete this;
00104 }
00105
00106 virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
00107
00108 void add_ref_copy()
00109 {
00110 atomic_increment( &use_count_ );
00111 }
00112
00113 bool add_ref_lock()
00114 {
00115 return atomic_conditional_increment( &use_count_ ) != 0;
00116 }
00117
00118 void release()
00119 {
00120 if( atomic_decrement( &use_count_ ) == 0 )
00121 {
00122 dispose();
00123 weak_release();
00124 }
00125 }
00126
00127 void weak_add_ref()
00128 {
00129 atomic_increment( &weak_count_ );
00130 }
00131
00132 void weak_release()
00133 {
00134 if( atomic_decrement( &weak_count_ ) == 0 )
00135 {
00136 destroy();
00137 }
00138 }
00139
00140 long use_count() const
00141 {
00142 return static_cast<int const volatile &>( use_count_ );
00143 }
00144 };
00145
00146 }
00147
00148 }
00149
00150 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_ACC_IA64_HPP_INCLUDED