1 #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED
4 // MS compatible compilers support #pragma once
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
11 // detail/sp_counted_base_nt.hpp
13 // Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
14 // Copyright 2004-2005 Peter Dimov
16 // Distributed under the Boost Software License, Version 1.0. (See
17 // accompanying file LICENSE_1_0.txt or copy at
18 // http://www.boost.org/LICENSE_1_0.txt)
21 #include <boost/smart_ptr/detail/sp_typeinfo_.hpp>
22 #include <boost/smart_ptr/detail/sp_noexcept.hpp>
23 #include <boost/config.hpp>
24 #include <boost/cstdint.hpp>
26 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
28 #include <boost/config/pragma_message.hpp>
29 BOOST_PRAGMA_MESSAGE("Using single-threaded, non-atomic sp_counted_base")
39 class BOOST_SYMBOL_VISIBLE sp_counted_base
43 sp_counted_base( sp_counted_base const & );
44 sp_counted_base & operator= ( sp_counted_base const & );
46 boost::int_least32_t use_count_; // #shared
47 boost::int_least32_t weak_count_; // #weak + (#shared != 0)
51 sp_counted_base() BOOST_SP_NOEXCEPT: use_count_( 1 ), weak_count_( 1 )
55 virtual ~sp_counted_base() /*BOOST_SP_NOEXCEPT*/
59 // dispose() is called when use_count_ drops to zero, to release
60 // the resources managed by *this.
62 virtual void dispose() BOOST_SP_NOEXCEPT = 0; // nothrow
64 // destroy() is called when weak_count_ drops to zero.
66 virtual void destroy() BOOST_SP_NOEXCEPT // nothrow
71 virtual void * get_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT = 0;
72 virtual void * get_local_deleter( sp_typeinfo_ const & ti ) BOOST_SP_NOEXCEPT = 0;
73 virtual void * get_untyped_deleter() BOOST_SP_NOEXCEPT = 0;
75 void add_ref_copy() BOOST_SP_NOEXCEPT
80 bool add_ref_lock() BOOST_SP_NOEXCEPT // true on success
82 if( use_count_ == 0 ) return false;
87 void release() BOOST_SP_NOEXCEPT
89 if( --use_count_ == 0 )
96 void weak_add_ref() BOOST_SP_NOEXCEPT
101 void weak_release() BOOST_SP_NOEXCEPT
103 if( --weak_count_ == 0 )
109 long use_count() const BOOST_SP_NOEXCEPT
115 } // namespace detail
119 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED