1 #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED 2 #define BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED 3 4 // 5 // boost/detail/atomic_count_gcc.hpp 6 // 7 // atomic_count for GNU libstdc++ v3 8 // 9 // http://gcc.gnu.org/onlinedocs/porting/Thread-safety.html 10 // 11 // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd. 12 // Copyright (c) 2002 Lars Gullik Bjønnes <larsbj@lyx.org> 13 // Copyright 2003-2005 Peter Dimov 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 #if __GNUC__ * 100 + __GNUC_MINOR__ >= 402 21 # include <ext/atomicity.h> 22 #else 23 # include <bits/atomicity.h> 24 #endif 25 26 #if defined(BOOST_SP_REPORT_IMPLEMENTATION) 27 28 #include <boost/config/pragma_message.hpp> 29 BOOST_PRAGMA_MESSAGE("Using libstdc++ atomic_count") 30 31 #endif 32 33 namespace boost 34 { 35 36 namespace detail 37 { 38 39 #if defined(__GLIBCXX__) // g++ 3.4+ 40 41 using __gnu_cxx::__atomic_add; 42 using __gnu_cxx::__exchange_and_add; 43 44 #endif 45 46 class atomic_count 47 { 48 public: 49 atomic_count(long v)50 explicit atomic_count( long v ) : value_( v ) {} 51 operator ++()52 long operator++() 53 { 54 return __exchange_and_add( &value_, +1 ) + 1; 55 } 56 operator --()57 long operator--() 58 { 59 return __exchange_and_add( &value_, -1 ) - 1; 60 } 61 operator long() const62 operator long() const 63 { 64 return __exchange_and_add( &value_, 0 ); 65 } 66 67 private: 68 69 atomic_count(atomic_count const &); 70 atomic_count & operator=(atomic_count const &); 71 72 mutable _Atomic_word value_; 73 }; 74 75 } // namespace detail 76 77 } // namespace boost 78 79 #endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED 80