USRP Hardware Driver and USRP Manual Version: 4.1.0.3
UHD and USRP Manual
zero_copy.hpp
Go to the documentation of this file.
1//
2// Copyright 2010-2012,2015 Ettus Research LLC
3// Copyright 2018 Ettus Research, a National Instruments Company
4//
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
7
8#pragma once
9
10#include <uhd/config.hpp>
12#include <boost/detail/atomic_count.hpp>
13#include <boost/intrusive_ptr.hpp>
14#include <boost/utility.hpp>
15#include <memory>
16
17namespace uhd { namespace transport {
18
21{
22public:
23 managed_buffer(void) : _ref_count(0), _buffer(NULL), _length(0) {}
24
25 virtual ~managed_buffer(void) {}
26
32 virtual void release(void) = 0;
33
38 UHD_INLINE void commit(size_t num_bytes)
39 {
40 _length = num_bytes;
41 }
42
47 template <class T>
48 UHD_INLINE T cast(void) const
49 {
50 return static_cast<T>(_buffer);
51 }
52
57 UHD_INLINE size_t size(void) const
58 {
59 return _length;
60 }
61
63 template <typename T>
64 UHD_INLINE boost::intrusive_ptr<T> make(T* p, void* buffer, size_t length)
65 {
66 _buffer = buffer;
67 _length = length;
68 return boost::intrusive_ptr<T>(p);
69 }
70
71 boost::detail::atomic_count _ref_count;
72 typedef boost::intrusive_ptr<managed_buffer> sptr;
73
75 {
76 return (int)_ref_count;
77 }
78
79protected:
80 void* _buffer;
81 size_t _length;
82
83private:
84};
85
87{
88 ++(p->_ref_count);
89}
90
92{
93 if (--(p->_ref_count) == 0)
94 p->release();
95}
96
103{
104public:
105 typedef boost::intrusive_ptr<managed_recv_buffer> sptr;
106};
107
114{
115public:
116 typedef boost::intrusive_ptr<managed_send_buffer> sptr;
117};
118
123{
125 : recv_frame_size(0)
126 , send_frame_size(0)
127 , num_recv_frames(0)
128 , num_send_frames(0)
129 , recv_buff_size(0)
130 , send_buff_size(0)
131 { /* NOP */
132 }
139};
140
147{
148public:
149 typedef std::shared_ptr<zero_copy_if> sptr;
150
154 virtual ~zero_copy_if(){};
155
161 virtual managed_recv_buffer::sptr get_recv_buff(double timeout = 0.1) = 0;
162
168 virtual size_t get_num_recv_frames(void) const = 0;
169
175 virtual size_t get_recv_frame_size(void) const = 0;
176
182 virtual managed_send_buffer::sptr get_send_buff(double timeout = 0.1) = 0;
183
189 virtual size_t get_num_send_frames(void) const = 0;
190
196 virtual size_t get_send_frame_size(void) const = 0;
197};
198
199}} // namespace uhd::transport
Simple managed buffer with release interface.
Definition: zero_copy.hpp:21
int ref_count()
Definition: zero_copy.hpp:74
UHD_INLINE void commit(size_t num_bytes)
Definition: zero_copy.hpp:38
boost::detail::atomic_count _ref_count
Definition: zero_copy.hpp:71
managed_buffer(void)
Definition: zero_copy.hpp:23
size_t _length
Definition: zero_copy.hpp:81
virtual ~managed_buffer(void)
Definition: zero_copy.hpp:25
UHD_INLINE size_t size(void) const
Definition: zero_copy.hpp:57
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
boost::intrusive_ptr< managed_buffer > sptr
Definition: zero_copy.hpp:72
void * _buffer
Definition: zero_copy.hpp:80
UHD_INLINE T cast(void) const
Definition: zero_copy.hpp:48
virtual void release(void)=0
Definition: zero_copy.hpp:103
boost::intrusive_ptr< managed_recv_buffer > sptr
Definition: zero_copy.hpp:105
Definition: zero_copy.hpp:114
boost::intrusive_ptr< managed_send_buffer > sptr
Definition: zero_copy.hpp:116
Definition: zero_copy.hpp:147
virtual managed_send_buffer::sptr get_send_buff(double timeout=0.1)=0
virtual size_t get_num_send_frames(void) const =0
virtual managed_recv_buffer::sptr get_recv_buff(double timeout=0.1)=0
std::shared_ptr< zero_copy_if > sptr
Definition: zero_copy.hpp:149
virtual size_t get_recv_frame_size(void) const =0
virtual size_t get_send_frame_size(void) const =0
virtual ~zero_copy_if()
Definition: zero_copy.hpp:154
virtual size_t get_num_recv_frames(void) const =0
#define UHD_INLINE
Definition: config.h:55
#define UHD_API
Definition: config.h:70
UHD_INLINE void intrusive_ptr_add_ref(managed_buffer *p)
Definition: zero_copy.hpp:86
UHD_INLINE void intrusive_ptr_release(managed_buffer *p)
Definition: zero_copy.hpp:91
Definition: build_info.hpp:12
boost::noncopyable noncopyable
Definition: noncopyable.hpp:45
Definition: zero_copy.hpp:123
size_t num_recv_frames
Definition: zero_copy.hpp:135
size_t recv_frame_size
Definition: zero_copy.hpp:133
size_t send_buff_size
Definition: zero_copy.hpp:138
size_t send_frame_size
Definition: zero_copy.hpp:134
size_t recv_buff_size
Definition: zero_copy.hpp:137
zero_copy_xport_params()
Definition: zero_copy.hpp:124
size_t num_send_frames
Definition: zero_copy.hpp:136