sp_counted_base_w32.hpp
Go to the documentation of this file.
1 #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_W32_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_W32_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_w32.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 // Lock-free algorithm by Alexander Terekhov
22 //
23 // Thanks to Ben Hitchings for the #weak + (#shared != 0)
24 // formulation
25 //
26 
30 
31 namespace boost
32 {
33 
34 namespace detail
35 {
36 
37 class sp_counted_base
38 {
39 private:
40 
43 
44  long use_count_; // #shared
45  long weak_count_; // #weak + (#shared != 0)
46 
47 public:
48 
50  {
51  }
52 
53  virtual ~sp_counted_base() // nothrow
54  {
55  }
56 
57  // dispose() is called when use_count_ drops to zero, to release
58  // the resources managed by *this.
59 
60  virtual void dispose() = 0; // nothrow
61 
62  // destroy() is called when weak_count_ drops to zero.
63 
64  virtual void destroy() // nothrow
65  {
66  delete this;
67  }
68 
69  virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
70  virtual void * get_untyped_deleter() = 0;
71 
72  void add_ref_copy()
73  {
74  BOOST_SP_INTERLOCKED_INCREMENT( &use_count_ );
75  }
76 
77  bool add_ref_lock() // true on success
78  {
79  for( ;; )
80  {
81  long tmp = static_cast< long const volatile& >( use_count_ );
82  if( tmp == 0 ) return false;
83 
84 #if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, == 1200 )
85 
86  // work around a code generation bug
87 
88  long tmp2 = tmp + 1;
89  if( BOOST_SP_INTERLOCKED_COMPARE_EXCHANGE( &use_count_, tmp2, tmp ) == tmp2 - 1 ) return true;
90 
91 #else
92 
93  if( BOOST_SP_INTERLOCKED_COMPARE_EXCHANGE( &use_count_, tmp + 1, tmp ) == tmp ) return true;
94 
95 #endif
96  }
97  }
98 
99  void release() // nothrow
100  {
101  if( BOOST_SP_INTERLOCKED_DECREMENT( &use_count_ ) == 0 )
102  {
103  dispose();
104  weak_release();
105  }
106  }
107 
108  void weak_add_ref() // nothrow
109  {
110  BOOST_SP_INTERLOCKED_INCREMENT( &weak_count_ );
111  }
112 
113  void weak_release() // nothrow
114  {
115  if( BOOST_SP_INTERLOCKED_DECREMENT( &weak_count_ ) == 0 )
116  {
117  destroy();
118  }
119  }
120 
121  long use_count() const // nothrow
122  {
123  return static_cast<long const volatile &>( use_count_ );
124  }
125 };
126 
127 } // namespace detail
128 
129 } // namespace boost
130 
131 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_W32_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_w32.hpp:64
boost::detail::sp_counted_base::add_ref_copy
void add_ref_copy()
Definition: sp_counted_base_w32.hpp:72
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_w32.hpp:77
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_w32.hpp:121
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_w32.hpp:53
boost::detail::sp_counted_base::operator=
sp_counted_base & operator=(sp_counted_base const &)
sp_interlocked.hpp
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_w32.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
workaround.hpp
boost::detail::sp_counted_base::weak_add_ref
void weak_add_ref()
Definition: sp_counted_base_w32.hpp:108


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