blob: 69c5eb0ce3cf3b69d820f7fab316585351bd27c4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
//
// Copyright 2012 Josh Blum
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with io_sig program. If not, see <http://www.gnu.org/licenses/>.
#ifndef INCLUDED_LIBGRAS_IMPL_OUTPUT_BUFFER_QUEUES_HPP
#define INCLUDED_LIBGRAS_IMPL_OUTPUT_BUFFER_QUEUES_HPP
#include <gras_impl/bitset.hpp>
#include <vector>
#include <boost/circular_buffer.hpp>
namespace gnuradio
{
template <typename T>
struct OutputBufferQueues
{
enum {MAX_QUEUE_SIZE = 128};
BitSet _bitset;
std::vector<boost::circular_buffer<T> > _queues;
GRAS_FORCE_INLINE void resize(const size_t size)
{
_bitset.resize(size);
_queues.resize(size, boost::circular_buffer<T>(MAX_QUEUE_SIZE));
}
GRAS_FORCE_INLINE void push(const size_t i, const T &value)
{
_queues[i].push_back(value);
_bitset.set(i);
}
//! used for input buffer inlining
GRAS_FORCE_INLINE void push_front(const size_t i, const T &value)
{
ASSERT(not _queues[i].full());
_queues[i].push_front(value);
_bitset.set(i);
}
GRAS_FORCE_INLINE const T &front(const size_t i) const
{
return _queues[i].front();
}
GRAS_FORCE_INLINE T &front(const size_t i)
{
return _queues[i].front();
}
GRAS_FORCE_INLINE void pop(const size_t i)
{
_queues[i].pop_front();
_bitset.set(i, not _queues[i].empty());
}
GRAS_FORCE_INLINE void flush(const size_t i)
{
_queues[i].clear();
_bitset.reset(i);
}
GRAS_FORCE_INLINE void flush_all(void)
{
_queues.clear();
_queues.resize(_bitset.size());
_bitset.reset();
}
GRAS_FORCE_INLINE bool ready(const size_t i) const
{
return not _queues[i].empty();
}
GRAS_FORCE_INLINE bool empty(const size_t i) const
{
return _queues[i].empty();
}
GRAS_FORCE_INLINE bool all_ready(void) const
{
return _bitset.all();
}
GRAS_FORCE_INLINE size_t size(void) const
{
return _queues.size();
}
};
} //namespace gnuradio
#endif /*INCLUDED_LIBGRAS_IMPL_OUTPUT_BUFFER_QUEUES_HPP*/
|