sp_counted_base_std_atomic.hpp
Go to the documentation of this file.
1 #include "sick_scan/sick_scan_base.h" /* Base definitions included in all header files, added by add_sick_scan_base_header.py. Do not edit this line. */
2 #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_STD_ATOMIC_HPP_INCLUDED
3 #define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_STD_ATOMIC_HPP_INCLUDED
4 
5 // MS compatible compilers support #pragma once
6 
7 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
8 # pragma once
9 #endif
10 
11 // detail/sp_counted_base_std_atomic.hpp - C++11 std::atomic
12 //
13 // Copyright (c) 2007, 2013 Peter Dimov
14 //
15 // Distributed under the Boost Software License, Version 1.0.
16 // See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt
18 
19 typedef std::type_info sp_typeinfo;
20 #define BOOST_CORE_TYPEID(T) typeid(T)
21 #define BOOST_SP_TYPEID(T) typeid(T)
22 #define BOOST_CONSTEXPR constexpr
23 #include <atomic>
24 #include <cstdint>
25 
26 namespace boost
27 {
28 
29 namespace detail
30 {
31 
32 inline void atomic_increment( std::atomic_int_least32_t * pw )
33 {
34  pw->fetch_add( 1, std::memory_order_relaxed );
35 }
36 
37 inline std::int_least32_t atomic_decrement( std::atomic_int_least32_t * pw )
38 {
39  return pw->fetch_sub( 1, std::memory_order_acq_rel );
40 }
41 
42 inline std::int_least32_t atomic_conditional_increment( std::atomic_int_least32_t * pw )
43 {
44  // long r = *pw;
45  // if( r != 0 ) ++*pw;
46  // return r;
47 
48  std::int_least32_t r = pw->load( std::memory_order_relaxed );
49 
50  for( ;; )
51  {
52  if( r == 0 )
53  {
54  return r;
55  }
56 
57  if( pw->compare_exchange_weak( r, r + 1, std::memory_order_relaxed, std::memory_order_relaxed ) )
58  {
59  return r;
60  }
61  }
62 }
63 
65 {
66 private:
67 
70 
71  std::atomic_int_least32_t use_count_; // #shared
72  std::atomic_int_least32_t weak_count_; // #weak + (#shared != 0)
73 
74 public:
75 
77  {
78  }
79 
80  virtual ~sp_counted_base() // nothrow
81  {
82  }
83 
84  // dispose() is called when use_count_ drops to zero, to release
85  // the resources managed by *this.
86 
87  virtual void dispose() = 0; // nothrow
88 
89  // destroy() is called when weak_count_ drops to zero.
90 
91  virtual void destroy() // nothrow
92  {
93  delete this;
94  }
95 
96  virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
97  virtual void * get_local_deleter( sp_typeinfo const & ti ) = 0;
98  virtual void * get_untyped_deleter() = 0;
99 
101  {
103  }
104 
105  bool add_ref_lock() // true on success
106  {
108  }
109 
110  void release() // nothrow
111  {
112  if( atomic_decrement( &use_count_ ) == 1 )
113  {
114  dispose();
115  weak_release();
116  }
117  }
118 
119  void weak_add_ref() // nothrow
120  {
122  }
123 
124  void weak_release() // nothrow
125  {
126  if( atomic_decrement( &weak_count_ ) == 1 )
127  {
128  destroy();
129  }
130  }
131 
132  long use_count() const // nothrow
133  {
134  return use_count_.load( std::memory_order_acquire );
135  }
136 };
137 
138 } // namespace detail
139 
140 } // namespace boost
141 
142 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_STD_ATOMIC_HPP_INCLUDED
boost::detail::atomic_conditional_increment
std::int_least32_t atomic_conditional_increment(std::atomic_int_least32_t *pw)
Definition: sp_counted_base_std_atomic.hpp:42
const
#define const
Definition: getopt.c:38
boost::detail::sp_counted_base::get_untyped_deleter
virtual void * get_untyped_deleter()=0
boost
boost::detail::atomic_increment
void atomic_increment(std::atomic_int_least32_t *pw)
Definition: sp_counted_base_std_atomic.hpp:32
boost::detail::sp_counted_base
Definition: sp_counted_base_std_atomic.hpp:64
boost::detail::sp_counted_base::destroy
virtual void destroy()
Definition: sp_counted_base_std_atomic.hpp:91
boost::detail::sp_counted_base::add_ref_copy
void add_ref_copy()
Definition: sp_counted_base_std_atomic.hpp:100
sp_typeinfo
std::type_info sp_typeinfo
Definition: sp_counted_base_std_atomic.hpp:19
boost::detail::sp_counted_base::weak_release
void weak_release()
Definition: sp_counted_base_std_atomic.hpp:124
boost::detail::sp_counted_base::add_ref_lock
bool add_ref_lock()
Definition: sp_counted_base_std_atomic.hpp:105
boost::detail::sp_counted_base::weak_count_
std::atomic_int_least32_t weak_count_
Definition: sp_counted_base_std_atomic.hpp:72
boost::detail::sp_counted_base::get_deleter
virtual void * get_deleter(sp_typeinfo const &ti)=0
boost::detail::sp_counted_base::get_local_deleter
virtual void * get_local_deleter(sp_typeinfo const &ti)=0
boost::detail::sp_counted_base::use_count
long use_count() const
Definition: sp_counted_base_std_atomic.hpp:132
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_std_atomic.hpp:80
boost::detail::sp_counted_base::operator=
sp_counted_base & operator=(sp_counted_base const &)
boost::detail::sp_counted_base::use_count_
std::atomic_int_least32_t use_count_
Definition: sp_counted_base_std_atomic.hpp:71
boost::detail::atomic_decrement
std::int_least32_t atomic_decrement(std::atomic_int_least32_t *pw)
Definition: sp_counted_base_std_atomic.hpp:37
sick_scan_base.h
boost::detail::sp_counted_base::sp_counted_base
sp_counted_base()
Definition: sp_counted_base_std_atomic.hpp:76
boost::detail::sp_counted_base::release
void release()
Definition: sp_counted_base_std_atomic.hpp:110
boost::detail::sp_counted_base::weak_add_ref
void weak_add_ref()
Definition: sp_counted_base_std_atomic.hpp:119


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:12