sp_counted_base_sync.hpp
Go to the documentation of this file.
1 #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_SYNC_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_SYNC_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 // detail/sp_counted_base_sync.hpp - g++ 4.1+ __sync intrinsics
11 //
12 // Copyright (c) 2007 Peter Dimov
13 //
14 // Distributed under the Boost Software License, Version 1.0.
15 // See accompanying file LICENSE_1_0.txt or copy at
16 // http://www.boost.org/LICENSE_1_0.txt
17 
19 #include <limits.h>
20 
21 #if defined( __ia64__ ) && defined( __INTEL_COMPILER )
22 # include <ia64intrin.h>
23 #endif
24 
25 namespace boost
26 {
27 
28 namespace detail
29 {
30 
31 #if INT_MAX >= 2147483647
32 
33 typedef int sp_int32_t;
34 
35 #else
36 
37 typedef long sp_int32_t;
38 
39 #endif
40 
41 inline void atomic_increment( sp_int32_t * pw )
42 {
43  __sync_fetch_and_add( pw, 1 );
44 }
45 
47 {
48  return __sync_fetch_and_add( pw, -1 );
49 }
50 
52 {
53  // long r = *pw;
54  // if( r != 0 ) ++*pw;
55  // return r;
56 
57  sp_int32_t r = *pw;
58 
59  for( ;; )
60  {
61  if( r == 0 )
62  {
63  return r;
64  }
65 
66  sp_int32_t r2 = __sync_val_compare_and_swap( pw, r, r + 1 );
67 
68  if( r2 == r )
69  {
70  return r;
71  }
72  else
73  {
74  r = r2;
75  }
76  }
77 }
78 
79 class sp_counted_base
80 {
81 private:
82 
85 
86  sp_int32_t use_count_; // #shared
87  sp_int32_t weak_count_; // #weak + (#shared != 0)
88 
89 public:
90 
92  {
93  }
94 
95  virtual ~sp_counted_base() // nothrow
96  {
97  }
98 
99  // dispose() is called when use_count_ drops to zero, to release
100  // the resources managed by *this.
101 
102  virtual void dispose() = 0; // nothrow
103 
104  // destroy() is called when weak_count_ drops to zero.
105 
106  virtual void destroy() // nothrow
107  {
108  delete this;
109  }
110 
111  virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
112  virtual void * get_untyped_deleter() = 0;
113 
115  {
117  }
118 
119  bool add_ref_lock() // true on success
120  {
122  }
123 
124  void release() // nothrow
125  {
126  if( atomic_decrement( &use_count_ ) == 1 )
127  {
128  dispose();
129  weak_release();
130  }
131  }
132 
133  void weak_add_ref() // nothrow
134  {
136  }
137 
138  void weak_release() // nothrow
139  {
140  if( atomic_decrement( &weak_count_ ) == 1 )
141  {
142  destroy();
143  }
144  }
145 
146  long use_count() const // nothrow
147  {
148  return const_cast< sp_int32_t const volatile & >( use_count_ );
149  }
150 };
151 
152 } // namespace detail
153 
154 } // namespace boost
155 
156 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_SYNC_HPP_INCLUDED
boost::detail::atomic_increment
void atomic_increment(int *pw)
Definition: sp_counted_base_acc_ia64.hpp:27
boost::detail::sp_counted_base::get_untyped_deleter
virtual void * get_untyped_deleter()=0
boost::detail::sp_counted_base::use_count_
sp_int32_t use_count_
Definition: sp_counted_base_sync.hpp:86
boost
BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE.
boost::detail::sp_counted_base::destroy
virtual void destroy()
Definition: sp_counted_base_sync.hpp:106
boost::detail::sp_counted_base::add_ref_copy
void add_ref_copy()
Definition: sp_counted_base_sync.hpp:114
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_sync.hpp:119
boost::detail::sp_int32_t
long sp_int32_t
Definition: sp_counted_base_sync.hpp:37
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_sync.hpp:146
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_sync.hpp:95
boost::detail::sp_counted_base::operator=
sp_counted_base & operator=(sp_counted_base const &)
boost::detail::sp_counted_base::weak_count_
sp_int32_t weak_count_
Definition: sp_counted_base_sync.hpp:87
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_sync.hpp:124
boost::detail::atomic_decrement
int atomic_decrement(int *pw)
Definition: sp_counted_base_acc_ia64.hpp:34
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_sync.hpp:133


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