Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 08:52:13

0001 #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED
0002 #define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED
0003 
0004 // MS compatible compilers support #pragma once
0005 
0006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
0007 # pragma once
0008 #endif
0009 
0010 //
0011 //  detail/sp_counted_base_nt.hpp
0012 //
0013 //  Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
0014 //  Copyright 2004-2005 Peter Dimov
0015 //
0016 // Distributed under the Boost Software License, Version 1.0. (See
0017 // accompanying file LICENSE_1_0.txt or copy at
0018 // http://www.boost.org/LICENSE_1_0.txt)
0019 //
0020 
0021 #include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
0022 #include <boost/config.hpp>
0023 #include <boost/cstdint.hpp>
0024 
0025 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
0026 
0027 #include <boost/config/pragma_message.hpp>
0028 BOOST_PRAGMA_MESSAGE("Using single-threaded, non-atomic sp_counted_base")
0029 
0030 #endif
0031 
0032 namespace boost
0033 {
0034 
0035 namespace detail
0036 {
0037 
0038 class BOOST_SYMBOL_VISIBLE sp_counted_base
0039 {
0040 private:
0041 
0042     sp_counted_base( sp_counted_base const & );
0043     sp_counted_base & operator= ( sp_counted_base const & );
0044 
0045     boost::int_least32_t use_count_;        // #shared
0046     boost::int_least32_t weak_count_;       // #weak + (#shared != 0)
0047 
0048 public:
0049 
0050     sp_counted_base() noexcept: use_count_( 1 ), weak_count_( 1 )
0051     {
0052     }
0053 
0054     virtual ~sp_counted_base() /*noexcept*/
0055     {
0056     }
0057 
0058     // dispose() is called when use_count_ drops to zero, to release
0059     // the resources managed by *this.
0060 
0061     virtual void dispose() noexcept = 0; // nothrow
0062 
0063     // destroy() is called when weak_count_ drops to zero.
0064 
0065     virtual void destroy() noexcept // nothrow
0066     {
0067         delete this;
0068     }
0069 
0070     virtual void * get_deleter( sp_typeinfo_ const & ti ) noexcept = 0;
0071     virtual void * get_local_deleter( sp_typeinfo_ const & ti ) noexcept = 0;
0072     virtual void * get_untyped_deleter() noexcept = 0;
0073 
0074     void add_ref_copy() noexcept
0075     {
0076         ++use_count_;
0077     }
0078 
0079     bool add_ref_lock() noexcept // true on success
0080     {
0081         if( use_count_ == 0 ) return false;
0082         ++use_count_;
0083         return true;
0084     }
0085 
0086     void release() noexcept
0087     {
0088         if( --use_count_ == 0 )
0089         {
0090             dispose();
0091             weak_release();
0092         }
0093     }
0094 
0095     void weak_add_ref() noexcept
0096     {
0097         ++weak_count_;
0098     }
0099 
0100     void weak_release() noexcept
0101     {
0102         if( --weak_count_ == 0 )
0103         {
0104             destroy();
0105         }
0106     }
0107 
0108     long use_count() const noexcept
0109     {
0110         return use_count_;
0111     }
0112 };
0113 
0114 } // namespace detail
0115 
0116 } // namespace boost
0117 
0118 #endif  // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED