summaryrefslogtreecommitdiffstats
path: root/host/include
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-10-02 23:15:46 -0700
committerJosh Blum <josh@joshknows.com>2010-10-02 23:15:46 -0700
commit7352c95037fa57d37dd7adc4c2ea6935006b56c8 (patch)
treeaf0e2a3cbb42db9296ddbfe18e4d5eb7efc27de6 /host/include
parent00cd6018405b57a0982b0ce103ff858c646ee18c (diff)
downloaduhd-7352c95037fa57d37dd7adc4c2ea6935006b56c8.tar.gz
uhd-7352c95037fa57d37dd7adc4c2ea6935006b56c8.tar.bz2
uhd-7352c95037fa57d37dd7adc4c2ea6935006b56c8.zip
uhd: reworked the zero copy interface
- recv buffers have a release call - safe make function for recv buffers (buff + release callback) - send buffer commits now have a void return - safe make function for send buffers (buff + commit callback) The reason for the void return from commit is that ssize_t num_bytes was never returning anything of use. That is for all of the zero copy implementations so far, commit cannot really error (being asynchronous). libusb zero copy impl was reworked to support the new interface. USRP1 io_impl with the psuedo managed buffer was replaced with safe_make. Also, usrp1 io_impl was simplified greatly due to commit returning void now. UDP zero copy asio was disabled (in this commit, until its reworked). Phony send and recv interfaces were removed completely.
Diffstat (limited to 'host/include')
-rw-r--r--host/include/uhd/transport/zero_copy.hpp112
1 files changed, 34 insertions, 78 deletions
diff --git a/host/include/uhd/transport/zero_copy.hpp b/host/include/uhd/transport/zero_copy.hpp
index ba19b193c..9dd16280c 100644
--- a/host/include/uhd/transport/zero_copy.hpp
+++ b/host/include/uhd/transport/zero_copy.hpp
@@ -19,10 +19,10 @@
#define INCLUDED_UHD_TRANSPORT_ZERO_COPY_HPP
#include <uhd/config.hpp>
-#include <uhd/utils/pimpl.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>
+#include <boost/function.hpp>
namespace uhd{ namespace transport{
@@ -34,14 +34,27 @@ namespace uhd{ namespace transport{
class UHD_API managed_recv_buffer : boost::noncopyable{
public:
typedef boost::shared_ptr<managed_recv_buffer> sptr;
+ typedef boost::function<void(void)> release_fcn_t;
+
+ /*!
+ * 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 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
+ );
/*!
- * Managed recv buffer destructor:
* Signal to the transport that we are done with the buffer.
- * This should be called to release the buffer to the transport.
+ * This should be called to release the buffer to the transport object.
* After calling, the referenced memory should be considered invalid.
*/
- virtual ~managed_recv_buffer(void) = 0;
+ virtual void release(void) = 0;
/*!
* Get the size of the underlying buffer.
@@ -71,20 +84,34 @@ namespace uhd{ namespace transport{
/*!
* A managed send buffer:
* Contains a reference to transport-managed memory,
- * and a method to release the memory after writing.
+ * and a method to commit the memory after writing.
*/
class UHD_API managed_send_buffer : boost::noncopyable{
public:
typedef boost::shared_ptr<managed_send_buffer> sptr;
+ typedef boost::function<void(size_t)> commit_fcn_t;
+
+ /*!
+ * Make a safe managed send buffer:
+ * 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 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
+ );
/*!
* Signal to the transport that we are done with the buffer.
* This should be called to commit the write to the transport object.
* After calling, the referenced memory should be considered invalid.
* \param num_bytes the number of bytes written into the buffer
- * \return the number of bytes written, 0 for timeout, negative for error
*/
- virtual ssize_t commit(size_t num_bytes) = 0;
+ virtual void commit(size_t num_bytes) = 0;
/*!
* Get the size of the underlying buffer.
@@ -154,77 +181,6 @@ namespace uhd{ namespace transport{
};
- /*!
- * A phony-zero-copy interface for transport objects that
- * provides a zero-copy interface on top of copying transport.
- * This interface implements the get managed recv buffer,
- * the base class must implement the private recv method.
- */
- class UHD_API phony_zero_copy_recv_if : public virtual zero_copy_if{
- public:
- /*!
- * Create a phony zero copy recv interface.
- * \param max_buff_size max buffer size in bytes
- */
- phony_zero_copy_recv_if(size_t max_buff_size);
-
- //! destructor
- virtual ~phony_zero_copy_recv_if(void);
-
- /*!
- * Get a new receive buffer from this transport object.
- * \param timeout the timeout to get the buffer in seconds
- * \return a managed buffer, or null sptr on timeout/error
- */
- managed_recv_buffer::sptr get_recv_buff(double timeout);
-
- private:
- /*!
- * Perform a private copying recv.
- * \param buff the buffer to write data into
- * \param timeout the timeout to get the buffer in seconds
- * \return the number of bytes written to buff, 0 for timeout, negative for error
- */
- virtual ssize_t recv(const boost::asio::mutable_buffer &buff, double timeout) = 0;
-
- UHD_PIMPL_DECL(impl) _impl;
- };
-
- /*!
- * A phony-zero-copy interface for transport objects that
- * provides a zero-copy interface on top of copying transport.
- * This interface implements the get managed send buffer,
- * the base class must implement the private send method.
- */
- class UHD_API phony_zero_copy_send_if : public virtual zero_copy_if{
- public:
- /*!
- * Create a phony zero copy send interface.
- * \param max_buff_size max buffer size in bytes
- */
- phony_zero_copy_send_if(size_t max_buff_size);
-
- //! destructor
- virtual ~phony_zero_copy_send_if(void);
-
- /*!
- * Get a new send buffer from this transport object.
- * \param timeout the timeout to get the buffer in seconds
- * \return a managed buffer, or null sptr on timeout/error
- */
- managed_send_buffer::sptr get_send_buff(double timeout);
-
- private:
- /*!
- * Perform a private copying send.
- * \param buff the buffer to read data from
- * \return the number of bytes read from buff, 0 for timeout, negative for error
- */
- virtual ssize_t send(const boost::asio::const_buffer &buff) = 0;
-
- UHD_PIMPL_DECL(impl) _impl;
- };
-
}} //namespace
#endif /* INCLUDED_UHD_TRANSPORT_ZERO_COPY_HPP */