UHD 003.005.002-0-unknown

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
zero_copy.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2010-2012 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 #include <boost/detail/atomic_count.hpp>
26
27 namespace uhd{ namespace transport{
28
30 class UHD_API managed_buffer{
31 public:
32 managed_buffer(void):_ref_count(0){}
33
39 virtual void release(void) = 0;
40
45 UHD_INLINE void commit(size_t num_bytes){
46 _length = num_bytes;
47 }
48
53 template <class T> UHD_INLINE T cast(void) const{
54 return static_cast<T>(_buffer);
55 }
56
61 UHD_INLINE size_t size(void) const{
62 return _length;
63 }
64
66 template <typename T> UHD_INLINE boost::intrusive_ptr<T> make(
67 T *p, void *buffer, size_t length
68 ){
69 _buffer = buffer;
70 _length = length;
71 return boost::intrusive_ptr<T>(p);
72 }
73
74 boost::detail::atomic_count _ref_count;
75
76 protected:
77 void *_buffer;
78 size_t _length;
79 };
80
81 UHD_INLINE void intrusive_ptr_add_ref(managed_buffer *p){
82 ++(p->_ref_count);
83 }
84
85 UHD_INLINE void intrusive_ptr_release(managed_buffer *p){
86 if (--(p->_ref_count) == 0) p->release();
87 }
88
94 class UHD_API managed_recv_buffer : public managed_buffer{
95 public:
96 typedef boost::intrusive_ptr<managed_recv_buffer> sptr;
97 };
98
104 class UHD_API managed_send_buffer : public managed_buffer{
105 public:
106 typedef boost::intrusive_ptr<managed_send_buffer> sptr;
107 };
108
114 class UHD_API zero_copy_if : boost::noncopyable{
115 public:
116 typedef boost::shared_ptr<zero_copy_if> sptr;
117
123 virtual managed_recv_buffer::sptr get_recv_buff(double timeout = 0.1) = 0;
124
130 virtual size_t get_num_recv_frames(void) const = 0;
131
137 virtual size_t get_recv_frame_size(void) const = 0;
138
144 virtual managed_send_buffer::sptr get_send_buff(double timeout = 0.1) = 0;
145
151 virtual size_t get_num_send_frames(void) const = 0;
152
158 virtual size_t get_send_frame_size(void) const = 0;
159
160 };
161
162 }} //namespace
163
164 #endif /* INCLUDED_UHD_TRANSPORT_ZERO_COPY_HPP */
uhd::transport::managed_buffer
Simple managed buffer with release interface.
Definition: zero_copy.hpp:30
uhd::transport::intrusive_ptr_release
UHD_INLINE void intrusive_ptr_release(managed_buffer *p)
Definition: zero_copy.hpp:85
uhd::transport::managed_buffer::commit
UHD_INLINE void commit(size_t num_bytes)
Definition: zero_copy.hpp:45
uhd::transport::managed_buffer::release
virtual void release(void)=0
config.hpp
uhd::transport::managed_buffer::size
UHD_INLINE size_t size(void) const
Definition: zero_copy.hpp:61
uhd::transport::zero_copy_if::sptr
boost::shared_ptr< zero_copy_if > sptr
Definition: zero_copy.hpp:116
uhd::transport::managed_send_buffer
Definition: zero_copy.hpp:104
UHD_API
#define UHD_API
Definition: config.hpp:76
uhd::transport::managed_recv_buffer
Definition: zero_copy.hpp:94
UHD_INLINE
#define UHD_INLINE
Definition: config.hpp:67
uhd::transport::managed_buffer::cast
UHD_INLINE T cast(void) const
Definition: zero_copy.hpp:53
uhd::transport::managed_buffer::_ref_count
boost::detail::atomic_count _ref_count
Definition: zero_copy.hpp:74
uhd::transport::intrusive_ptr_add_ref
UHD_INLINE void intrusive_ptr_add_ref(managed_buffer *p)
Definition: zero_copy.hpp:81
uhd::transport::managed_recv_buffer::sptr
boost::intrusive_ptr< managed_recv_buffer > sptr
Definition: zero_copy.hpp:96
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:66
uhd::transport::zero_copy_if
Definition: zero_copy.hpp:114
uhd::transport::managed_send_buffer::sptr
boost::intrusive_ptr< managed_send_buffer > sptr
Definition: zero_copy.hpp:106
uhd::transport::managed_buffer::managed_buffer
managed_buffer(void)
Definition: zero_copy.hpp:32
uhd::transport::managed_buffer::_length
size_t _length
Definition: zero_copy.hpp:78
uhd::transport::managed_buffer::_buffer
void * _buffer
Definition: zero_copy.hpp:77