sp_counted_base_spin.hpp
Go to the documentation of this file.
1 #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_SPIN_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_SPIN_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_spin.hpp - spinlock pool atomic emulation
12 //
13 // Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
14 // Copyright 2004-2008 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 
23 
24 namespace boost
25 {
26 
27 namespace detail
28 {
29 
30 inline int atomic_exchange_and_add( int * pw, int dv )
31 {
32  spinlock_pool<1>::scoped_lock lock( pw );
33 
34  int r = *pw;
35  *pw += dv;
36  return r;
37 }
38 
39 inline void atomic_increment( int * pw )
40 {
41  spinlock_pool<1>::scoped_lock lock( pw );
42  ++*pw;
43 }
44 
45 inline int atomic_conditional_increment( int * pw )
46 {
47  spinlock_pool<1>::scoped_lock lock( pw );
48 
49  int rv = *pw;
50  if( rv != 0 ) ++*pw;
51  return rv;
52 }
53 
54 class sp_counted_base
55 {
56 private:
57 
60 
61  int use_count_; // #shared
62  int weak_count_; // #weak + (#shared != 0)
63 
64 public:
65 
67  {
68  }
69 
70  virtual ~sp_counted_base() // nothrow
71  {
72  }
73 
74  // dispose() is called when use_count_ drops to zero, to release
75  // the resources managed by *this.
76 
77  virtual void dispose() = 0; // nothrow
78 
79  // destroy() is called when weak_count_ drops to zero.
80 
81  virtual void destroy() // nothrow
82  {
83  delete this;
84  }
85 
86  virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
87  virtual void * get_untyped_deleter() = 0;
88 
89  void add_ref_copy()
90  {
92  }
93 
94  bool add_ref_lock() // true on success
95  {
97  }
98 
99  void release() // nothrow
100  {
101  if( atomic_exchange_and_add( &use_count_, -1 ) == 1 )
102  {
103  dispose();
104  weak_release();
105  }
106  }
107 
108  void weak_add_ref() // nothrow
109  {
111  }
112 
113  void weak_release() // nothrow
114  {
115  if( atomic_exchange_and_add( &weak_count_, -1 ) == 1 )
116  {
117  destroy();
118  }
119  }
120 
121  long use_count() const // nothrow
122  {
124  return use_count_;
125  }
126 };
127 
128 } // namespace detail
129 
130 } // namespace boost
131 
132 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_SPIN_HPP_INCLUDED
boost::detail::atomic_increment
void atomic_increment(int *pw)
Definition: sp_counted_base_acc_ia64.hpp:27
boost::detail::spinlock_pool::scoped_lock
Definition: spinlock_pool.hpp:52
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_spin.hpp:81
boost::detail::sp_counted_base::add_ref_copy
void add_ref_copy()
Definition: sp_counted_base_spin.hpp:89
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_spin.hpp:94
boost::detail::sp_typeinfo
boost::core::typeinfo sp_typeinfo
Definition: sp_typeinfo.hpp:28
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_spin.hpp:121
boost::detail::sp_counted_base::dispose
virtual void dispose()=0
spinlock_pool.hpp
boost::detail::sp_counted_base::~sp_counted_base
virtual ~sp_counted_base()
Definition: sp_counted_base_spin.hpp:70
boost::detail::sp_counted_base::operator=
sp_counted_base & operator=(sp_counted_base const &)
boost::detail::atomic_exchange_and_add
int atomic_exchange_and_add(int *pw, int dv)
Definition: sp_counted_base_gcc_x86.hpp:35
boost::detail::atomic_conditional_increment
int atomic_conditional_increment(int *pw)
Definition: sp_counted_base_acc_ia64.hpp:47
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_spin.hpp:99
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_spin.hpp:108


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