-#ifndef BOOST_DETAIL_SP_COUNTED_BASE_GCC_MIPS_HPP_INCLUDED\r
-#define BOOST_DETAIL_SP_COUNTED_BASE_GCC_MIPS_HPP_INCLUDED\r
-\r
-// MS compatible compilers support #pragma once\r
-\r
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)\r
-# pragma once\r
-#endif\r
-\r
-//\r
-// detail/sp_counted_base_gcc_mips.hpp - g++ on MIPS\r
-//\r
-// Copyright (c) 2009, Spirent Communications, Inc.\r
-//\r
-// Distributed under the Boost Software License, Version 1.0. (See\r
-// accompanying file LICENSE_1_0.txt or copy at\r
-// http://www.boost.org/LICENSE_1_0.txt)\r
-//\r
-//\r
-// Lock-free algorithm by Alexander Terekhov\r
-//\r
-\r
-#include <boost/detail/sp_typeinfo.hpp>\r
-\r
-namespace boost\r
-{\r
-\r
-namespace detail\r
-{\r
-\r
-inline void atomic_increment( int * pw )\r
-{\r
- // ++*pw;\r
-\r
- int tmp;\r
-\r
- __asm__ __volatile__\r
- (\r
- "0:\n\t"\r
- "ll %0, %1\n\t"\r
- "addiu %0, 1\n\t"\r
- "sc %0, %1\n\t"\r
- "beqz %0, 0b":\r
- "=&r"( tmp ), "=m"( *pw ):\r
- "m"( *pw )\r
- );\r
-}\r
-\r
-inline int atomic_decrement( int * pw )\r
-{\r
- // return --*pw;\r
-\r
- int rv, tmp;\r
-\r
- __asm__ __volatile__\r
- (\r
- "0:\n\t"\r
- "ll %1, %2\n\t"\r
- "addiu %0, %1, -1\n\t"\r
- "sc %0, %2\n\t"\r
- "beqz %0, 0b\n\t"\r
- "addiu %0, %1, -1":\r
- "=&r"( rv ), "=&r"( tmp ), "=m"( *pw ):\r
- "m"( *pw ):\r
- "memory"\r
- );\r
-\r
- return rv;\r
-}\r
-\r
-inline int atomic_conditional_increment( int * pw )\r
-{\r
- // if( *pw != 0 ) ++*pw;\r
- // return *pw;\r
-\r
- int rv, tmp;\r
-\r
- __asm__ __volatile__\r
- (\r
- "0:\n\t"\r
- "ll %0, %2\n\t"\r
- "beqz %0, 1f\n\t"\r
- "addiu %1, %0, 1\n\t"\r
- "sc %1, %2\n\t"\r
- "beqz %1, 0b\n\t"\r
- "addiu %0, %0, 1\n\t"\r
- "1:":\r
- "=&r"( rv ), "=&r"( tmp ), "=m"( *pw ):\r
- "m"( *pw ):\r
- "memory"\r
- );\r
-\r
- return rv;\r
-}\r
-\r
-class sp_counted_base\r
-{\r
-private:\r
-\r
- sp_counted_base( sp_counted_base const & );\r
- sp_counted_base & operator= ( sp_counted_base const & );\r
-\r
- int use_count_; // #shared\r
- int weak_count_; // #weak + (#shared != 0)\r
-\r
-public:\r
-\r
- sp_counted_base(): use_count_( 1 ), weak_count_( 1 )\r
- {\r
- }\r
-\r
- virtual ~sp_counted_base() // nothrow\r
- {\r
- }\r
-\r
- // dispose() is called when use_count_ drops to zero, to release\r
- // the resources managed by *this.\r
-\r
- virtual void dispose() = 0; // nothrow\r
-\r
- // destroy() is called when weak_count_ drops to zero.\r
-\r
- virtual void destroy() // nothrow\r
- {\r
- delete this;\r
- }\r
-\r
- virtual void * get_deleter( sp_typeinfo const & ti ) = 0;\r
-\r
- void add_ref_copy()\r
- {\r
- atomic_increment( &use_count_ );\r
- }\r
-\r
- bool add_ref_lock() // true on success\r
- {\r
- return atomic_conditional_increment( &use_count_ ) != 0;\r
- }\r
-\r
- void release() // nothrow\r
- {\r
- if( atomic_decrement( &use_count_ ) == 0 )\r
- {\r
- dispose();\r
- weak_release();\r
- }\r
- }\r
-\r
- void weak_add_ref() // nothrow\r
- {\r
- atomic_increment( &weak_count_ );\r
- }\r
-\r
- void weak_release() // nothrow\r
- {\r
- if( atomic_decrement( &weak_count_ ) == 0 )\r
- {\r
- destroy();\r
- }\r
- }\r
-\r
- long use_count() const // nothrow\r
- {\r
- return static_cast<int const volatile &>( use_count_ );\r
- }\r
-};\r
-\r
-} // namespace detail\r
-\r
-} // namespace boost\r
-\r
-#endif // #ifndef BOOST_DETAIL_SP_COUNTED_BASE_GCC_MIPS_HPP_INCLUDED\r
+#ifndef BOOST_DETAIL_SP_COUNTED_BASE_GCC_MIPS_HPP_INCLUDED
+#define BOOST_DETAIL_SP_COUNTED_BASE_GCC_MIPS_HPP_INCLUDED
+
+// MS compatible compilers support #pragma once
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+//
+// detail/sp_counted_base_gcc_mips.hpp - g++ on MIPS
+//
+// Copyright (c) 2009, Spirent Communications, Inc.
+//
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+//
+// Lock-free algorithm by Alexander Terekhov
+//
+
+#include <boost/detail/sp_typeinfo.hpp>
+
+namespace boost
+{
+
+namespace detail
+{
+
+inline void atomic_increment( int * pw )
+{
+ // ++*pw;
+
+ int tmp;
+
+ __asm__ __volatile__
+ (
+ "0:\n\t"
+ "ll %0, %1\n\t"
+ "addiu %0, 1\n\t"
+ "sc %0, %1\n\t"
+ "beqz %0, 0b":
+ "=&r"( tmp ), "=m"( *pw ):
+ "m"( *pw )
+ );
+}
+
+inline int atomic_decrement( int * pw )
+{
+ // return --*pw;
+
+ int rv, tmp;
+
+ __asm__ __volatile__
+ (
+ "0:\n\t"
+ "ll %1, %2\n\t"
+ "addiu %0, %1, -1\n\t"
+ "sc %0, %2\n\t"
+ "beqz %0, 0b\n\t"
+ "addiu %0, %1, -1":
+ "=&r"( rv ), "=&r"( tmp ), "=m"( *pw ):
+ "m"( *pw ):
+ "memory"
+ );
+
+ return rv;
+}
+
+inline int atomic_conditional_increment( int * pw )
+{
+ // if( *pw != 0 ) ++*pw;
+ // return *pw;
+
+ int rv, tmp;
+
+ __asm__ __volatile__
+ (
+ "0:\n\t"
+ "ll %0, %2\n\t"
+ "beqz %0, 1f\n\t"
+ "addiu %1, %0, 1\n\t"
+ "sc %1, %2\n\t"
+ "beqz %1, 0b\n\t"
+ "addiu %0, %0, 1\n\t"
+ "1:":
+ "=&r"( rv ), "=&r"( tmp ), "=m"( *pw ):
+ "m"( *pw ):
+ "memory"
+ );
+
+ return rv;
+}
+
+class sp_counted_base
+{
+private:
+
+ sp_counted_base( sp_counted_base const & );
+ sp_counted_base & operator= ( sp_counted_base const & );
+
+ int use_count_; // #shared
+ int weak_count_; // #weak + (#shared != 0)
+
+public:
+
+ sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
+ {
+ }
+
+ virtual ~sp_counted_base() // nothrow
+ {
+ }
+
+ // dispose() is called when use_count_ drops to zero, to release
+ // the resources managed by *this.
+
+ virtual void dispose() = 0; // nothrow
+
+ // destroy() is called when weak_count_ drops to zero.
+
+ virtual void destroy() // nothrow
+ {
+ delete this;
+ }
+
+ virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
+
+ void add_ref_copy()
+ {
+ atomic_increment( &use_count_ );
+ }
+
+ bool add_ref_lock() // true on success
+ {
+ return atomic_conditional_increment( &use_count_ ) != 0;
+ }
+
+ void release() // nothrow
+ {
+ if( atomic_decrement( &use_count_ ) == 0 )
+ {
+ dispose();
+ weak_release();
+ }
+ }
+
+ void weak_add_ref() // nothrow
+ {
+ atomic_increment( &weak_count_ );
+ }
+
+ void weak_release() // nothrow
+ {
+ if( atomic_decrement( &weak_count_ ) == 0 )
+ {
+ destroy();
+ }
+ }
+
+ long use_count() const // nothrow
+ {
+ return static_cast<int const volatile &>( use_count_ );
+ }
+};
+
+} // namespace detail
+
+} // namespace boost
+
+#endif // #ifndef BOOST_DETAIL_SP_COUNTED_BASE_GCC_MIPS_HPP_INCLUDED