12#include <condition_variable>
13#include <boost/circular_buffer.hpp>
19template <
typename elem_type>
25 _not_full_fcn = std::bind(&bounded_buffer_detail<elem_type>::not_full,
this);
26 _not_empty_fcn = std::bind(&bounded_buffer_detail<elem_type>::not_empty,
this);
31 std::unique_lock<std::mutex> lock(_mutex);
35 _buffer.push_front(elem);
36 _empty_cond.notify_one();
42 std::lock_guard<std::mutex> lock(_mutex);
45 _buffer.push_front(elem);
46 _empty_cond.notify_one();
49 _buffer.push_front(elem);
50 _empty_cond.notify_one();
57 std::unique_lock<std::mutex> lock(_mutex);
59 _full_cond.wait(lock, _not_full_fcn);
61 _buffer.push_front(elem);
62 _empty_cond.notify_one();
67 std::unique_lock<std::mutex> lock(_mutex);
69 if (not _full_cond.wait_for(lock, to_time_dur(timeout), _not_full_fcn)) {
73 _buffer.push_front(elem);
74 _empty_cond.notify_one();
80 std::unique_lock<std::mutex> lock(_mutex);
81 if (_buffer.empty()) {
85 _full_cond.notify_one();
91 std::unique_lock<std::mutex> lock(_mutex);
92 if (_buffer.empty()) {
93 _empty_cond.wait(lock, _not_empty_fcn);
96 _full_cond.notify_one();
101 std::unique_lock<std::mutex> lock(_mutex);
102 if (_buffer.empty()) {
103 if (not _empty_cond.wait_for(lock, to_time_dur(timeout), _not_empty_fcn)) {
107 this->pop_back(elem);
108 _full_cond.notify_one();
114 std::unique_lock<std::mutex> lock(_mutex);
115 std::vector<elem_type> retval(_buffer.size());
116 for (
size_t i = 0; i < retval.size(); ++i) {
118 this->pop_back(retval[i]);
120 _full_cond.notify_all();
126 std::condition_variable _empty_cond, _full_cond;
127 boost::circular_buffer<elem_type> _buffer;
129 bool not_full(
void)
const
131 return not _buffer.full();
133 bool not_empty(
void)
const
135 return not _buffer.empty();
138 std::function<bool(
void)> _not_full_fcn, _not_empty_fcn;
148 elem = _buffer.back();
149 _buffer.back() = elem_type();
153 static inline std::chrono::microseconds to_time_dur(
double timeout)
155 return std::chrono::microseconds(
long(timeout * 1e6));
UHD_INLINE bool pop_with_haste(elem_type &elem)
Definition bounded_buffer.ipp:78
UHD_INLINE bool pop_with_timed_wait(elem_type &elem, double timeout)
Definition bounded_buffer.ipp:99
UHD_INLINE void pop_with_wait(elem_type &elem)
Definition bounded_buffer.ipp:89
bounded_buffer_detail(size_t capacity)
Definition bounded_buffer.ipp:23
UHD_INLINE bool push_with_timed_wait(const elem_type &elem, double timeout)
Definition bounded_buffer.ipp:65
UHD_INLINE void push_with_wait(const elem_type &elem)
Definition bounded_buffer.ipp:55
UHD_INLINE bool push_with_haste(const elem_type &elem)
Definition bounded_buffer.ipp:29
UHD_INLINE bool push_with_pop_on_full(const elem_type &elem)
Definition bounded_buffer.ipp:40
UHD_INLINE std::vector< elem_type > pop_all()
Definition bounded_buffer.ipp:112
#define UHD_INLINE
Definition config.h:65
Definition adapter_id.hpp:11
Definition build_info.hpp:12
boost::noncopyable noncopyable
Definition noncopyable.hpp:45