diff options
author | Josh Blum | 2012-12-15 09:53:25 -0800 |
---|---|---|
committer | Josh Blum | 2012-12-15 09:53:25 -0800 |
commit | b7c0a59c0a86f289f55935b19efaf448e892eefb (patch) | |
tree | 1e641f9816237481124835ac2fbf2792a8b1d50f /lib/buffer_queue_pool.cpp | |
parent | 6a03c661ede88203ff90eb01bf1e678b87cb6056 (diff) | |
download | sandhi-b7c0a59c0a86f289f55935b19efaf448e892eefb.tar.gz sandhi-b7c0a59c0a86f289f55935b19efaf448e892eefb.tar.bz2 sandhi-b7c0a59c0a86f289f55935b19efaf448e892eefb.zip |
work on the buffer queue api
Diffstat (limited to 'lib/buffer_queue_pool.cpp')
-rw-r--r-- | lib/buffer_queue_pool.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/buffer_queue_pool.cpp b/lib/buffer_queue_pool.cpp new file mode 100644 index 0000000..a30f4a6 --- /dev/null +++ b/lib/buffer_queue_pool.cpp @@ -0,0 +1,54 @@ +// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. + +#include <gras/buffer_queue.hpp> +#include <gras_impl/debug.hpp> +#include <boost/circular_buffer.hpp> + +using namespace gras; + +struct BufferQueuePool : BufferQueue +{ + BufferQueuePool(const size_t num) + { + queue.resize(num); + } + + SBuffer &front(void) + { + return queue.front(); + } + + void pop(void) + { + ASSERT(not queue.empty()); + queue.front() = SBuffer(); //dont hold ref + queue.pop_front(); + } + + void push(const SBuffer &buff) + { + queue.push_back(buff); + } + + bool empty(void) const + { + return queue.empty(); + } + + boost::circular_buffer<SBuffer> queue; + +}; + +BufferQueueSptr BufferQueue::make_pool( + const SBufferConfig &config, + const size_t num_buffs +){ + BufferQueueSptr bq(new BufferQueuePool(num_buffs)); + for (size_t i = 0; i < num_buffs; i++) + { + SBuffer buff(config); + std::memset(buff.get_actual_memory(), 0, buff.get_actual_length()); + bq->push(buff); + } + return bq; +} |