aboutsummaryrefslogtreecommitdiffstats
path: root/host/include
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-02-05 12:37:20 -0800
committerJosh Blum <josh@joshknows.com>2011-02-05 12:37:20 -0800
commit5d10aa397f044ea6781b4977c14171abfb4a727d (patch)
treec4578313720b2be2f4ce4d7c5e05c8e8a2a3b7e7 /host/include
parent3d32e7dc3b28cc384185c580035c0011a5beb167 (diff)
downloaduhd-5d10aa397f044ea6781b4977c14171abfb4a727d.tar.gz
uhd-5d10aa397f044ea6781b4977c14171abfb4a727d.tar.bz2
uhd-5d10aa397f044ea6781b4977c14171abfb4a727d.zip
uhd: change bounded_buffer implementation and code using it
The bounded buffer now uses the detail idiom to hide implementation to inline better. The whole sptr/make idiom was removed from bounded buffer to just construct directly. The code using bounded buffer was changed for the new api: replaces access operators and calls to the factory function.
Diffstat (limited to 'host/include')
-rw-r--r--host/include/uhd/transport/bounded_buffer.hpp43
-rw-r--r--host/include/uhd/transport/bounded_buffer.ipp30
2 files changed, 34 insertions, 39 deletions
diff --git a/host/include/uhd/transport/bounded_buffer.hpp b/host/include/uhd/transport/bounded_buffer.hpp
index 33ded8cfd..412d73f17 100644
--- a/host/include/uhd/transport/bounded_buffer.hpp
+++ b/host/include/uhd/transport/bounded_buffer.hpp
@@ -18,8 +18,7 @@
#ifndef INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_HPP
#define INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_HPP
-#include <uhd/config.hpp>
-#include <boost/shared_ptr.hpp>
+#include <uhd/transport/bounded_buffer.ipp> //detail
namespace uhd{ namespace transport{
@@ -32,13 +31,16 @@ namespace uhd{ namespace transport{
*/
template <typename elem_type> class bounded_buffer{
public:
- typedef boost::shared_ptr<bounded_buffer<elem_type> > sptr;
/*!
- * Make a new bounded buffer object.
+ * Create a new bounded buffer object.
* \param capacity the bounded_buffer capacity
*/
- static sptr make(size_t capacity);
+ bounded_buffer(size_t capacity):
+ _detail(capacity)
+ {
+ /* NOP */
+ }
/*!
* Push a new element into the bounded buffer.
@@ -47,14 +49,18 @@ namespace uhd{ namespace transport{
* \param elem the new element to push
* \return true if the element fit without popping for space
*/
- virtual bool push_with_pop_on_full(const elem_type &elem) = 0;
+ bool push_with_pop_on_full(const elem_type &elem){
+ return _detail.push_with_pop_on_full(elem);
+ }
/*!
* Push a new element into the bounded_buffer.
* Wait until the bounded_buffer becomes non-full.
* \param elem the new element to push
*/
- virtual void push_with_wait(const elem_type &elem) = 0;
+ void push_with_wait(const elem_type &elem){
+ return _detail.push_with_wait(elem);
+ }
/*!
* Push a new element into the bounded_buffer.
@@ -63,21 +69,27 @@ namespace uhd{ namespace transport{
* \param timeout the timeout in seconds
* \return false when the operation times out
*/
- virtual bool push_with_timed_wait(const elem_type &elem, double timeout) = 0;
+ bool push_with_timed_wait(const elem_type &elem, double timeout){
+ return _detail.push_with_timed_wait(elem, timeout);
+ }
/*!
* Pop an element from the bounded_buffer immediately.
* \param elem the element reference pop to
* \return false when the bounded_buffer is empty
*/
- virtual bool pop_with_haste(elem_type &elem) = 0;
+ bool pop_with_haste(elem_type &elem){
+ return _detail.pop_with_haste(elem);
+ }
/*!
* Pop an element from the bounded_buffer.
* Wait until the bounded_buffer becomes non-empty.
* \param elem the element reference pop to
*/
- virtual void pop_with_wait(elem_type &elem) = 0;
+ void pop_with_wait(elem_type &elem){
+ return _detail.pop_with_wait(elem);
+ }
/*!
* Pop an element from the bounded_buffer.
@@ -86,16 +98,13 @@ namespace uhd{ namespace transport{
* \param timeout the timeout in seconds
* \return false when the operation times out
*/
- virtual bool pop_with_timed_wait(elem_type &elem, double timeout) = 0;
+ bool pop_with_timed_wait(elem_type &elem, double timeout){
+ return _detail.pop_with_timed_wait(elem, timeout);
+ }
- /*!
- * Clear all elements from the bounded_buffer.
- */
- virtual void clear(void) = 0;
+ private: bounded_buffer_detail<elem_type> _detail;
};
}} //namespace
-#include <uhd/transport/bounded_buffer.ipp>
-
#endif /* INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_HPP */
diff --git a/host/include/uhd/transport/bounded_buffer.ipp b/host/include/uhd/transport/bounded_buffer.ipp
index 7bf182ee3..466c7a306 100644
--- a/host/include/uhd/transport/bounded_buffer.ipp
+++ b/host/include/uhd/transport/bounded_buffer.ipp
@@ -18,22 +18,24 @@
#ifndef INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_IPP
#define INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_IPP
+#include <uhd/config.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/circular_buffer.hpp>
#include <boost/thread/condition.hpp>
#include <boost/thread/locks.hpp>
-#include <boost/date_time/posix_time/posix_time_types.hpp>
namespace uhd{ namespace transport{ namespace{ /*anon*/
- template <typename elem_type>
- class bounded_buffer_impl : public bounded_buffer<elem_type>{
+ template <typename elem_type> class bounded_buffer_detail{
public:
- bounded_buffer_impl(size_t capacity) : _buffer(capacity){
- _not_full_fcn = boost::bind(&bounded_buffer_impl<elem_type>::not_full, this);
- _not_empty_fcn = boost::bind(&bounded_buffer_impl<elem_type>::not_empty, this);
+ bounded_buffer_detail(size_t capacity):
+ _buffer(capacity),
+ _not_full_fcn(boost::bind(&bounded_buffer_detail<elem_type>::not_full, this)),
+ _not_empty_fcn(boost::bind(&bounded_buffer_detail<elem_type>::not_empty, this))
+ {
+ /* NOP */
}
UHD_INLINE bool push_with_pop_on_full(const elem_type &elem){
@@ -100,13 +102,6 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/
return true;
}
- UHD_INLINE void clear(void){
- boost::mutex::scoped_lock lock(_mutex);
- while (not_empty()) this->pop_back();
- lock.unlock();
- _full_cond.notify_one();
- }
-
private:
boost::mutex _mutex;
boost::condition _empty_cond, _full_cond;
@@ -137,13 +132,4 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/
};
}}} //namespace
-namespace uhd{ namespace transport{
-
- template <typename elem_type> typename bounded_buffer<elem_type>::sptr
- bounded_buffer<elem_type>::make(size_t capacity){
- return typename bounded_buffer<elem_type>::sptr(new bounded_buffer_impl<elem_type>(capacity));
- }
-
-}} //namespace
-
#endif /* INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_IPP */