TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/common/atomic.hpp
Go to the documentation of this file.
00001 #ifndef _TUTTLE_ATOMIC_HPP_
00002 #define _TUTTLE_ATOMIC_HPP_
00003 
00004 #ifndef WITHOUT_BOOST_ATOMIC
00005 
00006 #include <boost/atomic/atomic.hpp>
00007 
00008 #else
00009 // For compatibility with boost versions without boost.atomic (added in 1.53).
00010 // Use mutex instead of atomic.
00011 
00012 #define BOOST_ATOMIC_HPP
00013 #include <boost/thread/mutex.hpp>
00014 #include <boost/memory_order.hpp>
00015 
00016 namespace boost
00017 {
00018 
00019 // Fake atomic class using mutex to work without boost.atomic.
00020 template<typename T>
00021 class atomic
00022 {
00023 public:
00024     typedef T value_type;
00025         atomic(const T v)
00026         : _value(v)
00027         {}
00028 
00029         void store( const T v, const memory_order unused )
00030         {
00031                 boost::mutex::scoped_lock locker( _mutex );
00032                 _value = v;
00033         }
00034 
00035         value_type load( const memory_order unused ) const
00036         {
00037                 boost::mutex::scoped_lock locker( _mutex );
00038                 return _value;
00039         }
00040 
00041 private:
00042         T _value;
00043         mutable boost::mutex _mutex;
00044 };
00045 
00046 typedef atomic<bool> atomic_bool;
00047 
00048 }
00049 
00050 #endif
00051 
00052 #endif