diff options
Diffstat (limited to 'lib/buffer_queue_pool.cpp')
-rw-r--r-- | lib/buffer_queue_pool.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/lib/buffer_queue_pool.cpp b/lib/buffer_queue_pool.cpp new file mode 100644 index 0000000..db9b68a --- /dev/null +++ b/lib/buffer_queue_pool.cpp @@ -0,0 +1,67 @@ +// 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 SBufferConfig &config, const size_t num): + _token(config.token), //save config, its holds token + _queue(boost::circular_buffer<SBuffer>(num)) + { + //NOP + } + + ~BufferQueuePool(void) + { + _token.reset(); + _queue.clear(); + } + + SBuffer &front(void) + { + ASSERT(not _queue.empty()); + ASSERT(_queue.front()); + return _queue.front(); + } + + void pop(void) + { + ASSERT(not _queue.empty()); + _queue.front().reset(); //dont hold ref + _queue.pop_front(); + } + + void push(const SBuffer &buff) + { + _queue.push_back(buff); + } + + bool empty(void) const + { + return _queue.empty(); + } + + SBufferToken _token; + boost::circular_buffer<SBuffer> _queue; + +}; + +BufferQueueSptr BufferQueue::make_pool( + const SBufferConfig &config, + const size_t num_buffs +){ + BufferQueueSptr queue(new BufferQueuePool(config, 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()); + //buffer derefs and returns to this queue thru token callback + } + + return queue; +} |