diff options
author | Josh Blum <josh@joshknows.com> | 2011-02-10 13:58:38 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2011-02-10 13:58:38 -0800 |
commit | 1be2590962669f307dce24ccb0b0011b3f3f25f5 (patch) | |
tree | bebf7fe400e2b794809a9c34a58105d1ed64b8d2 /host/include | |
parent | 1daf74483ed3e5e5a70f856aecefa96f30b2cbc2 (diff) | |
download | uhd-1be2590962669f307dce24ccb0b0011b3f3f25f5.tar.gz uhd-1be2590962669f307dce24ccb0b0011b3f3f25f5.tar.bz2 uhd-1be2590962669f307dce24ccb0b0011b3f3f25f5.zip |
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
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/transport/bounded_buffer.hpp | 15 | ||||
-rw-r--r-- | host/include/uhd/transport/bounded_buffer.ipp | 17 |
2 files changed, 28 insertions, 4 deletions
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 @@ -43,6 +43,16 @@ namespace uhd{ namespace transport{ } /*! + * 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, * make room by poping the oldest element. @@ -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<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 |