1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/boost/detail/sp_counted_base_gcc_ia64.hpp Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,157 @@
1.4 +#ifndef BOOST_DETAIL_SP_COUNTED_BASE_GCC_IA64_HPP_INCLUDED
1.5 +#define BOOST_DETAIL_SP_COUNTED_BASE_GCC_IA64_HPP_INCLUDED
1.6 +
1.7 +//
1.8 +// detail/sp_counted_base_gcc_ia64.hpp - g++ on IA64
1.9 +//
1.10 +// Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
1.11 +// Copyright 2004-2006 Peter Dimov
1.12 +// Copyright 2005 Ben Hutchings
1.13 +//
1.14 +// Distributed under the Boost Software License, Version 1.0. (See
1.15 +// accompanying file LICENSE_1_0.txt or copy at
1.16 +// http://www.boost.org/LICENSE_1_0.txt)
1.17 +//
1.18 +//
1.19 +// Lock-free algorithm by Alexander Terekhov
1.20 +//
1.21 +
1.22 +#include <typeinfo>
1.23 +
1.24 +namespace boost
1.25 +{
1.26 +
1.27 +namespace detail
1.28 +{
1.29 +
1.30 +inline void atomic_increment( int * pw )
1.31 +{
1.32 + // ++*pw;
1.33 +
1.34 + int tmp;
1.35 +
1.36 + // No barrier is required here but fetchadd always has an acquire or
1.37 + // release barrier associated with it. We choose release as it should be
1.38 + // cheaper.
1.39 + __asm__ ("fetchadd4.rel %0=%1,1" :
1.40 + "=r"(tmp), "=m"(*pw) :
1.41 + "m"( *pw ));
1.42 +}
1.43 +
1.44 +inline int atomic_decrement( int * pw )
1.45 +{
1.46 + // return --*pw;
1.47 +
1.48 + int rv;
1.49 +
1.50 + __asm__ (" fetchadd4.rel %0=%1,-1 ;; \n"
1.51 + " cmp.eq p7,p0=1,%0 ;; \n"
1.52 + "(p7) ld4.acq %0=%1 " :
1.53 + "=&r"(rv), "=m"(*pw) :
1.54 + "m"( *pw ) :
1.55 + "p7");
1.56 +
1.57 + return rv;
1.58 +}
1.59 +
1.60 +inline int atomic_conditional_increment( int * pw )
1.61 +{
1.62 + // if( *pw != 0 ) ++*pw;
1.63 + // return *pw;
1.64 +
1.65 + int rv, tmp, tmp2;
1.66 +
1.67 + __asm__ ("0: ld4 %0=%3 ;; \n"
1.68 + " cmp.eq p7,p0=0,%0 ;; \n"
1.69 + "(p7) br.cond.spnt 1f \n"
1.70 + " mov ar.ccv=%0 \n"
1.71 + " add %1=1,%0 ;; \n"
1.72 + " cmpxchg4.acq %2=%3,%1,ar.ccv ;; \n"
1.73 + " cmp.ne p7,p0=%0,%2 ;; \n"
1.74 + "(p7) br.cond.spnt 0b \n"
1.75 + " mov %0=%1 ;; \n"
1.76 + "1:" :
1.77 + "=&r"(rv), "=&r"(tmp), "=&r"(tmp2), "=m"(*pw) :
1.78 + "m"( *pw ) :
1.79 + "ar.ccv", "p7");
1.80 +
1.81 + return rv;
1.82 +}
1.83 +
1.84 +class sp_counted_base
1.85 +{
1.86 +private:
1.87 +
1.88 + sp_counted_base( sp_counted_base const & );
1.89 + sp_counted_base & operator= ( sp_counted_base const & );
1.90 +
1.91 + int use_count_; // #shared
1.92 + int weak_count_; // #weak + (#shared != 0)
1.93 +
1.94 +public:
1.95 +
1.96 + sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
1.97 + {
1.98 + }
1.99 +
1.100 + virtual ~sp_counted_base() // nothrow
1.101 + {
1.102 + }
1.103 +
1.104 + // dispose() is called when use_count_ drops to zero, to release
1.105 + // the resources managed by *this.
1.106 +
1.107 + virtual void dispose() = 0; // nothrow
1.108 +
1.109 + // destroy() is called when weak_count_ drops to zero.
1.110 +
1.111 + virtual void destroy() // nothrow
1.112 + {
1.113 + delete this;
1.114 + }
1.115 +
1.116 + virtual void * get_deleter( std::type_info const & ti ) = 0;
1.117 +
1.118 + void add_ref_copy()
1.119 + {
1.120 + atomic_increment( &use_count_ );
1.121 + }
1.122 +
1.123 + bool add_ref_lock() // true on success
1.124 + {
1.125 + return atomic_conditional_increment( &use_count_ ) != 0;
1.126 + }
1.127 +
1.128 + void release() // nothrow
1.129 + {
1.130 + if( atomic_decrement( &use_count_ ) == 0 )
1.131 + {
1.132 + dispose();
1.133 + weak_release();
1.134 + }
1.135 + }
1.136 +
1.137 + void weak_add_ref() // nothrow
1.138 + {
1.139 + atomic_increment( &weak_count_ );
1.140 + }
1.141 +
1.142 + void weak_release() // nothrow
1.143 + {
1.144 + if( atomic_decrement( &weak_count_ ) == 0 )
1.145 + {
1.146 + destroy();
1.147 + }
1.148 + }
1.149 +
1.150 + long use_count() const // nothrow
1.151 + {
1.152 + return static_cast<int const volatile &>( use_count_ ); // TODO use ld.acq here
1.153 + }
1.154 +};
1.155 +
1.156 +} // namespace detail
1.157 +
1.158 +} // namespace boost
1.159 +
1.160 +#endif // #ifndef BOOST_DETAIL_SP_COUNTED_BASE_GCC_IA64_HPP_INCLUDED