summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Blum2012-10-01 19:43:52 -0700
committerJosh Blum2012-10-01 19:43:52 -0700
commit29a2a6679ba8c149b1220d06225abaf89d8c88f0 (patch)
treebdf9fab2f8776cde933e889b4b7659403f89e9af
parent8e224b5da13783bfd89eccd356b030146d02396d (diff)
downloadsandhi-29a2a6679ba8c149b1220d06225abaf89d8c88f0.tar.gz
sandhi-29a2a6679ba8c149b1220d06225abaf89d8c88f0.tar.bz2
sandhi-29a2a6679ba8c149b1220d06225abaf89d8c88f0.zip
switch to fixed size queue to avoid runtime allocs
-rw-r--r--lib/gras_impl/buffer_queue.hpp14
-rw-r--r--lib/gras_impl/input_buffer_queues.hpp14
-rw-r--r--lib/gras_impl/output_buffer_queues.hpp11
3 files changed, 23 insertions, 16 deletions
diff --git a/lib/gras_impl/buffer_queue.hpp b/lib/gras_impl/buffer_queue.hpp
index b3c9cf7..e9950b8 100644
--- a/lib/gras_impl/buffer_queue.hpp
+++ b/lib/gras_impl/buffer_queue.hpp
@@ -19,26 +19,26 @@
#include <gnuradio/sbuffer.hpp>
#include <boost/bind.hpp>
-#include <queue>
+#include <boost/circular_buffer.hpp>
namespace gnuradio
{
-struct BufferQueue : std::queue<SBuffer>
+struct BufferQueue : boost::circular_buffer<SBuffer>
{
+ enum {MAX_QUEUE_SIZE = 4};
+
BufferQueue(void)
{
- SBufferDeleter deleter = boost::bind(&BufferQueue::push, this, _1);
+ this->resize(MAX_QUEUE_SIZE);
+ SBufferDeleter deleter = boost::bind(&BufferQueue::push_back, this, _1);
_token = SBufferToken(new SBufferDeleter(deleter));
}
~BufferQueue(void)
{
_token.reset();
- while (not this->empty())
- {
- this->pop();
- }
+ this->clear();
}
void allocate_one(const size_t num_bytes)
diff --git a/lib/gras_impl/input_buffer_queues.hpp b/lib/gras_impl/input_buffer_queues.hpp
index 9b0df4a..74fc5ee 100644
--- a/lib/gras_impl/input_buffer_queues.hpp
+++ b/lib/gras_impl/input_buffer_queues.hpp
@@ -25,12 +25,15 @@
#include <queue>
#include <deque>
#include <cstring> //memcpy/memset
+#include <boost/circular_buffer.hpp>
namespace gnuradio
{
struct InputBufferQueues
{
+ enum {MAX_QUEUE_SIZE = 128};
+
~InputBufferQueues(void)
{
this->resize(0);
@@ -52,6 +55,7 @@ struct InputBufferQueues
GRAS_FORCE_INLINE void push(const size_t i, const SBuffer &buffer)
{
+ ASSERT(not _queues[i].full());
_queues[i].push_back(buffer);
_enqueued_bytes[i] += _queues[i].back().length;
__update(i);
@@ -59,7 +63,7 @@ struct InputBufferQueues
GRAS_FORCE_INLINE void flush(const size_t i)
{
- _queues[i] = std::deque<SBuffer>();
+ _queues[i].clear();
_bitset.reset(i);
}
@@ -99,7 +103,7 @@ struct InputBufferQueues
BitSet _bitset;
std::vector<size_t> _enqueued_bytes;
- std::vector<std::deque<SBuffer> > _queues;
+ std::vector<boost::circular_buffer<SBuffer> > _queues;
std::vector<size_t> _history_bytes;
std::vector<size_t> _reserve_bytes;
std::vector<size_t> _multiple_bytes;
@@ -113,7 +117,7 @@ GRAS_FORCE_INLINE void InputBufferQueues::resize(const size_t size)
{
_bitset.resize(size);
_enqueued_bytes.resize(size, 0);
- _queues.resize(size);
+ _queues.resize(size, boost::circular_buffer<SBuffer>(MAX_QUEUE_SIZE));
_history_bytes.resize(size, 0);
_reserve_bytes.resize(size, 0);
_multiple_bytes.resize(size, 0);
@@ -175,7 +179,7 @@ GRAS_FORCE_INLINE void InputBufferQueues::init(
if (_history_bytes[i] > old_history)
{
SBuffer buff = _aux_queues[i]->front();
- _aux_queues[i]->pop();
+ _aux_queues[i]->pop_front();
const size_t delta = _history_bytes[i] - old_history;
std::memset(buff.get_actual_memory(), 0, delta);
@@ -242,7 +246,7 @@ GRAS_FORCE_INLINE void InputBufferQueues::__prepare(const size_t i)
else
{
dst = _aux_queues[i]->front();
- _aux_queues[i]->pop();
+ _aux_queues[i]->pop_front();
dst.offset = 0;
dst.length = 0;
_in_aux_buff[i] = true;
diff --git a/lib/gras_impl/output_buffer_queues.hpp b/lib/gras_impl/output_buffer_queues.hpp
index 18eb551..69c5eb0 100644
--- a/lib/gras_impl/output_buffer_queues.hpp
+++ b/lib/gras_impl/output_buffer_queues.hpp
@@ -19,7 +19,7 @@
#include <gras_impl/bitset.hpp>
#include <vector>
-#include <deque>
+#include <boost/circular_buffer.hpp>
namespace gnuradio
{
@@ -27,13 +27,15 @@ namespace gnuradio
template <typename T>
struct OutputBufferQueues
{
+ enum {MAX_QUEUE_SIZE = 128};
+
BitSet _bitset;
- std::vector<std::deque<T> > _queues;
+ std::vector<boost::circular_buffer<T> > _queues;
GRAS_FORCE_INLINE void resize(const size_t size)
{
_bitset.resize(size);
- _queues.resize(size);
+ _queues.resize(size, boost::circular_buffer<T>(MAX_QUEUE_SIZE));
}
GRAS_FORCE_INLINE void push(const size_t i, const T &value)
@@ -45,6 +47,7 @@ struct OutputBufferQueues
//! 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);
}
@@ -67,7 +70,7 @@ struct OutputBufferQueues
GRAS_FORCE_INLINE void flush(const size_t i)
{
- _queues[i] = std::deque<T>();
+ _queues[i].clear();
_bitset.reset(i);
}