aboutsummaryrefslogtreecommitdiffstats
path: root/host/include/uhd/transport/bounded_buffer.ipp
diff options
context:
space:
mode:
Diffstat (limited to 'host/include/uhd/transport/bounded_buffer.ipp')
-rw-r--r--host/include/uhd/transport/bounded_buffer.ipp31
1 files changed, 25 insertions, 6 deletions
diff --git a/host/include/uhd/transport/bounded_buffer.ipp b/host/include/uhd/transport/bounded_buffer.ipp
index e106e229e..58f78bab4 100644
--- a/host/include/uhd/transport/bounded_buffer.ipp
+++ b/host/include/uhd/transport/bounded_buffer.ipp
@@ -21,6 +21,7 @@
#include <boost/bind.hpp>
#include <boost/circular_buffer.hpp>
#include <boost/thread/condition.hpp>
+#include <boost/date_time/posix_time/posix_time_types.hpp>
namespace uhd{ namespace transport{ namespace{ /*anon*/
@@ -57,9 +58,12 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/
_empty_cond.notify_one();
}
- bool push_with_timed_wait(const elem_type &elem, const time_duration_t &time){
+ bool push_with_timed_wait(const elem_type &elem, double timeout){
boost::unique_lock<boost::mutex> lock(_mutex);
- if (not _full_cond.timed_wait(lock, time, boost::bind(&bounded_buffer_impl<elem_type>::not_full, this))) return false;
+ if (not _full_cond.timed_wait(
+ lock, boost::posix_time::microseconds(long(timeout*1e6)),
+ boost::bind(&bounded_buffer_impl<elem_type>::not_full, this)
+ )) return false;
_buffer.push_front(elem);
lock.unlock();
_empty_cond.notify_one();
@@ -69,15 +73,18 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/
UHD_INLINE void pop_with_wait(elem_type &elem){
boost::unique_lock<boost::mutex> lock(_mutex);
_empty_cond.wait(lock, boost::bind(&bounded_buffer_impl<elem_type>::not_empty, this));
- elem = _buffer.back(); _buffer.pop_back();
+ this->pop_back(elem);
lock.unlock();
_full_cond.notify_one();
}
- bool pop_with_timed_wait(elem_type &elem, const time_duration_t &time){
+ bool pop_with_timed_wait(elem_type &elem, double timeout){
boost::unique_lock<boost::mutex> lock(_mutex);
- if (not _empty_cond.timed_wait(lock, time, boost::bind(&bounded_buffer_impl<elem_type>::not_empty, this))) return false;
- elem = _buffer.back(); _buffer.pop_back();
+ if (not _empty_cond.timed_wait(
+ lock, boost::posix_time::microseconds(long(timeout*1e6)),
+ boost::bind(&bounded_buffer_impl<elem_type>::not_empty, this)
+ )) return false;
+ this->pop_back(elem);
lock.unlock();
_full_cond.notify_one();
return true;
@@ -97,6 +104,18 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/
bool not_full(void) const{return not _buffer.full();}
bool not_empty(void) const{return not _buffer.empty();}
+
+ /*!
+ * Three part operation to pop an element:
+ * 1) assign elem to the back element
+ * 2) assign the back element to empty
+ * 3) pop the back to move the counter
+ */
+ UHD_INLINE void pop_back(elem_type &elem){
+ elem = _buffer.back();
+ _buffer.back() = elem_type();
+ _buffer.pop_back();
+ }
};
}}} //namespace