diff options
Diffstat (limited to 'host/include/uhd/transport/bounded_buffer.ipp')
-rw-r--r-- | host/include/uhd/transport/bounded_buffer.ipp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/host/include/uhd/transport/bounded_buffer.ipp b/host/include/uhd/transport/bounded_buffer.ipp index 7be2f987c..0d393ad64 100644 --- a/host/include/uhd/transport/bounded_buffer.ipp +++ b/host/include/uhd/transport/bounded_buffer.ipp @@ -37,9 +37,18 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/ _not_empty_fcn = boost::bind(&bounded_buffer_detail<elem_type>::not_empty, this); } + UHD_INLINE bool push_with_haste(const elem_type &elem){ + boost::mutex::scoped_lock lock(_mutex); + if (_buffer.full()) return false; + _buffer.push_front(elem); + lock.unlock(); + _empty_cond.notify_one(); + return true; + } + UHD_INLINE bool push_with_pop_on_full(const elem_type &elem){ boost::mutex::scoped_lock lock(_mutex); - if(_buffer.full()){ + if (_buffer.full()){ _buffer.pop_back(); _buffer.push_front(elem); lock.unlock(); @@ -55,6 +64,7 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/ } UHD_INLINE void push_with_wait(const elem_type &elem){ + if (this->push_with_haste(elem)) return; boost::mutex::scoped_lock lock(_mutex); _full_cond.wait(lock, _not_full_fcn); _buffer.push_front(elem); @@ -63,6 +73,7 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/ } UHD_INLINE bool push_with_timed_wait(const elem_type &elem, double timeout){ + if (this->push_with_haste(elem)) return true; boost::mutex::scoped_lock lock(_mutex); if (not _full_cond.timed_wait( lock, to_time_dur(timeout), _not_full_fcn @@ -75,7 +86,7 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/ UHD_INLINE bool pop_with_haste(elem_type &elem){ boost::mutex::scoped_lock lock(_mutex); - if(_buffer.empty()) return false; + if (_buffer.empty()) return false; elem = this->pop_back(); lock.unlock(); _full_cond.notify_one(); @@ -83,6 +94,7 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/ } UHD_INLINE void pop_with_wait(elem_type &elem){ + if (this->pop_with_haste(elem)) return; boost::mutex::scoped_lock lock(_mutex); _empty_cond.wait(lock, _not_empty_fcn); elem = this->pop_back(); @@ -91,6 +103,7 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/ } UHD_INLINE bool pop_with_timed_wait(elem_type &elem, double timeout){ + if (this->pop_with_haste(elem)) return true; boost::mutex::scoped_lock lock(_mutex); if (not _empty_cond.timed_wait( lock, to_time_dur(timeout), _not_empty_fcn |