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