File indexing completed on 2026-04-29 07:53:55
0001 #ifndef BOOST_INTERPROCESS_DETAIL_SP_COUNTED_BASE_ATOMIC_HPP_INCLUDED
0002 #define BOOST_INTERPROCESS_DETAIL_SP_COUNTED_BASE_ATOMIC_HPP_INCLUDED
0003
0004 #ifndef BOOST_CONFIG_HPP
0005 # include <boost/config.hpp>
0006 #endif
0007 0008 ">#
0009 #if defined(BOOST_HAS_PRAGMA_ONCE)
0010 # pragma once
0011 #endif
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #include <boost/interprocess/detail/config_begin.hpp>
0029 #include <boost/interprocess/detail/workaround.hpp>
0030
0031 #include <boost/interprocess/detail/atomic.hpp>
0032 #include <typeinfo>
0033
0034 namespace boost {
0035
0036 namespace interprocess {
0037
0038 namespace ipcdetail {
0039
0040 class sp_counted_base
0041 {
0042 private:
0043
0044 sp_counted_base( sp_counted_base const & );
0045 sp_counted_base & operator= ( sp_counted_base const & );
0046
0047 boost::uint32_t use_count_;
0048 boost::uint32_t weak_count_;
0049
0050 public:
0051
0052 sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
0053 {}
0054
0055 ~sp_counted_base()
0056 {}
0057
0058 void add_ref_copy()
0059 {
0060 ipcdetail::atomic_inc32( &use_count_ );
0061 }
0062
0063 bool add_ref_lock()
0064 {
0065 for( ;; )
0066 {
0067 boost::uint32_t tmp = static_cast< boost::uint32_t const volatile& >( use_count_ );
0068 if( tmp == 0 ) return false;
0069 if( ipcdetail::atomic_cas32( &use_count_, tmp + 1, tmp ) == tmp )
0070 return true;
0071 }
0072 }
0073
0074 bool ref_release()
0075 { return 1 == ipcdetail::atomic_dec32( &use_count_ ); }
0076
0077 void weak_add_ref()
0078 { ipcdetail::atomic_inc32( &weak_count_ ); }
0079
0080 bool weak_release()
0081 { return 1 == ipcdetail::atomic_dec32( &weak_count_ ); }
0082
0083 long use_count() const
0084 { return (long)static_cast<boost::uint32_t const volatile &>( use_count_ ); }
0085 };
0086
0087 }
0088
0089 }
0090
0091 }
0092
0093 #include <boost/interprocess/detail/config_end.hpp>
0094
0095 #endif