/opt/workspace/qpid/tags/M2/Final/cpp/lib/common/sys/AtomicCount.h

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

Generated on Mon Nov 26 19:13:17 2007 for Qpid by  doxygen 1.5.1