atomic_count_gcc.hpp
Go to the documentation of this file.
00001 #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED
00002 #define BOOST_SMART_PTR_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 #if __GNUC__ * 100 + __GNUC_MINOR__ >= 402
00021 # include <ext/atomicity.h> 
00022 #else 
00023 # include <bits/atomicity.h>
00024 #endif
00025 
00026 namespace boost
00027 {
00028 
00029 namespace detail
00030 {
00031 
00032 #if defined(__GLIBCXX__) // g++ 3.4+
00033 
00034 using __gnu_cxx::__atomic_add;
00035 using __gnu_cxx::__exchange_and_add;
00036 
00037 #endif
00038 
00039 class atomic_count
00040 {
00041 public:
00042 
00043     explicit atomic_count( long v ) : value_( v ) {}
00044 
00045     long operator++()
00046     {
00047         return __exchange_and_add( &value_, +1 ) + 1;
00048     }
00049 
00050     long operator--()
00051     {
00052         return __exchange_and_add( &value_, -1 ) - 1;
00053     }
00054 
00055     operator long() const
00056     {
00057         return __exchange_and_add( &value_, 0 );
00058     }
00059 
00060 private:
00061 
00062     atomic_count(atomic_count const &);
00063     atomic_count & operator=(atomic_count const &);
00064 
00065     mutable _Atomic_word value_;
00066 };
00067 
00068 } // namespace detail
00069 
00070 } // namespace boost
00071 
00072 #endif // #ifndef BOOST_SMART_PTR_DETAIL_ATOMIC_COUNT_GCC_HPP_INCLUDED


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:28