]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/smart_ptr/detail/sp_counted_base_nt.hpp
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / boost / boost / smart_ptr / detail / sp_counted_base_nt.hpp
1 #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED
3
4 // MS compatible compilers support #pragma once
5
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
7 # pragma once
8 #endif
9
10 //
11 // detail/sp_counted_base_nt.hpp
12 //
13 // Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
14 // Copyright 2004-2005 Peter Dimov
15 //
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)
19 //
20
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>
25
26 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
27
28 #include <boost/config/pragma_message.hpp>
29 BOOST_PRAGMA_MESSAGE("Using single-threaded, non-atomic sp_counted_base")
30
31 #endif
32
33 namespace boost
34 {
35
36 namespace detail
37 {
38
39 class BOOST_SYMBOL_VISIBLE sp_counted_base
40 {
41 private:
42
43 sp_counted_base( sp_counted_base const & );
44 sp_counted_base & operator= ( sp_counted_base const & );
45
46 boost::int_least32_t use_count_; // #shared
47 boost::int_least32_t weak_count_; // #weak + (#shared != 0)
48
49 public:
50
51 sp_counted_base() BOOST_SP_NOEXCEPT: use_count_( 1 ), weak_count_( 1 )
52 {
53 }
54
55 virtual ~sp_counted_base() /*BOOST_SP_NOEXCEPT*/
56 {
57 }
58
59 // dispose() is called when use_count_ drops to zero, to release
60 // the resources managed by *this.
61
62 virtual void dispose() BOOST_SP_NOEXCEPT = 0; // nothrow
63
64 // destroy() is called when weak_count_ drops to zero.
65
66 virtual void destroy() BOOST_SP_NOEXCEPT // nothrow
67 {
68 delete this;
69 }
70
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;
74
75 void add_ref_copy() BOOST_SP_NOEXCEPT
76 {
77 ++use_count_;
78 }
79
80 bool add_ref_lock() BOOST_SP_NOEXCEPT // true on success
81 {
82 if( use_count_ == 0 ) return false;
83 ++use_count_;
84 return true;
85 }
86
87 void release() BOOST_SP_NOEXCEPT
88 {
89 if( --use_count_ == 0 )
90 {
91 dispose();
92 weak_release();
93 }
94 }
95
96 void weak_add_ref() BOOST_SP_NOEXCEPT
97 {
98 ++weak_count_;
99 }
100
101 void weak_release() BOOST_SP_NOEXCEPT
102 {
103 if( --weak_count_ == 0 )
104 {
105 destroy();
106 }
107 }
108
109 long use_count() const BOOST_SP_NOEXCEPT
110 {
111 return use_count_;
112 }
113 };
114
115 } // namespace detail
116
117 } // namespace boost
118
119 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_NT_HPP_INCLUDED