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 #include <boost/detail/atomic_count.hpp>
00023 #include <boost/noncopyable.hpp>
00024
00025 namespace qpid {
00026 namespace sys {
00027
00031 class AtomicCount : boost::noncopyable {
00032 public:
00033 class ScopedDecrement : boost::noncopyable {
00034 public:
00036 ScopedDecrement(AtomicCount& c) : count(c) { value = --count; }
00037 ~ScopedDecrement() { ++count; }
00039 operator long() { return value; }
00040 private:
00041 AtomicCount& count;
00042 long value;
00043 };
00044
00045 class ScopedIncrement : boost::noncopyable {
00046 public:
00048 ScopedIncrement(AtomicCount& c) : count(c) { ++count; }
00049 ~ScopedIncrement() { --count; }
00050 private:
00051 AtomicCount& count;
00052 };
00053
00054 AtomicCount(long value = 0) : count(value) {}
00055
00056 void operator++() { ++count ; }
00057
00058 long operator--() { return --count; }
00059
00060 operator long() const { return count; }
00061
00062
00063 private:
00064 boost::detail::atomic_count count;
00065 };
00066
00067
00068 }}
00069
00070
00071 #endif // _posix_AtomicCount_h