sp_counted_base_vacpp_ppc.hpp
Go to the documentation of this file.
1 #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_VACPP_PPC_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_VACPP_PPC_HPP_INCLUDED
3 
4 //
5 // detail/sp_counted_base_vacpp_ppc.hpp - xlC(vacpp) on POWER
6 // based on: detail/sp_counted_base_w32.hpp
7 //
8 // Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
9 // Copyright 2004-2005 Peter Dimov
10 // Copyright 2006 Michael van der Westhuizen
11 // Copyright 2012 IBM Corp.
12 //
13 // Distributed under the Boost Software License, Version 1.0. (See
14 // accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
16 //
17 //
18 // Lock-free algorithm by Alexander Terekhov
19 //
20 // Thanks to Ben Hitchings for the #weak + (#shared != 0)
21 // formulation
22 //
23 
25 
26 extern "builtin" void __lwsync(void);
27 extern "builtin" void __isync(void);
28 extern "builtin" int __fetch_and_add(volatile int* addr, int val);
29 extern "builtin" int __compare_and_swap(volatile int*, int*, int);
30 
31 namespace boost
32 {
33 
34 namespace detail
35 {
36 
37 inline void atomic_increment( int *pw )
38 {
39  // ++*pw;
40  __lwsync();
41  __fetch_and_add(pw, 1);
42  __isync();
43 }
44 
45 inline int atomic_decrement( int *pw )
46 {
47  // return --*pw;
48  __lwsync();
49  int originalValue = __fetch_and_add(pw, -1);
50  __isync();
51 
52  return (originalValue - 1);
53 }
54 
55 inline int atomic_conditional_increment( int *pw )
56 {
57  // if( *pw != 0 ) ++*pw;
58  // return *pw;
59 
60  __lwsync();
61  int v = *const_cast<volatile int*>(pw);
62  for (;;)
63  // loop until state is known
64  {
65  if (v == 0) return 0;
66  if (__compare_and_swap(pw, &v, v + 1))
67  {
68  __isync(); return (v + 1);
69  }
70  }
71 }
72 
73 class sp_counted_base
74 {
75 private:
76 
79 
80  int use_count_; // #shared
81  int weak_count_; // #weak + (#shared != 0)
82  char pad[64] __attribute__((__aligned__(64)));
83  // pad to prevent false sharing
84 public:
85 
87  {
88  }
89 
90  virtual ~sp_counted_base() // nothrow
91  {
92  }
93 
94  // dispose() is called when use_count_ drops to zero, to release
95  // the resources managed by *this.
96 
97  virtual void dispose() = 0; // nothrow
98 
99  // destroy() is called when weak_count_ drops to zero.
100 
101  virtual void destroy() // nothrow
102  {
103  delete this;
104  }
105 
106  virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
107  virtual void * get_untyped_deleter() = 0;
108 
110  {
112  }
113 
114  bool add_ref_lock() // true on success
115  {
117  }
118 
119  void release() // nothrow
120  {
121  if( atomic_decrement( &use_count_ ) == 0 )
122  {
123  dispose();
124  weak_release();
125  }
126  }
127 
128  void weak_add_ref() // nothrow
129  {
131  }
132 
133  void weak_release() // nothrow
134  {
135  if( atomic_decrement( &weak_count_ ) == 0 )
136  {
137  destroy();
138  }
139  }
140 
141  long use_count() const // nothrow
142  {
143  return *const_cast<volatile int*>(&use_count_);
144  }
145 };
146 
147 } // namespace detail
148 
149 } // namespace boost
150 
151 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_VACPP_PPC_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_vacpp_ppc.hpp:101
__fetch_and_add
builtin int __fetch_and_add(volatile int *addr, int val)
boost::detail::sp_counted_base::add_ref_copy
void add_ref_copy()
Definition: sp_counted_base_vacpp_ppc.hpp:109
sp_typeinfo.hpp
boost::detail::sp_counted_base::__attribute__
char pad[64] __attribute__((__aligned__(64)))
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_vacpp_ppc.hpp:114
__isync
builtin void __isync(void)
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_vacpp_ppc.hpp:141
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_vacpp_ppc.hpp:90
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
__compare_and_swap
builtin int __compare_and_swap(volatile int *, int *, int)
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_vacpp_ppc.hpp:119
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
__lwsync
builtin void __lwsync(void)
boost::detail::sp_counted_base::weak_add_ref
void weak_add_ref()
Definition: sp_counted_base_vacpp_ppc.hpp:128


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