diff options
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/transport/zero_copy.hpp | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/host/include/uhd/transport/zero_copy.hpp b/host/include/uhd/transport/zero_copy.hpp index 092028d09..f80c738aa 100644 --- a/host/include/uhd/transport/zero_copy.hpp +++ b/host/include/uhd/transport/zero_copy.hpp @@ -21,9 +21,16 @@ #include <uhd/config.hpp> #include <boost/utility.hpp> #include <boost/shared_ptr.hpp> +#include <boost/intrusive_ptr.hpp> namespace uhd{ namespace transport{ + //! Create smart pointer to a reusable managed buffer + template <typename T> UHD_INLINE boost::intrusive_ptr<T> make_managed_buffer(T *p){ + p->_ref_count = 1; //reset the count to 1 reference + return boost::intrusive_ptr<T>(p, false); + } + /*! * A managed receive buffer: * Contains a reference to transport-managed memory, @@ -31,7 +38,7 @@ namespace uhd{ namespace transport{ */ class UHD_API managed_recv_buffer{ public: - typedef boost::shared_ptr<managed_recv_buffer> sptr; + typedef boost::intrusive_ptr<managed_recv_buffer> sptr; /*! * Signal to the transport that we are done with the buffer. @@ -59,8 +66,18 @@ namespace uhd{ namespace transport{ private: virtual const void *get_buff(void) const = 0; virtual size_t get_size(void) const = 0; + + public: int _ref_count; }; + UHD_INLINE void intrusive_ptr_add_ref(managed_recv_buffer *p){ + ++(p->_ref_count); + } + + UHD_INLINE void intrusive_ptr_release(managed_recv_buffer *p){ + if (--(p->_ref_count) == 0) p->release(); + } + /*! * A managed send buffer: * Contains a reference to transport-managed memory, @@ -68,7 +85,7 @@ namespace uhd{ namespace transport{ */ class UHD_API managed_send_buffer{ public: - typedef boost::shared_ptr<managed_send_buffer> sptr; + typedef boost::intrusive_ptr<managed_send_buffer> sptr; /*! * Signal to the transport that we are done with the buffer. @@ -97,8 +114,18 @@ namespace uhd{ namespace transport{ private: virtual void *get_buff(void) const = 0; virtual size_t get_size(void) const = 0; + + public: int _ref_count; }; + UHD_INLINE void intrusive_ptr_add_ref(managed_send_buffer *p){ + ++(p->_ref_count); + } + + UHD_INLINE void intrusive_ptr_release(managed_send_buffer *p){ + if (--(p->_ref_count) == 0) p->commit(0); + } + /*! * A zero-copy interface for transport objects. * Provides a way to get send and receive buffers |