sp_counted_base_pt.hpp
Go to the documentation of this file.
1 #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_PT_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_PT_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_pt.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 
22 #include <boost/assert.hpp>
23 #include <pthread.h>
24 
25 namespace boost
26 {
27 
28 namespace detail
29 {
30 
31 class sp_counted_base
32 {
33 private:
34 
37 
38  long use_count_; // #shared
39  long weak_count_; // #weak + (#shared != 0)
40 
41  mutable pthread_mutex_t m_;
42 
43 public:
44 
46  {
47 // HPUX 10.20 / DCE has a nonstandard pthread_mutex_init
48 
49 #if defined(__hpux) && defined(_DECTHREADS_)
50  BOOST_VERIFY( pthread_mutex_init( &m_, pthread_mutexattr_default ) == 0 );
51 #else
52  BOOST_VERIFY( pthread_mutex_init( &m_, 0 ) == 0 );
53 #endif
54  }
55 
56  virtual ~sp_counted_base() // nothrow
57  {
58  BOOST_VERIFY( pthread_mutex_destroy( &m_ ) == 0 );
59  }
60 
61  // dispose() is called when use_count_ drops to zero, to release
62  // the resources managed by *this.
63 
64  virtual void dispose() = 0; // nothrow
65 
66  // destroy() is called when weak_count_ drops to zero.
67 
68  virtual void destroy() // nothrow
69  {
70  delete this;
71  }
72 
73  virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
74  virtual void * get_untyped_deleter() = 0;
75 
76  void add_ref_copy()
77  {
78  BOOST_VERIFY( pthread_mutex_lock( &m_ ) == 0 );
79  ++use_count_;
80  BOOST_VERIFY( pthread_mutex_unlock( &m_ ) == 0 );
81  }
82 
83  bool add_ref_lock() // true on success
84  {
85  BOOST_VERIFY( pthread_mutex_lock( &m_ ) == 0 );
86  bool r = use_count_ == 0? false: ( ++use_count_, true );
87  BOOST_VERIFY( pthread_mutex_unlock( &m_ ) == 0 );
88  return r;
89  }
90 
91  void release() // nothrow
92  {
93  BOOST_VERIFY( pthread_mutex_lock( &m_ ) == 0 );
94  long new_use_count = --use_count_;
95  BOOST_VERIFY( pthread_mutex_unlock( &m_ ) == 0 );
96 
97  if( new_use_count == 0 )
98  {
99  dispose();
100  weak_release();
101  }
102  }
103 
104  void weak_add_ref() // nothrow
105  {
106  BOOST_VERIFY( pthread_mutex_lock( &m_ ) == 0 );
107  ++weak_count_;
108  BOOST_VERIFY( pthread_mutex_unlock( &m_ ) == 0 );
109  }
110 
111  void weak_release() // nothrow
112  {
113  BOOST_VERIFY( pthread_mutex_lock( &m_ ) == 0 );
114  long new_weak_count = --weak_count_;
115  BOOST_VERIFY( pthread_mutex_unlock( &m_ ) == 0 );
116 
117  if( new_weak_count == 0 )
118  {
119  destroy();
120  }
121  }
122 
123  long use_count() const // nothrow
124  {
125  BOOST_VERIFY( pthread_mutex_lock( &m_ ) == 0 );
126  long r = use_count_;
127  BOOST_VERIFY( pthread_mutex_unlock( &m_ ) == 0 );
128 
129  return r;
130  }
131 };
132 
133 } // namespace detail
134 
135 } // namespace boost
136 
137 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_PT_HPP_INCLUDED
boost::detail::sp_counted_base::get_untyped_deleter
virtual void * get_untyped_deleter()=0
boost
BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE.
boost::detail::sp_counted_base::destroy
virtual void destroy()
Definition: sp_counted_base_pt.hpp:68
boost::detail::sp_counted_base::add_ref_copy
void add_ref_copy()
Definition: sp_counted_base_pt.hpp:76
sp_typeinfo.hpp
boost::detail::sp_counted_base::weak_release
void weak_release()
Definition: sp_counted_base_acc_ia64.hpp:133
boost::detail::sp_counted_base::add_ref_lock
bool add_ref_lock()
Definition: sp_counted_base_pt.hpp:83
BOOST_VERIFY
#define BOOST_VERIFY(expr)
Definition: assert.hpp:82
boost::detail::sp_counted_base::m_
pthread_mutex_t m_
Definition: sp_counted_base_pt.hpp:41
boost::detail::sp_typeinfo
boost::core::typeinfo sp_typeinfo
Definition: sp_typeinfo.hpp:28
assert.hpp
boost::detail::sp_counted_base::get_deleter
virtual void * get_deleter(sp_typeinfo const &ti)=0
boost::detail::sp_counted_base::use_count
long use_count() const
Definition: sp_counted_base_pt.hpp:123
boost::detail::sp_counted_base::dispose
virtual void dispose()=0
boost::detail::sp_counted_base::~sp_counted_base
virtual ~sp_counted_base()
Definition: sp_counted_base_pt.hpp:56
boost::detail::sp_counted_base::operator=
sp_counted_base & operator=(sp_counted_base const &)
boost::detail::sp_counted_base::sp_counted_base
sp_counted_base()
Definition: sp_counted_base_acc_ia64.hpp:86
boost::detail::sp_counted_base::release
void release()
Definition: sp_counted_base_pt.hpp:91
boost::detail::sp_counted_base::use_count_
int use_count_
Definition: sp_counted_base_acc_ia64.hpp:81
boost::detail::sp_counted_base::weak_count_
int weak_count_
Definition: sp_counted_base_acc_ia64.hpp:82
boost::detail::sp_counted_base::weak_add_ref
void weak_add_ref()
Definition: sp_counted_base_pt.hpp:104


sick_visionary_ros
Author(s): SICK AG TechSupport 3D Snapshot
autogenerated on Thu Feb 8 2024 03:48:40