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
5 // detail/sp_counted_base_acc_ia64.hpp - aC++ on HP-UX IA64
7 // Copyright 2007 Baruch Zilber
8 // Copyright 2007 Boris Gubenko
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)
15 // Lock-free algorithm by Alexander Terekhov
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>
23 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
25 #include <boost/config/pragma_message.hpp>
26 BOOST_PRAGMA_MESSAGE("Using HP aCC++/HP-UX/IA64 sp_counted_base")
38 inline void atomic_increment( int * pw )
42 _Asm_fetchadd(_FASZ_W, _SEM_REL, pw, +1, _LDHINT_NONE);
45 inline int atomic_decrement( int * pw )
49 int r = static_cast<int>(_Asm_fetchadd(_FASZ_W, _SEM_REL, pw, -1, _LDHINT_NONE));
58 inline int atomic_conditional_increment( int * pw )
60 // if( *pw != 0 ) ++*pw;
72 _Asm_mov_to_ar(_AREG_CCV,
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));
85 class BOOST_SYMBOL_VISIBLE sp_counted_base
89 sp_counted_base( sp_counted_base const & );
90 sp_counted_base & operator= ( sp_counted_base const & );
92 int use_count_; // #shared
93 int weak_count_; // #weak + (#shared != 0)
97 sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
101 virtual ~sp_counted_base() // nothrow
105 // dispose() is called when use_count_ drops to zero, to release
106 // the resources managed by *this.
108 virtual void dispose() = 0; // nothrow
110 // destroy() is called when weak_count_ drops to zero.
112 virtual void destroy() // nothrow
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;
123 atomic_increment( &use_count_ );
126 bool add_ref_lock() // true on success
128 return atomic_conditional_increment( &use_count_ ) != 0;
131 void release() // nothrow
133 if( atomic_decrement( &use_count_ ) == 0 )
140 void weak_add_ref() // nothrow
142 atomic_increment( &weak_count_ );
145 void weak_release() // nothrow
147 if( atomic_decrement( &weak_count_ ) == 0 )
153 long use_count() const // nothrow
155 return static_cast<int const volatile &>( use_count_ ); // TODO use ld.acq here
159 } // namespace detail
163 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_ACC_IA64_HPP_INCLUDED