Go to the documentation of this file.00001 #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED
00002 #define BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #if __GNUC__ * 100 + __GNUC_MINOR__ >= 402
00021 # include <ext/atomicity.h>
00022 #else
00023 # include <bits/atomicity.h>
00024 #endif
00025
00026 namespace boost
00027 {
00028
00029 namespace detail
00030 {
00031
00032 #if defined(__GLIBCXX__) // g++ 3.4+
00033
00034 using __gnu_cxx::__atomic_add;
00035 using __gnu_cxx::__exchange_and_add;
00036
00037 #endif
00038
00039 class atomic_count
00040 {
00041 public:
00042
00043 explicit atomic_count( long v ) : value_( v ) {}
00044
00045 long operator++()
00046 {
00047 return __exchange_and_add( &value_, +1 ) + 1;
00048 }
00049
00050 long operator--()
00051 {
00052 return __exchange_and_add( &value_, -1 ) - 1;
00053 }
00054
00055 operator long() const
00056 {
00057 return __exchange_and_add( &value_, 0 );
00058 }
00059
00060 private:
00061
00062 atomic_count(atomic_count const &);
00063 atomic_count & operator=(atomic_count const &);
00064
00065 mutable _Atomic_word value_;
00066 };
00067
00068 }
00069
00070 }
00071
00072 #endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED