12#include <boost/circular_buffer.hpp>
13#include <boost/thread/condition.hpp>
14#include <boost/utility.hpp>
18namespace uhd{
namespace transport{
33 std::unique_lock<std::mutex> lock(_mutex);
37 _buffer.push_front(elem);
38 _empty_cond.notify_one();
44 std::lock_guard<std::mutex> lock(_mutex);
47 _buffer.push_front(elem);
48 _empty_cond.notify_one();
51 _buffer.push_front(elem);
52 _empty_cond.notify_one();
59 std::unique_lock<std::mutex> lock(_mutex);
62 _full_cond.wait(lock, _not_full_fcn);
64 _buffer.push_front(elem);
65 _empty_cond.notify_one();
70 std::unique_lock<std::mutex> lock(_mutex);
73 if (not _full_cond.timed_wait(lock,
74 to_time_dur(timeout), _not_full_fcn))
79 _buffer.push_front(elem);
80 _empty_cond.notify_one();
86 std::unique_lock<std::mutex> lock(_mutex);
87 if (_buffer.empty()) {
91 _full_cond.notify_one();
97 std::unique_lock<std::mutex> lock(_mutex);
100 _empty_cond.wait(lock, _not_empty_fcn);
102 this->pop_back(elem);
103 _full_cond.notify_one();
108 std::unique_lock<std::mutex> lock(_mutex);
109 if (_buffer.empty()) {
110 if (not _empty_cond.timed_wait(lock, to_time_dur(timeout),
116 this->pop_back(elem);
117 _full_cond.notify_one();
123 boost::condition _empty_cond, _full_cond;
124 boost::circular_buffer<elem_type> _buffer;
126 bool not_full(
void)
const{
return not _buffer.full();}
127 bool not_empty(
void)
const{
return not _buffer.empty();}
129 std::function<bool(
void)> _not_full_fcn, _not_empty_fcn;
139 elem = _buffer.back();
140 _buffer.back() = elem_type();
144 static UHD_INLINE boost::posix_time::time_duration to_time_dur(
double timeout)
146 return boost::posix_time::microseconds(
long(timeout*1e6));
Definition bounded_buffer.ipp:21
UHD_INLINE bool pop_with_haste(elem_type &elem)
Definition bounded_buffer.ipp:84
UHD_INLINE bool pop_with_timed_wait(elem_type &elem, double timeout)
Definition bounded_buffer.ipp:106
UHD_INLINE void pop_with_wait(elem_type &elem)
Definition bounded_buffer.ipp:95
bounded_buffer_detail(size_t capacity)
Definition bounded_buffer.ipp:24
UHD_INLINE bool push_with_timed_wait(const elem_type &elem, double timeout)
Definition bounded_buffer.ipp:68
UHD_INLINE void push_with_wait(const elem_type &elem)
Definition bounded_buffer.ipp:57
UHD_INLINE bool push_with_haste(const elem_type &elem)
Definition bounded_buffer.ipp:31
UHD_INLINE bool push_with_pop_on_full(const elem_type &elem)
Definition bounded_buffer.ipp:42
#define UHD_INLINE
Definition config.h:65
Definition build_info.hpp:12
boost::noncopyable noncopyable
Definition noncopyable.hpp:45