src/sysc/packages/boost/detail/atomic_count_linux.hpp

Go to the documentation of this file.
00001 #ifndef BOOST_DETAIL_ATOMIC_COUNT_LINUX_HPP_INCLUDED
00002 #define BOOST_DETAIL_ATOMIC_COUNT_LINUX_HPP_INCLUDED
00003 
00004 //
00005 //  boost/detail/atomic_count_linux.hpp
00006 //
00007 //  Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
00008 //
00009 //  Permission to copy, use, modify, sell and distribute this software
00010 //  is granted provided this copyright notice appears in all copies.
00011 //  This software is provided "as is" without express or implied
00012 //  warranty, and with no claim as to its suitability for any purpose.
00013 //
00014 
00015 //
00016 //  This implementation uses <asm/atomic.h>. This is a kernel header;
00017 //  using kernel headers in a user program may cause a number of problems,
00018 //  and not all flavors of Linux provide the atomic instructions.
00019 //
00020 //  This file is only provided because the performance of this implementation
00021 //  is significantly higher than the pthreads version. Use at your own risk
00022 //  (by defining BOOST_USE_ASM_ATOMIC_H.)
00023 //
00024 
00025 #include <asm/atomic.h>
00026 
00027 namespace boost
00028 {
00029 
00030 namespace detail
00031 {
00032 
00033 class atomic_count
00034 {
00035 public:
00036 
00037     explicit atomic_count(long v)
00038     {
00039         atomic_t init = ATOMIC_INIT(v);
00040         value_ = init;
00041     }
00042 
00043     void operator++()
00044     {
00045         atomic_inc(&value_);
00046     }
00047 
00048     long operator--()
00049     {
00050         return !atomic_dec_and_test(&value_);
00051     }
00052 
00053     operator long() const
00054     {
00055         return atomic_read(&value_);
00056     }
00057 
00058 private:
00059 
00060     atomic_count(atomic_count const &);
00061     atomic_count & operator=(atomic_count const &);
00062 
00063     atomic_t value_;
00064 };
00065 
00066 } // namespace detail
00067 
00068 } // namespace boost
00069 
00070 #endif // #ifndef BOOST_DETAIL_ATOMIC_COUNT_LINUX_HPP_INCLUDED

Generated on Wed Apr 25 13:53:28 2007 for SystemC by  doxygen 1.5.1