Back to home page

EIC code displayed by LXR

 
 

    


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 //  detail/sp_counted_base_acc_ia64.hpp - aC++ on HP-UX IA64
0006 //
0007 //  Copyright 2007 Baruch Zilber
0008 //  Copyright 2007 Boris Gubenko
0009 //
0010 //  Distributed under the Boost Software License, Version 1.0. (See
0011 //  accompanying file LICENSE_1_0.txt or copy at
0012 //  http://www.boost.org/LICENSE_1_0.txt)
0013 //
0014 //
0015 //  Lock-free algorithm by Alexander Terekhov
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     // ++*pw;
0041 
0042     _Asm_fetchadd(_FASZ_W, _SEM_REL, pw, +1, _LDHINT_NONE);
0043 } 
0044 
0045 inline int atomic_decrement( int * pw )
0046 {
0047     // return --*pw;
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     // if( *pw != 0 ) ++*pw;
0061     // return *pw;
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_;        // #shared
0093     int weak_count_;       // #weak + (#shared != 0)
0094 
0095 public:
0096 
0097     sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
0098     {
0099     }
0100 
0101     virtual ~sp_counted_base() // nothrow
0102     {
0103     }
0104 
0105     // dispose() is called when use_count_ drops to zero, to release
0106     // the resources managed by *this.
0107 
0108     virtual void dispose() = 0; // nothrow
0109 
0110     // destroy() is called when weak_count_ drops to zero.
0111 
0112     virtual void destroy() // nothrow
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() // true on success
0127     {
0128         return atomic_conditional_increment( &use_count_ ) != 0;
0129     }
0130 
0131     void release() // nothrow
0132     {
0133         if( atomic_decrement( &use_count_ ) == 0 )
0134         {
0135             dispose();
0136             weak_release();
0137         }
0138     }
0139 
0140     void weak_add_ref() // nothrow
0141     {
0142         atomic_increment( &weak_count_ );
0143     }
0144 
0145     void weak_release() // nothrow
0146     {
0147         if( atomic_decrement( &weak_count_ ) == 0 )
0148         {
0149             destroy();
0150         }
0151     }
0152 
0153     long use_count() const // nothrow
0154     {
0155         return static_cast<int const volatile &>( use_count_ ); // TODO use ld.acq here
0156     }
0157 };
0158 
0159 } // namespace detail
0160 
0161 } // namespace boost
0162 
0163 #endif  // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_ACC_IA64_HPP_INCLUDED