Loading...
Searching...
No Matches
zero_copy.hpp
Go to the documentation of this file.
//
// Copyright 2010-2012,2015 Ettus Research LLC
// Copyright 2018 Ettus Research, a National Instruments Company
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
#pragma once
#include <uhd/config.hpp>
#include <uhd/utils/noncopyable.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/smart_ptr/detail/atomic_count.hpp>
#include <boost/utility.hpp>
#include <memory>
namespace uhd { namespace transport {
class UHD_API managed_buffer
{
public:
managed_buffer(void) : _ref_count(0), _buffer(NULL), _length(0) {}
virtual ~managed_buffer(void) {}
virtual void release(void) = 0;
UHD_INLINE void commit(size_t num_bytes)
{
_length = num_bytes;
}
template <class T>
UHD_INLINE T cast(void) const
{
return static_cast<T>(_buffer);
}
UHD_INLINE size_t size(void) const
{
return _length;
}
template <typename T>
UHD_INLINE boost::intrusive_ptr<T> make(T* p, void* buffer, size_t length)
{
_buffer = buffer;
_length = length;
return boost::intrusive_ptr<T>(p);
}
boost::detail::atomic_count _ref_count;
typedef boost::intrusive_ptr<managed_buffer> sptr;
int ref_count()
{
return (int)_ref_count;
}
protected:
void* _buffer;
size_t _length;
private:
};
UHD_INLINE void intrusive_ptr_add_ref(managed_buffer* p)
{
++(p->_ref_count);
}
UHD_INLINE void intrusive_ptr_release(managed_buffer* p)
{
if (--(p->_ref_count) == 0)
p->release();
}
class UHD_API managed_recv_buffer : public managed_buffer
{
public:
typedef boost::intrusive_ptr<managed_recv_buffer> sptr;
};
class UHD_API managed_send_buffer : public managed_buffer
{
public:
typedef boost::intrusive_ptr<managed_send_buffer> sptr;
};
struct zero_copy_xport_params
{
zero_copy_xport_params()
: recv_frame_size(0)
, send_frame_size(0)
, num_recv_frames(0)
, num_send_frames(0)
, recv_buff_size(0)
, send_buff_size(0)
{ /* NOP */
}
size_t recv_frame_size;
size_t send_frame_size;
size_t num_recv_frames;
size_t num_send_frames;
size_t recv_buff_size;
size_t send_buff_size;
};
class UHD_API zero_copy_if : uhd::noncopyable
{
public:
typedef std::shared_ptr<zero_copy_if> sptr;
virtual ~zero_copy_if(){};
virtual managed_recv_buffer::sptr get_recv_buff(double timeout = 0.1) = 0;
virtual size_t get_num_recv_frames(void) const = 0;
virtual size_t get_recv_frame_size(void) const = 0;
virtual managed_send_buffer::sptr get_send_buff(double timeout = 0.1) = 0;
virtual size_t get_num_send_frames(void) const = 0;
virtual size_t get_send_frame_size(void) const = 0;
};
}} // namespace uhd::transport
uhd::transport::managed_buffer
Simple managed buffer with release interface.
Definition zero_copy.hpp:21
uhd::transport::managed_buffer::ref_count
int ref_count()
Definition zero_copy.hpp:74
uhd::transport::managed_buffer::commit
UHD_INLINE void commit(size_t num_bytes)
Definition zero_copy.hpp:38
uhd::transport::managed_buffer::_ref_count
boost::detail::atomic_count _ref_count
Definition zero_copy.hpp:71
uhd::transport::managed_buffer::managed_buffer
managed_buffer(void)
Definition zero_copy.hpp:23
uhd::transport::managed_buffer::_length
size_t _length
Definition zero_copy.hpp:81
uhd::transport::managed_buffer::~managed_buffer
virtual ~managed_buffer(void)
Definition zero_copy.hpp:25
uhd::transport::managed_buffer::size
UHD_INLINE size_t size(void) const
Definition zero_copy.hpp:57
uhd::transport::managed_buffer::make
UHD_INLINE boost::intrusive_ptr< T > make(T *p, void *buffer, size_t length)
Create smart pointer to a reusable managed buffer.
Definition zero_copy.hpp:64
uhd::transport::managed_buffer::sptr
boost::intrusive_ptr< managed_buffer > sptr
Definition zero_copy.hpp:72
uhd::transport::managed_buffer::_buffer
void * _buffer
Definition zero_copy.hpp:80
uhd::transport::managed_buffer::cast
UHD_INLINE T cast(void) const
Definition zero_copy.hpp:48
uhd::transport::managed_buffer::release
virtual void release(void)=0
uhd::transport::managed_recv_buffer
Definition zero_copy.hpp:103
uhd::transport::managed_recv_buffer::sptr
boost::intrusive_ptr< managed_recv_buffer > sptr
Definition zero_copy.hpp:105
uhd::transport::managed_send_buffer
Definition zero_copy.hpp:114
uhd::transport::managed_send_buffer::sptr
boost::intrusive_ptr< managed_send_buffer > sptr
Definition zero_copy.hpp:116
uhd::transport::zero_copy_if
Definition zero_copy.hpp:147
uhd::transport::zero_copy_if::get_send_buff
virtual managed_send_buffer::sptr get_send_buff(double timeout=0.1)=0
uhd::transport::zero_copy_if::get_num_send_frames
virtual size_t get_num_send_frames(void) const =0
uhd::transport::zero_copy_if::get_recv_buff
virtual managed_recv_buffer::sptr get_recv_buff(double timeout=0.1)=0
uhd::transport::zero_copy_if::sptr
std::shared_ptr< zero_copy_if > sptr
Definition zero_copy.hpp:149
uhd::transport::zero_copy_if::get_recv_frame_size
virtual size_t get_recv_frame_size(void) const =0
uhd::transport::zero_copy_if::get_send_frame_size
virtual size_t get_send_frame_size(void) const =0
uhd::transport::zero_copy_if::~zero_copy_if
virtual ~zero_copy_if()
Definition zero_copy.hpp:154
uhd::transport::zero_copy_if::get_num_recv_frames
virtual size_t get_num_recv_frames(void) const =0
UHD_INLINE
#define UHD_INLINE
Definition config.h:65
UHD_API
#define UHD_API
Definition config.h:87
config.hpp
uhd::transport
Definition adapter_id.hpp:11
uhd::transport::intrusive_ptr_add_ref
UHD_INLINE void intrusive_ptr_add_ref(managed_buffer *p)
Definition zero_copy.hpp:86
uhd::transport::intrusive_ptr_release
UHD_INLINE void intrusive_ptr_release(managed_buffer *p)
Definition zero_copy.hpp:91
uhd
Definition build_info.hpp:12
uhd::noncopyable
boost::noncopyable noncopyable
Definition noncopyable.hpp:45
noncopyable.hpp
uhd::transport::zero_copy_xport_params::num_recv_frames
size_t num_recv_frames
Definition zero_copy.hpp:135
uhd::transport::zero_copy_xport_params::recv_frame_size
size_t recv_frame_size
Definition zero_copy.hpp:133
uhd::transport::zero_copy_xport_params::send_buff_size
size_t send_buff_size
Definition zero_copy.hpp:138
uhd::transport::zero_copy_xport_params::send_frame_size
size_t send_frame_size
Definition zero_copy.hpp:134
uhd::transport::zero_copy_xport_params::recv_buff_size
size_t recv_buff_size
Definition zero_copy.hpp:137
uhd::transport::zero_copy_xport_params::zero_copy_xport_params
zero_copy_xport_params()
Definition zero_copy.hpp:124
uhd::transport::zero_copy_xport_params::num_send_frames
size_t num_send_frames
Definition zero_copy.hpp:136