diff options
author | Josh Blum <josh@joshknows.com> | 2011-05-14 17:11:05 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2011-05-14 20:28:20 -0700 |
commit | ea5ce50a465e714c63196f52df97fb3e927e701c (patch) | |
tree | d69b081995d483ebb43d0971e48e401cd35c1a53 /host/include | |
parent | 4b772ff4f3b1e388e150402beaf6567f3ea29e1c (diff) | |
download | uhd-ea5ce50a465e714c63196f52df97fb3e927e701c.tar.gz uhd-ea5ce50a465e714c63196f52df97fb3e927e701c.tar.bz2 uhd-ea5ce50a465e714c63196f52df97fb3e927e701c.zip |
uhd: replace managed buffer shared pointer w/ intrusive pointer to reduce overhead
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 |