summaryrefslogtreecommitdiff
path: root/lib/buffer_queue_pool.cpp
blob: a2a4c283cb749bd183ff1e593989c3d0e8b80629 (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
// 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(boost::circular_buffer<SBuffer>(num))
    {
        //NOP
    }

    SBuffer &front(void)
    {
        ASSERT(not queue.empty());
        ASSERT(queue.front());
        return queue.front();
    }

    void pop(void)
    {
        ASSERT(not queue.empty());
        queue.front() = SBuffer(); //dont hold ref
        queue.pop_front();
    }

    void push(const SBuffer &buff)
    {
        ASSERT(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;
}