sp_counted_base_gcc_mips.hpp
Go to the documentation of this file.
1 #ifndef BOOST_DETAIL_SP_COUNTED_BASE_GCC_MIPS_HPP_INCLUDED
2 #define BOOST_DETAIL_SP_COUNTED_BASE_GCC_MIPS_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 //
11 // detail/sp_counted_base_gcc_mips.hpp - g++ on MIPS
12 //
13 // Copyright (c) 2009, Spirent Communications, Inc.
14 //
15 // Distributed under the Boost Software License, Version 1.0. (See
16 // accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
18 //
19 //
20 // Lock-free algorithm by Alexander Terekhov
21 //
22 
24 
25 namespace boost
26 {
27 
28 namespace detail
29 {
30 
31 inline void atomic_increment( int * pw )
32 {
33  // ++*pw;
34 
35  int tmp;
36 
37  __asm__ __volatile__
38  (
39  "0:\n\t"
40  ".set push\n\t"
41  ".set mips2\n\t"
42  "ll %0, %1\n\t"
43  "addiu %0, 1\n\t"
44  "sc %0, %1\n\t"
45  ".set pop\n\t"
46  "beqz %0, 0b":
47  "=&r"( tmp ), "=m"( *pw ):
48  "m"( *pw )
49  );
50 }
51 
52 inline int atomic_decrement( int * pw )
53 {
54  // return --*pw;
55 
56  int rv, tmp;
57 
58  __asm__ __volatile__
59  (
60  "0:\n\t"
61  ".set push\n\t"
62  ".set mips2\n\t"
63  "ll %1, %2\n\t"
64  "addiu %0, %1, -1\n\t"
65  "sc %0, %2\n\t"
66  ".set pop\n\t"
67  "beqz %0, 0b\n\t"
68  "addiu %0, %1, -1":
69  "=&r"( rv ), "=&r"( tmp ), "=m"( *pw ):
70  "m"( *pw ):
71  "memory"
72  );
73 
74  return rv;
75 }
76 
77 inline int atomic_conditional_increment( int * pw )
78 {
79  // if( *pw != 0 ) ++*pw;
80  // return *pw;
81 
82  int rv, tmp;
83 
84  __asm__ __volatile__
85  (
86  "0:\n\t"
87  ".set push\n\t"
88  ".set mips2\n\t"
89  "ll %0, %2\n\t"
90  "beqz %0, 1f\n\t"
91  "addiu %1, %0, 1\n\t"
92  "sc %1, %2\n\t"
93  ".set pop\n\t"
94  "beqz %1, 0b\n\t"
95  "addiu %0, %0, 1\n\t"
96  "1:":
97  "=&r"( rv ), "=&r"( tmp ), "=m"( *pw ):
98  "m"( *pw ):
99  "memory"
100  );
101 
102  return rv;
103 }
104 
105 class sp_counted_base
106 {
107 private:
108 
109  sp_counted_base( sp_counted_base const & );
111 
112  int use_count_; // #shared
113  int weak_count_; // #weak + (#shared != 0)
114 
115 public:
116 
118  {
119  }
120 
121  virtual ~sp_counted_base() // nothrow
122  {
123  }
124 
125  // dispose() is called when use_count_ drops to zero, to release
126  // the resources managed by *this.
127 
128  virtual void dispose() = 0; // nothrow
129 
130  // destroy() is called when weak_count_ drops to zero.
131 
132  virtual void destroy() // nothrow
133  {
134  delete this;
135  }
136 
137  virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
138  virtual void * get_untyped_deleter() = 0;
139 
141  {
143  }
144 
145  bool add_ref_lock() // true on success
146  {
148  }
149 
150  void release() // nothrow
151  {
152  if( atomic_decrement( &use_count_ ) == 0 )
153  {
154  dispose();
155  weak_release();
156  }
157  }
158 
159  void weak_add_ref() // nothrow
160  {
162  }
163 
164  void weak_release() // nothrow
165  {
166  if( atomic_decrement( &weak_count_ ) == 0 )
167  {
168  destroy();
169  }
170  }
171 
172  long use_count() const // nothrow
173  {
174  return static_cast<int const volatile &>( use_count_ );
175  }
176 };
177 
178 } // namespace detail
179 
180 } // namespace boost
181 
182 #endif // #ifndef BOOST_DETAIL_SP_COUNTED_BASE_GCC_MIPS_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_mips.hpp:132
boost::detail::sp_counted_base::add_ref_copy
void add_ref_copy()
Definition: sp_counted_base_gcc_mips.hpp:140
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_mips.hpp:145
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_mips.hpp:172
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_mips.hpp:121
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_mips.hpp:150
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
__volatile__
#define __volatile__
Definition: linux.hpp:92
boost::detail::sp_counted_base::weak_add_ref
void weak_add_ref()
Definition: sp_counted_base_gcc_mips.hpp:159


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