18 #ifndef INCLUDED_UHD_UTILS_ATOMIC_HPP 19 #define INCLUDED_UHD_UTILS_ATOMIC_HPP 23 #include <boost/thread/thread.hpp> 24 #include <boost/interprocess/detail/atomic.hpp> 26 #include <boost/version.hpp> 27 #if BOOST_VERSION >= 104800 28 # define BOOST_IPC_DETAIL boost::interprocess::ipcdetail 30 # define BOOST_IPC_DETAIL boost::interprocess::detail 45 UHD_INLINE boost::uint32_t
cas(boost::uint32_t newval, boost::uint32_t cmp){
46 return BOOST_IPC_DETAIL::atomic_cas32(&_num, newval, cmp);
51 BOOST_IPC_DETAIL::atomic_write32(&_num, newval);
56 return BOOST_IPC_DETAIL::atomic_read32(&_num);
61 return BOOST_IPC_DETAIL::atomic_inc32(&_num);
66 return BOOST_IPC_DETAIL::atomic_dec32(&_num);
69 private:
volatile boost::uint32_t _num;
89 while (_count.read() != _size){
90 boost::this_thread::interruption_point();
91 boost::this_thread::yield();
109 boost::uint32_t value,
112 if (cond.
read() == value)
return true;
114 while (cond.
read() != value){
116 boost::this_thread::interruption_point();
117 boost::this_thread::yield();
UHD_INLINE boost::uint32_t read(void)
Gets the current value of the atomic integer.
Definition: atomic.hpp:55
UHD_INLINE void wait(void)
Wait on the barrier condition.
Definition: atomic.hpp:86
UHD_INLINE void release(void)
Definition: atomic.hpp:132
Definition: atomic.hpp:76
Definition: time_spec.hpp:39
A 32-bit integer that can be atomically accessed.
Definition: atomic.hpp:36
UHD_INLINE bool spin_wait_with_timeout(atomic_uint32_t &cond, boost::uint32_t value, const double timeout)
Definition: atomic.hpp:107
static time_spec_t get_system_time(void)
#define UHD_API
Definition: config.hpp:76
Definition: convert.hpp:28
UHD_INLINE boost::uint32_t cas(boost::uint32_t newval, boost::uint32_t cmp)
Compare with cmp, swap with newval if same, return old value.
Definition: atomic.hpp:45
UHD_INLINE bool claim_with_wait(const double timeout)
Definition: atomic.hpp:136
#define UHD_INLINE
Definition: config.hpp:67
UHD_INLINE atomic_uint32_t(void)
Create a new atomic 32-bit integer, initialized to zero.
Definition: atomic.hpp:40
UHD_INLINE void write(const boost::uint32_t newval)
Sets the atomic integer to a new value.
Definition: atomic.hpp:50
UHD_INLINE boost::uint32_t inc(void)
Increment by 1 and return the old value.
Definition: atomic.hpp:60
simple_claimer(void)
Definition: atomic.hpp:128
UHD_INLINE boost::uint32_t dec(void)
Decrement by 1 and return the old value.
Definition: atomic.hpp:65
void resize(const size_t size)
Resize the barrier for N threads.
Definition: atomic.hpp:80
Definition: atomic.hpp:126