/home/aconway/svn/qpid/cpp/lib/common/sys/AtomicCount.h

00001 #ifndef _posix_AtomicCount_h
00002 #define _posix_AtomicCount_h
00003 
00004 /*
00005  *
00006  * Copyright (c) 2006 The Apache Software Foundation
00007  *
00008  * Licensed under the Apache License, Version 2.0 (the "License");
00009  * you may not use this file except in compliance with the License.
00010  * You may obtain a copy of the License at
00011  *
00012  *    http://www.apache.org/licenses/LICENSE-2.0
00013  *
00014  * Unless required by applicable law or agreed to in writing, software
00015  * distributed under the License is distributed on an "AS IS" BASIS,
00016  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00017  * See the License for the specific language governing permissions and
00018  * limitations under the License.
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

Generated on Thu Jan 25 11:48:13 2007 for Qpid by  doxygen 1.5.1