Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:51:42

0001 #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_SYNC_HPP_INCLUDED
0002 #define BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_SYNC_HPP_INCLUDED
0003 
0004 //
0005 //  boost/detail/atomic_count_sync.hpp
0006 //
0007 //  atomic_count for g++ 4.1+
0008 //
0009 //  http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Atomic-Builtins.html
0010 //
0011 //  Copyright 2007 Peter Dimov
0012 //
0013 //  Distributed under the Boost Software License, Version 1.0. (See
0014 //  accompanying file LICENSE_1_0.txt or copy at
0015 //  http://www.boost.org/LICENSE_1_0.txt)
0016 //
0017 
0018 #include <boost/cstdint.hpp>
0019 
0020 #if defined( __ia64__ ) && defined( __INTEL_COMPILER )
0021 # include <ia64intrin.h>
0022 #endif
0023 
0024 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
0025 
0026 #include <boost/config/pragma_message.hpp>
0027 BOOST_PRAGMA_MESSAGE("Using __sync atomic_count")
0028 
0029 #endif
0030 
0031 namespace boost
0032 {
0033 
0034 namespace detail
0035 {
0036 
0037 class atomic_count
0038 {
0039 public:
0040 
0041     explicit atomic_count( long v ): value_( static_cast< boost::int_least32_t >( v ) )
0042     {
0043     }
0044 
0045     long operator++()
0046     {
0047         return __sync_add_and_fetch( &value_, 1 );
0048     }
0049 
0050     long operator--()
0051     {
0052         return __sync_add_and_fetch( &value_, -1 );
0053     }
0054 
0055     operator long() const
0056     {
0057         return __sync_fetch_and_add( &value_, 0 );
0058     }
0059 
0060 private:
0061 
0062     atomic_count(atomic_count const &);
0063     atomic_count & operator=(atomic_count const &);
0064 
0065     mutable boost::int_least32_t value_;
0066 };
0067 
0068 } // namespace detail
0069 
0070 } // namespace boost
0071 
0072 #endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_SYNC_HPP_INCLUDED