sp_counted_base_clang.hpp
Go to the documentation of this file.
1 #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_CLANG_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_CLANG_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_clang.hpp - __c11 clang intrinsics
11 //
12 // Copyright (c) 2007, 2013, 2015 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 <boost/cstdint.hpp>
20 
21 namespace boost
22 {
23 
24 namespace detail
25 {
26 
27 typedef _Atomic( boost::int_least32_t ) atomic_int_least32_t;
28 
29 inline void atomic_increment( atomic_int_least32_t * pw )
30 {
31  __c11_atomic_fetch_add( pw, 1, __ATOMIC_RELAXED );
32 }
33 
34 inline boost::int_least32_t atomic_decrement( atomic_int_least32_t * pw )
35 {
36  return __c11_atomic_fetch_sub( pw, 1, __ATOMIC_ACQ_REL );
37 }
38 
39 inline boost::int_least32_t atomic_conditional_increment( atomic_int_least32_t * pw )
40 {
41  // long r = *pw;
42  // if( r != 0 ) ++*pw;
43  // return r;
44 
45  boost::int_least32_t r = __c11_atomic_load( pw, __ATOMIC_RELAXED );
46 
47  for( ;; )
48  {
49  if( r == 0 )
50  {
51  return r;
52  }
53 
54  if( __c11_atomic_compare_exchange_weak( pw, &r, r + 1, __ATOMIC_RELAXED, __ATOMIC_RELAXED ) )
55  {
56  return r;
57  }
58  }
59 }
60 
61 class sp_counted_base
62 {
63 private:
64 
67 
68  atomic_int_least32_t use_count_; // #shared
69  atomic_int_least32_t weak_count_; // #weak + (#shared != 0)
70 
71 public:
72 
74  {
75  __c11_atomic_init( &use_count_, 1 );
76  __c11_atomic_init( &weak_count_, 1 );
77  }
78 
79  virtual ~sp_counted_base() // nothrow
80  {
81  }
82 
83  // dispose() is called when use_count_ drops to zero, to release
84  // the resources managed by *this.
85 
86  virtual void dispose() = 0; // nothrow
87 
88  // destroy() is called when weak_count_ drops to zero.
89 
90  virtual void destroy() // nothrow
91  {
92  delete this;
93  }
94 
95  virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
96  virtual void * get_untyped_deleter() = 0;
97 
98  void add_ref_copy()
99  {
101  }
102 
103  bool add_ref_lock() // true on success
104  {
106  }
107 
108  void release() // nothrow
109  {
110  if( atomic_decrement( &use_count_ ) == 1 )
111  {
112  dispose();
113  weak_release();
114  }
115  }
116 
117  void weak_add_ref() // nothrow
118  {
120  }
121 
122  void weak_release() // nothrow
123  {
124  if( atomic_decrement( &weak_count_ ) == 1 )
125  {
126  destroy();
127  }
128  }
129 
130  long use_count() const // nothrow
131  {
132  return __c11_atomic_load( const_cast< atomic_int_least32_t* >( &use_count_ ), __ATOMIC_ACQUIRE );
133  }
134 };
135 
136 } // namespace detail
137 
138 } // namespace boost
139 
140 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_CLANG_HPP_INCLUDED
boost::detail::atomic_increment
void atomic_increment(int *pw)
Definition: sp_counted_base_acc_ia64.hpp:27
boost::detail::_Atomic
typedef _Atomic(boost::int_least32_t) atomic_int_least32_t
cstdint.hpp
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_clang.hpp:90
boost::detail::sp_counted_base::add_ref_copy
void add_ref_copy()
Definition: sp_counted_base_clang.hpp:98
sp_typeinfo.hpp
boost::detail::sp_counted_base::weak_release
void weak_release()
Definition: sp_counted_base_acc_ia64.hpp:133
__ATOMIC_ACQUIRE
#define __ATOMIC_ACQUIRE
Definition: compiler/cray.hpp:86
boost::detail::sp_counted_base::add_ref_lock
bool add_ref_lock()
Definition: sp_counted_base_clang.hpp:103
boost::detail::sp_counted_base::use_count_
atomic_int_least32_t use_count_
Definition: sp_counted_base_clang.hpp:68
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
__ATOMIC_ACQ_REL
#define __ATOMIC_ACQ_REL
Definition: compiler/cray.hpp:88
boost::detail::sp_counted_base::use_count
long use_count() const
Definition: sp_counted_base_clang.hpp:130
boost::detail::sp_counted_base::dispose
virtual void dispose()=0
__ATOMIC_RELAXED
#define __ATOMIC_RELAXED
Definition: compiler/cray.hpp:84
boost::detail::sp_counted_base::~sp_counted_base
virtual ~sp_counted_base()
Definition: sp_counted_base_clang.hpp:79
boost::detail::sp_counted_base::operator=
sp_counted_base & operator=(sp_counted_base const &)
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_clang.hpp:108
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_count_
atomic_int_least32_t weak_count_
Definition: sp_counted_base_clang.hpp:69
boost::detail::sp_counted_base::weak_add_ref
void weak_add_ref()
Definition: sp_counted_base_clang.hpp:117


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