UHD
003.004.002-0-unknown
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
include
uhd
transport
zero_copy.hpp
Go to the documentation of this file.
1
//
2
// Copyright 2010-2011 Ettus Research LLC
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
//
17
18
#ifndef INCLUDED_UHD_TRANSPORT_ZERO_COPY_HPP
19
#define INCLUDED_UHD_TRANSPORT_ZERO_COPY_HPP
20
21
#include <
uhd/config.hpp
>
22
#include <boost/utility.hpp>
23
#include <boost/shared_ptr.hpp>
24
#include <boost/intrusive_ptr.hpp>
25
26
namespace
uhd{
namespace
transport{
27
29
template
<
typename
T>
UHD_INLINE
boost::intrusive_ptr<T>
make_managed_buffer
(T *p){
30
p->_ref_count = 1;
//reset the count to 1 reference
31
return
boost::intrusive_ptr<T>(p,
false
);
32
}
33
39
class
UHD_API
managed_recv_buffer
{
40
public
:
41
typedef
boost::intrusive_ptr<managed_recv_buffer>
sptr
;
42
48
virtual
void
release(
void
) = 0;
49
54
template
<
class
T>
inline
T
cast
(
void
)
const
{
55
return
static_cast<
T
>
(this->get_buff());
56
}
57
62
inline
size_t
size
(
void
)
const
{
63
return
this->get_size();
64
}
65
66
private
:
67
virtual
const
void
*get_buff(
void
)
const
= 0;
68
virtual
size_t
get_size(
void
)
const
= 0;
69
70
public
:
int
_ref_count
;
71
};
72
73
UHD_INLINE
void
intrusive_ptr_add_ref
(
managed_recv_buffer
*p){
74
++(p->
_ref_count
);
75
}
76
77
UHD_INLINE
void
intrusive_ptr_release
(
managed_recv_buffer
*p){
78
if
(--(p->
_ref_count
) == 0) p->
release
();
79
}
80
86
class
UHD_API
managed_send_buffer
{
87
public
:
88
typedef
boost::intrusive_ptr<managed_send_buffer>
sptr
;
89
96
virtual
void
commit(
size_t
num_bytes) = 0;
97
102
template
<
class
T>
inline
T
cast
(
void
)
const
{
103
return
static_cast<
T
>
(this->get_buff());
104
}
105
110
inline
size_t
size
(
void
)
const
{
111
return
this->get_size();
112
}
113
114
private
:
115
virtual
void
*get_buff(
void
)
const
= 0;
116
virtual
size_t
get_size(
void
)
const
= 0;
117
118
public
:
int
_ref_count
;
119
};
120
121
UHD_INLINE
void
intrusive_ptr_add_ref
(
managed_send_buffer
*p){
122
++(p->
_ref_count
);
123
}
124
125
UHD_INLINE
void
intrusive_ptr_release
(
managed_send_buffer
*p){
126
if
(--(p->
_ref_count
) == 0) p->
commit
(0);
127
}
128
134
class
UHD_API
zero_copy_if
: boost::noncopyable{
135
public
:
136
typedef
boost::shared_ptr<zero_copy_if>
sptr
;
137
143
virtual
managed_recv_buffer::sptr
get_recv_buff(
double
timeout = 0.1) = 0;
144
150
virtual
size_t
get_num_recv_frames(
void
)
const
= 0;
151
157
virtual
size_t
get_recv_frame_size(
void
)
const
= 0;
158
164
virtual
managed_send_buffer::sptr
get_send_buff(
double
timeout = 0.1) = 0;
165
171
virtual
size_t
get_num_send_frames(
void
)
const
= 0;
172
178
virtual
size_t
get_send_frame_size(
void
)
const
= 0;
179
180
};
181
182
}}
//namespace
183
184
#endif
/* INCLUDED_UHD_TRANSPORT_ZERO_COPY_HPP */
Generated on Fri May 25 2012 13:02:22 for UHD by
1.8.1