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_GCC_HPP_INCLUDED
0002 #define BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED
0003 
0004 //
0005 //  boost/detail/atomic_count_gcc.hpp
0006 //
0007 //  atomic_count for GNU libstdc++ v3
0008 //
0009 //  http://gcc.gnu.org/onlinedocs/porting/Thread-safety.html
0010 //
0011 //  Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
0012 //  Copyright (c) 2002 Lars Gullik Bjønnes <larsbj@lyx.org>
0013 //  Copyright 2003-2005 Peter Dimov
0014 //
0015 //  Distributed under the Boost Software License, Version 1.0. (See
0016 //  accompanying file LICENSE_1_0.txt or copy at
0017 //  http://www.boost.org/LICENSE_1_0.txt)
0018 //
0019 
0020 #if __GNUC__ * 100 + __GNUC_MINOR__ >= 402
0021 # include <ext/atomicity.h> 
0022 #else 
0023 # include <bits/atomicity.h>
0024 #endif
0025 
0026 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
0027 
0028 #include <boost/config/pragma_message.hpp>
0029 BOOST_PRAGMA_MESSAGE("Using libstdc++ atomic_count")
0030 
0031 #endif
0032 
0033 namespace boost
0034 {
0035 
0036 namespace detail
0037 {
0038 
0039 #if defined(__GLIBCXX__) // g++ 3.4+
0040 
0041 using __gnu_cxx::__atomic_add;
0042 using __gnu_cxx::__exchange_and_add;
0043 
0044 #endif
0045 
0046 class atomic_count
0047 {
0048 public:
0049 
0050     explicit atomic_count( long v ) : value_( v ) {}
0051 
0052     long operator++()
0053     {
0054         return __exchange_and_add( &value_, +1 ) + 1;
0055     }
0056 
0057     long operator--()
0058     {
0059         return __exchange_and_add( &value_, -1 ) - 1;
0060     }
0061 
0062     operator long() const
0063     {
0064         return __exchange_and_add( &value_, 0 );
0065     }
0066 
0067 private:
0068 
0069     atomic_count(atomic_count const &);
0070     atomic_count & operator=(atomic_count const &);
0071 
0072     mutable _Atomic_word value_;
0073 };
0074 
0075 } // namespace detail
0076 
0077 } // namespace boost
0078 
0079 #endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED