8#ifndef INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_IPP
9#define INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_IPP
13#include <boost/bind.hpp>
14#include <boost/utility.hpp>
15#include <boost/function.hpp>
16#include <boost/circular_buffer.hpp>
17#include <boost/thread/condition.hpp>
18#include <boost/thread/locks.hpp>
20namespace uhd{
namespace transport{
35 boost::mutex::scoped_lock lock(_mutex);
40 _buffer.push_front(elem);
41 _empty_cond.notify_one();
47 boost::mutex::scoped_lock lock(_mutex);
51 _buffer.push_front(elem);
52 _empty_cond.notify_one();
56 _buffer.push_front(elem);
57 _empty_cond.notify_one();
64 boost::mutex::scoped_lock lock(_mutex);
67 _full_cond.wait(lock, _not_full_fcn);
69 _buffer.push_front(elem);
70 _empty_cond.notify_one();
75 boost::mutex::scoped_lock lock(_mutex);
78 if (not _full_cond.timed_wait(lock,
79 to_time_dur(timeout), _not_full_fcn))
84 _buffer.push_front(elem);
85 _empty_cond.notify_one();
91 boost::mutex::scoped_lock lock(_mutex);
97 _full_cond.notify_one();
103 boost::mutex::scoped_lock lock(_mutex);
106 _empty_cond.wait(lock, _not_empty_fcn);
108 this->pop_back(elem);
109 _full_cond.notify_one();
114 boost::mutex::scoped_lock lock(_mutex);
117 if (not _empty_cond.timed_wait(lock, to_time_dur(timeout),
123 this->pop_back(elem);
124 _full_cond.notify_one();
130 boost::condition _empty_cond, _full_cond;
131 boost::circular_buffer<elem_type> _buffer;
133 bool not_full(
void)
const{
return not _buffer.full();}
134 bool not_empty(
void)
const{
return not _buffer.empty();}
136 boost::function<bool(
void)> _not_full_fcn, _not_empty_fcn;
146 elem = _buffer.back();
147 _buffer.back() = elem_type();
151 static UHD_INLINE boost::posix_time::time_duration to_time_dur(
double timeout)
153 return boost::posix_time::microseconds(
long(timeout*1e6));
Definition bounded_buffer.ipp:23
UHD_INLINE bool pop_with_haste(elem_type &elem)
Definition bounded_buffer.ipp:89
UHD_INLINE bool pop_with_timed_wait(elem_type &elem, double timeout)
Definition bounded_buffer.ipp:112
UHD_INLINE void pop_with_wait(elem_type &elem)
Definition bounded_buffer.ipp:101
bounded_buffer_detail(size_t capacity)
Definition bounded_buffer.ipp:26
UHD_INLINE bool push_with_timed_wait(const elem_type &elem, double timeout)
Definition bounded_buffer.ipp:73
UHD_INLINE void push_with_wait(const elem_type &elem)
Definition bounded_buffer.ipp:62
UHD_INLINE bool push_with_haste(const elem_type &elem)
Definition bounded_buffer.ipp:33
UHD_INLINE bool push_with_pop_on_full(const elem_type &elem)
Definition bounded_buffer.ipp:45
#define UHD_INLINE
Definition config.h:53
Definition build_info.hpp:13
boost::noncopyable noncopyable
Definition noncopyable.hpp:46