diff options
author | Josh Blum <josh@joshknows.com> | 2011-02-07 12:32:12 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2011-02-07 12:32:12 -0800 |
commit | ef351624eeb898e17662000a40b50076133118c7 (patch) | |
tree | 841cc50addc98183bf4b6a35dbe2b5375d08cc6c /host | |
parent | fec5fc2d319ab2808f88d2f4cec734a8102f18ca (diff) | |
download | uhd-ef351624eeb898e17662000a40b50076133118c7.tar.gz uhd-ef351624eeb898e17662000a40b50076133118c7.tar.bz2 uhd-ef351624eeb898e17662000a40b50076133118c7.zip |
uhd: replace asio buffer in make safe w/ memory and length, makes things simpler
Diffstat (limited to 'host')
-rw-r--r-- | host/include/uhd/transport/zero_copy.hpp | 63 | ||||
-rw-r--r-- | host/lib/transport/libusb1_zero_copy.cpp | 4 | ||||
-rw-r--r-- | host/lib/transport/udp_zero_copy_asio.cpp | 15 | ||||
-rw-r--r-- | host/lib/transport/zero_copy.cpp | 40 | ||||
-rw-r--r-- | host/lib/usrp/usrp1/io_impl.cpp | 6 | ||||
-rw-r--r-- | host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp | 4 |
6 files changed, 64 insertions, 68 deletions
diff --git a/host/include/uhd/transport/zero_copy.hpp b/host/include/uhd/transport/zero_copy.hpp index 7d8fb4b83..d5a536b27 100644 --- a/host/include/uhd/transport/zero_copy.hpp +++ b/host/include/uhd/transport/zero_copy.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -19,7 +19,6 @@ #define INCLUDED_UHD_TRANSPORT_ZERO_COPY_HPP #include <uhd/config.hpp> -#include <boost/asio/buffer.hpp> #include <boost/utility.hpp> #include <boost/shared_ptr.hpp> #include <boost/function.hpp> @@ -40,13 +39,13 @@ namespace uhd{ namespace transport{ * Make a safe managed receive buffer: * A safe managed buffer ensures that release is called once, * either by the user or automatically upon deconstruction. - * \param buff a reference to the constant buffer + * \param buff a pointer into read-only memory + * \param size the length of the buffer in bytes * \param release_fcn callback to release the memory * \return a new managed receive buffer */ static sptr make_safe( - const boost::asio::const_buffer &buff, - const release_fcn_t &release_fcn + const void *buff, size_t size, const release_fcn_t &release_fcn ); /*! @@ -57,28 +56,24 @@ namespace uhd{ namespace transport{ virtual void release(void) = 0; /*! - * Get the size of the underlying buffer. - * \return the number of bytes - */ - inline size_t size(void) const{ - return boost::asio::buffer_size(this->get()); - } - - /*! * Get a pointer to the underlying buffer. * \return a pointer into memory */ template <class T> inline T cast(void) const{ - return boost::asio::buffer_cast<T>(this->get()); + return static_cast<T>(this->get_buff()); } - private: /*! - * Get a reference to the internal const buffer. - * The buffer has a reference to memory and a size. - * \return a boost asio const buffer + * Get the size of the underlying buffer. + * \return the number of bytes */ - virtual const boost::asio::const_buffer &get(void) const = 0; + inline size_t size(void) const{ + return this->get_size(); + } + + private: + virtual const void *get_buff(void) const = 0; + virtual size_t get_size(void) const = 0; }; /*! @@ -96,13 +91,13 @@ namespace uhd{ namespace transport{ * A safe managed buffer ensures that commit is called once, * either by the user or automatically upon deconstruction. * In the later case, the deconstructor will call commit(0). - * \param buff a reference to the mutable buffer + * \param buff a pointer into writable memory + * \param size the length of the buffer in bytes * \param commit_fcn callback to commit the memory * \return a new managed send buffer */ static sptr make_safe( - const boost::asio::mutable_buffer &buff, - const commit_fcn_t &commit_fcn + void *buff, size_t size, const commit_fcn_t &commit_fcn ); /*! @@ -114,28 +109,24 @@ namespace uhd{ namespace transport{ virtual void commit(size_t num_bytes) = 0; /*! - * Get the size of the underlying buffer. - * \return the number of bytes - */ - inline size_t size(void) const{ - return boost::asio::buffer_size(this->get()); - } - - /*! * Get a pointer to the underlying buffer. * \return a pointer into memory */ template <class T> inline T cast(void) const{ - return boost::asio::buffer_cast<T>(this->get()); + return static_cast<T>(this->get_buff()); } - private: /*! - * Get a reference to the internal mutable buffer. - * The buffer has a reference to memory and a size. - * \return a boost asio mutable buffer + * Get the size of the underlying buffer. + * \return the number of bytes */ - virtual const boost::asio::mutable_buffer &get(void) const = 0; + inline size_t size(void) const{ + return this->get_size(); + } + + private: + virtual void *get_buff(void) const = 0; + virtual size_t get_size(void) const = 0; }; /*! diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp index 5ae6db39e..ca37f351f 100644 --- a/host/lib/transport/libusb1_zero_copy.cpp +++ b/host/lib/transport/libusb1_zero_copy.cpp @@ -398,7 +398,7 @@ managed_recv_buffer::sptr libusb_zero_copy_impl::get_recv_buff(double timeout){ } else { return managed_recv_buffer::make_safe( - boost::asio::const_buffer(lut->buffer, lut->actual_length), + lut->buffer, lut->actual_length, boost::bind(&libusb_zero_copy_impl::release, this, lut) ); } @@ -418,7 +418,7 @@ managed_send_buffer::sptr libusb_zero_copy_impl::get_send_buff(double timeout){ } else { return managed_send_buffer::make_safe( - boost::asio::mutable_buffer(lut->buffer, this->get_send_frame_size()), + lut->buffer, this->get_send_frame_size(), boost::bind(&libusb_zero_copy_impl::commit, this, lut, _1) ); } diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp index 0f16e7d14..90cd2a9ce 100644 --- a/host/lib/transport/udp_zero_copy_asio.cpp +++ b/host/lib/transport/udp_zero_copy_asio.cpp @@ -149,7 +149,8 @@ public: asio::mutable_buffer buff; if (_pending_recv_buffs.pop_with_timed_wait(buff, timeout)){ return managed_recv_buffer::make_safe( - buff, boost::bind( + asio::buffer_cast<const void *>(buff), + asio::buffer_size(buff), boost::bind( &udp_zero_copy_asio_impl::release, this, asio::buffer_cast<void*>(buff) ) @@ -193,10 +194,8 @@ public: and _pending_recv_buffs.pop_with_haste(buff) ){ return managed_recv_buffer::make_safe( - asio::buffer( - boost::asio::buffer_cast<void *>(buff), - _socket->receive(asio::buffer(buff)) - ), + boost::asio::buffer_cast<void *>(buff), + _socket->receive(asio::buffer(buff)), boost::bind( &udp_zero_copy_asio_impl::release, this, asio::buffer_cast<void*>(buff) @@ -231,7 +230,8 @@ public: asio::mutable_buffer buff; if (_pending_send_buffs.pop_with_timed_wait(buff, timeout)){ return managed_send_buffer::make_safe( - buff, boost::bind( + asio::buffer_cast<void *>(buff), + asio::buffer_size(buff), boost::bind( &udp_zero_copy_asio_impl::commit, this, asio::buffer_cast<void*>(buff), _1 ) @@ -258,7 +258,8 @@ public: asio::mutable_buffer buff; if (_pending_send_buffs.pop_with_haste(buff)){ return managed_send_buffer::make_safe( - buff, boost::bind( + asio::buffer_cast<void *>(buff), + asio::buffer_size(buff), boost::bind( &udp_zero_copy_asio_impl::commit, this, asio::buffer_cast<void*>(buff), _1 ) diff --git a/host/lib/transport/zero_copy.cpp b/host/lib/transport/zero_copy.cpp index a5a864a04..b91eaae1d 100644 --- a/host/lib/transport/zero_copy.cpp +++ b/host/lib/transport/zero_copy.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -29,10 +29,9 @@ static void release_nop(void){ class safe_managed_receive_buffer : public managed_recv_buffer{ public: safe_managed_receive_buffer( - const boost::asio::const_buffer &buff, - const release_fcn_t &release_fcn + const void *buff, size_t size, const release_fcn_t &release_fcn ): - _buff(buff), _release_fcn(release_fcn) + _buff(buff), _size(size), _release_fcn(release_fcn) { /* NOP */ } @@ -48,19 +47,23 @@ public: } private: - const boost::asio::const_buffer &get(void) const{ + const void *get_buff(void) const{ return _buff; } - const boost::asio::const_buffer _buff; + size_t get_size(void) const{ + return _size; + } + + const void *_buff; + size_t _size; release_fcn_t _release_fcn; }; managed_recv_buffer::sptr managed_recv_buffer::make_safe( - const boost::asio::const_buffer &buff, - const release_fcn_t &release_fcn + const void *buff, size_t size, const release_fcn_t &release_fcn ){ - return sptr(new safe_managed_receive_buffer(buff, release_fcn)); + return sptr(new safe_managed_receive_buffer(buff, size, release_fcn)); } /*********************************************************************** @@ -73,10 +76,9 @@ static void commit_nop(size_t){ class safe_managed_send_buffer : public managed_send_buffer{ public: safe_managed_send_buffer( - const boost::asio::mutable_buffer &buff, - const commit_fcn_t &commit_fcn + void *buff, size_t size, const commit_fcn_t &commit_fcn ): - _buff(buff), _commit_fcn(commit_fcn) + _buff(buff), _size(size), _commit_fcn(commit_fcn) { /* NOP */ } @@ -92,17 +94,21 @@ public: } private: - const boost::asio::mutable_buffer &get(void) const{ + void *get_buff(void) const{ return _buff; } - const boost::asio::mutable_buffer _buff; + size_t get_size(void) const{ + return _size; + } + + void *_buff; + size_t _size; commit_fcn_t _commit_fcn; }; safe_managed_send_buffer::sptr managed_send_buffer::make_safe( - const boost::asio::mutable_buffer &buff, - const commit_fcn_t &commit_fcn + void *buff, size_t size, const commit_fcn_t &commit_fcn ){ - return sptr(new safe_managed_send_buffer(buff, commit_fcn)); + return sptr(new safe_managed_send_buffer(buff, size, commit_fcn)); } diff --git a/host/lib/usrp/usrp1/io_impl.cpp b/host/lib/usrp/usrp1/io_impl.cpp index 52a7c6650..7953447d1 100644 --- a/host/lib/usrp/usrp1/io_impl.cpp +++ b/host/lib/usrp/usrp1/io_impl.cpp @@ -159,10 +159,8 @@ bool usrp1_impl::io_impl::get_send_buffs( //calculate the buffer pointer and size given the offset //references to the buffers are held in the bound function buffs[0] = managed_send_buffer::make_safe( - boost::asio::buffer( - curr_buff->buff->cast<char *>() + curr_buff->offset, - curr_buff->buff->size() - curr_buff->offset - ), + curr_buff->buff->cast<char *>() + curr_buff->offset, + curr_buff->buff->size() - curr_buff->offset, boost::bind(&usrp1_impl::io_impl::commit_send_buff, this, curr_buff, next_buff, _1) ); diff --git a/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp b/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp index c07e6e011..4e0137fdb 100644 --- a/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp +++ b/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp @@ -124,7 +124,7 @@ public: //return the managed buffer for this frame if (fp_verbose) std::cout << " make_recv_buff: " << info->len << std::endl; return managed_recv_buffer::make_safe( - boost::asio::const_buffer(mem, info->len), + mem, info->len, boost::bind(&usrp_e100_mmap_zero_copy_impl::release, this, info) ); } @@ -160,7 +160,7 @@ public: //return the managed buffer for this frame if (fp_verbose) std::cout << " make_send_buff: " << _frame_size << std::endl; return managed_send_buffer::make_safe( - boost::asio::mutable_buffer(mem, _frame_size), + mem, _frame_size, boost::bind(&usrp_e100_mmap_zero_copy_impl::commit, this, info, _1) ); } |