File indexing completed on 2025-01-18 09:52:31
0001 #ifndef BOOST_STATECHART_DETAIL_COUNTED_BASE_HPP_INCLUDED
0002 #define BOOST_STATECHART_DETAIL_COUNTED_BASE_HPP_INCLUDED
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <boost/detail/atomic_count.hpp>
0012 #include <boost/config.hpp> // BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
0013
0014
0015
0016 namespace boost
0017 {
0018 namespace statechart
0019 {
0020 namespace detail
0021 {
0022
0023
0024
0025 template< bool NeedsLocking >
0026 struct count_base
0027 {
0028 count_base() : count_( 0 ) {}
0029 mutable boost::detail::atomic_count count_;
0030 };
0031
0032 template<>
0033 struct count_base< false >
0034 {
0035 count_base() : count_( 0 ) {}
0036 mutable long count_;
0037 };
0038
0039
0040 template< bool NeedsLocking = true >
0041 class counted_base : private count_base< NeedsLocking >
0042 {
0043 typedef count_base< NeedsLocking > base_type;
0044 public:
0045
0046 bool ref_counted() const
0047 {
0048 return base_type::count_ != 0;
0049 }
0050
0051 long ref_count() const
0052 {
0053 return base_type::count_;
0054 }
0055
0056 protected:
0057
0058 counted_base() {}
0059 ~counted_base() {}
0060
0061
0062
0063
0064 counted_base( const counted_base & ) : base_type() {}
0065 counted_base & operator=( const counted_base & ) { return *this; }
0066
0067 public:
0068
0069
0070
0071
0072 void add_ref() const
0073 {
0074 ++base_type::count_;
0075 }
0076
0077 bool release() const
0078 {
0079 BOOST_ASSERT( base_type::count_ > 0 );
0080 return --base_type::count_ == 0;
0081 }
0082 };
0083
0084
0085
0086 }
0087 }
0088 }
0089
0090
0091
0092 #endif