From 1be2590962669f307dce24ccb0b0011b3f3f25f5 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 10 Feb 2011 13:58:38 -0800 Subject: uhd: tweaks to bounded buffer Added push with haste. Call with haste first in the wait methods to avoid time compare/wait when not needed. Added new calls to the libusb and udp zero copy impls tests pass --- host/include/uhd/transport/bounded_buffer.hpp | 15 +++++++++++++-- host/include/uhd/transport/bounded_buffer.ipp | 17 +++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/transport/bounded_buffer.hpp b/host/include/uhd/transport/bounded_buffer.hpp index 412d73f17..6aa92c2e6 100644 --- a/host/include/uhd/transport/bounded_buffer.hpp +++ b/host/include/uhd/transport/bounded_buffer.hpp @@ -42,6 +42,16 @@ namespace uhd{ namespace transport{ /* NOP */ } + /*! + * Push a new element into the bounded buffer immediately. + * The element will not be pushed when the buffer is full. + * \param elem the element reference pop to + * \return false when the buffer is full + */ + bool push_with_haste(const elem_type &elem){ + return _detail.push_with_haste(elem); + } + /*! * Push a new element into the bounded buffer. * If the buffer is full prior to the push, @@ -74,9 +84,10 @@ namespace uhd{ namespace transport{ } /*! - * Pop an element from the bounded_buffer immediately. + * Pop an element from the bounded buffer immediately. + * The element will not be popped when the buffer is empty. * \param elem the element reference pop to - * \return false when the bounded_buffer is empty + * \return false when the buffer is empty */ bool pop_with_haste(elem_type &elem){ return _detail.pop_with_haste(elem); 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::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 -- cgit v1.2.3