1 #ifndef BOOST_DETAIL_SP_COUNTED_BASE_ACC_IA64_HPP_INCLUDED
2 #define BOOST_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/detail/sp_typeinfo.hpp>
19 #include <machine/sys/inline.h>
27 inline void atomic_increment( int * pw )
31 _Asm_fetchadd(_FASZ_W, _SEM_REL, pw, +1, _LDHINT_NONE);
34 inline int atomic_decrement( int * pw )
38 int r = static_cast<int>(_Asm_fetchadd(_FASZ_W, _SEM_REL, pw, -1, _LDHINT_NONE));
47 inline int atomic_conditional_increment( int * pw )
49 // if( *pw != 0 ) ++*pw;
61 _Asm_mov_to_ar(_AREG_CCV,
63 (_UP_CALL_FENCE | _UP_SYS_FENCE | _DOWN_CALL_FENCE | _DOWN_SYS_FENCE));
64 int r = static_cast<int>(_Asm_cmpxchg(_SZ_W, _SEM_ACQ, pw, v + 1, _LDHINT_NONE));
78 sp_counted_base( sp_counted_base const & );
79 sp_counted_base & operator= ( sp_counted_base const & );
81 int use_count_; // #shared
82 int weak_count_; // #weak + (#shared != 0)
86 sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
90 virtual ~sp_counted_base() // nothrow
94 // dispose() is called when use_count_ drops to zero, to release
95 // the resources managed by *this.
97 virtual void dispose() = 0; // nothrow
99 // destroy() is called when weak_count_ drops to zero.
101 virtual void destroy() // nothrow
106 virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
110 atomic_increment( &use_count_ );
113 bool add_ref_lock() // true on success
115 return atomic_conditional_increment( &use_count_ ) != 0;
118 void release() // nothrow
120 if( atomic_decrement( &use_count_ ) == 0 )
127 void weak_add_ref() // nothrow
129 atomic_increment( &weak_count_ );
132 void weak_release() // nothrow
134 if( atomic_decrement( &weak_count_ ) == 0 )
140 long use_count() const // nothrow
142 return static_cast<int const volatile &>( use_count_ ); // TODO use ld.acq here
146 } // namespace detail
150 #endif // #ifndef BOOST_DETAIL_SP_COUNTED_BASE_ACC_IA64_HPP_INCLUDED