atomic_count_gcc.hpp

Go to the documentation of this file.
00001 #ifndef BOOST_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED
00002 #define BOOST_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED
00003 
00004 //
00005 //  boost/detail/atomic_count_gcc.hpp
00006 //
00007 //  atomic_count for GNU libstdc++ v3
00008 //
00009 //  http://gcc.gnu.org/onlinedocs/porting/Thread-safety.html
00010 //
00011 //  Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
00012 //  Copyright (c) 2002 Lars Gullik Bjønnes <larsbj@lyx.org>
00013 //  Copyright 2003-2005 Peter Dimov
00014 //
00015 //  Distributed under the Boost Software License, Version 1.0. (See
00016 //  accompanying file LICENSE_1_0.txt or copy at
00017 //  http://www.boost.org/LICENSE_1_0.txt)
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 } // namespace detail
00065 
00066 } // namespace boost
00067 
00068 #endif // #ifndef BOOST_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED

Generated on Wed Jan 21 15:32:09 2009 for SystemC by  doxygen 1.5.5