pans
2017-08-30 71c92f101b6c8b4a678a8c3cfe2d8edbf488efa4
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
#ifndef _PreAllocBufferPriorityList_H_
#define _PreAllocBufferPriorityList_H_
 
#include <cstdint>
#include <vector>
 
class PreAllocBuffers
{
public:
    struct Config
    {
        bool multithreadSafe;
        bool fullQueueDropFront;
        bool fullQueueSync;
        size_t count;
        size_t maxBuffSize;
        buffer_ud_deleter bud_deleter;//#todo no-impl
 
        Config()
            : multithreadSafe(false), fullQueueDropFront(false), fullQueueSync(false), count(0), maxBuffSize(0), bud_deleter(nullptr)
        { }
    };
 
    struct Buffer
    {
        uint8_t* buffer;
        size_t buffSize;
        void* userData;
 
        Buffer() : buffer(nullptr), buffSize(0), userData(nullptr) { }
    };
 
    PreAllocBufferPriorityList(const Config& _cfg);
    ~PreAllocBufferPriorityList();
 
    Buffer* GetFree();
    void Release(Buffer* buffer);
 
    bool Empty() const;
    bool Full() const;
 
private:
    const Config cfg;
    void* mtsMux;
 
    typedef std::vector<Buffer*> buffers_vec_t;
    buffers_vec_t allBuffers;
    buffers_vec_t freeBuffers;
};
 
#endif