00001 #ifndef _posix_AtomicCount_h
00002 #define _posix_AtomicCount_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <boost/detail/atomic_count.hpp>
00026 #include <boost/noncopyable.hpp>
00027
00028 namespace qpid {
00029 namespace sys {
00030
00034 class AtomicCount : boost::noncopyable {
00035 public:
00036 class ScopedDecrement : boost::noncopyable {
00037 public:
00039 ScopedDecrement(AtomicCount& c) : count(c) { value = --count; }
00040 ~ScopedDecrement() { ++count; }
00042 operator long() { return value; }
00043 private:
00044 AtomicCount& count;
00045 long value;
00046 };
00047
00048 class ScopedIncrement : boost::noncopyable {
00049 public:
00051 ScopedIncrement(AtomicCount& c) : count(c) { ++count; }
00052 ~ScopedIncrement() { --count; }
00053 private:
00054 AtomicCount& count;
00055 };
00056
00057 AtomicCount(long value = 0) : count(value) {}
00058
00059 void operator++() { ++count ; }
00060
00061 long operator--() { return --count; }
00062
00063 operator long() const { return count; }
00064
00065
00066 private:
00067 boost::detail::atomic_count count;
00068 };
00069
00070
00071 }}
00072
00073
00074 #endif // _posix_AtomicCount_h