sp_counted_base_gcc_sparc.hpp
Go to the documentation of this file.
1 #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_GCC_SPARC_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_GCC_SPARC_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_gcc_sparc.hpp - g++ on Sparc V8+
11 //
12 // Copyright (c) 2006 Piotr Wyderski
13 // Copyright (c) 2006 Tomas Puverle
14 // Copyright (c) 2006 Peter Dimov
15 //
16 // Distributed under the Boost Software License, Version 1.0.
17 // See accompanying file LICENSE_1_0.txt or copy at
18 // http://www.boost.org/LICENSE_1_0.txt
19 //
20 // Thanks to Michael van der Westhuizen
21 
23 #include <inttypes.h> // int32_t
24 
25 namespace boost
26 {
27 
28 namespace detail
29 {
30 
31 inline int32_t compare_and_swap( int32_t * dest_, int32_t compare_, int32_t swap_ )
32 {
33  __asm__ __volatile__( "cas [%1], %2, %0"
34  : "+r" (swap_)
35  : "r" (dest_), "r" (compare_)
36  : "memory" );
37 
38  return swap_;
39 }
40 
41 inline int32_t atomic_fetch_and_add( int32_t * pw, int32_t dv )
42 {
43  // long r = *pw;
44  // *pw += dv;
45  // return r;
46 
47  for( ;; )
48  {
49  int32_t r = *pw;
50 
51  if( __builtin_expect((compare_and_swap(pw, r, r + dv) == r), 1) )
52  {
53  return r;
54  }
55  }
56 }
57 
58 inline void atomic_increment( int32_t * pw )
59 {
60  atomic_fetch_and_add( pw, 1 );
61 }
62 
63 inline int32_t atomic_decrement( int32_t * pw )
64 {
65  return atomic_fetch_and_add( pw, -1 );
66 }
67 
68 inline int32_t atomic_conditional_increment( int32_t * pw )
69 {
70  // long r = *pw;
71  // if( r != 0 ) ++*pw;
72  // return r;
73 
74  for( ;; )
75  {
76  int32_t r = *pw;
77 
78  if( r == 0 )
79  {
80  return r;
81  }
82 
83  if( __builtin_expect( ( compare_and_swap( pw, r, r + 1 ) == r ), 1 ) )
84  {
85  return r;
86  }
87  }
88 }
89 
90 class sp_counted_base
91 {
92 private:
93 
96 
97  int32_t use_count_; // #shared
98  int32_t weak_count_; // #weak + (#shared != 0)
99 
100 public:
101 
103  {
104  }
105 
106  virtual ~sp_counted_base() // nothrow
107  {
108  }
109 
110  // dispose() is called when use_count_ drops to zero, to release
111  // the resources managed by *this.
112 
113  virtual void dispose() = 0; // nothrow
114 
115  // destroy() is called when weak_count_ drops to zero.
116 
117  virtual void destroy() // nothrow
118  {
119  delete this;
120  }
121 
122  virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
123  virtual void * get_untyped_deleter() = 0;
124 
126  {
128  }
129 
130  bool add_ref_lock() // true on success
131  {
133  }
134 
135  void release() // nothrow
136  {
137  if( atomic_decrement( &use_count_ ) == 1 )
138  {
139  dispose();
140  weak_release();
141  }
142  }
143 
144  void weak_add_ref() // nothrow
145  {
147  }
148 
149  void weak_release() // nothrow
150  {
151  if( atomic_decrement( &weak_count_ ) == 1 )
152  {
153  destroy();
154  }
155  }
156 
157  long use_count() const // nothrow
158  {
159  return const_cast< int32_t const volatile & >( use_count_ );
160  }
161 };
162 
163 } // namespace detail
164 
165 } // namespace boost
166 
167 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_GCC_SPARC_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
BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE.
boost::detail::sp_counted_base::destroy
virtual void destroy()
Definition: sp_counted_base_gcc_sparc.hpp:117
boost::detail::sp_counted_base::add_ref_copy
void add_ref_copy()
Definition: sp_counted_base_gcc_sparc.hpp:125
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_gcc_sparc.hpp:130
boost::detail::compare_and_swap
int32_t compare_and_swap(int32_t *dest_, int32_t compare_, int32_t swap_)
Definition: sp_counted_base_gcc_sparc.hpp:31
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_gcc_sparc.hpp:157
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_gcc_sparc.hpp:106
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_gcc_sparc.hpp:135
boost::detail::atomic_decrement
int atomic_decrement(int *pw)
Definition: sp_counted_base_acc_ia64.hpp:34
boost::detail::atomic_fetch_and_add
int32_t atomic_fetch_and_add(int32_t *pw, int32_t dv)
Definition: sp_counted_base_gcc_sparc.hpp:41
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
__volatile__
#define __volatile__
Definition: linux.hpp:92
boost::detail::sp_counted_base::weak_add_ref
void weak_add_ref()
Definition: sp_counted_base_gcc_sparc.hpp:144


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