aboutsummaryrefslogtreecommitdiff
path: root/lib/recycler.h
blob: b01742350f6b045c1b2396b05758d04ba04f6c77 (plain) (blame)
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
// Copyright (c) 2000-2001 Brad Hughes <bhughes@trolltech.com>
//
// Use, modification and distribution is allowed without limitation,
// warranty, or liability of any kind.
//

#ifndef __recycler_h
#define __recycler_h

#include <QMutex>
#include <QWaitCondition>

class Buffer;


class Recycler
{
public:
    Recycler(unsigned int sz); // sz = size in bytes
    ~Recycler();

    bool full() const;
    bool empty() const;

    int available() const;
    int used() const;

    Buffer *next(); // get next in queue
    Buffer *get(); // get next in recycle

    void add(); // add to queue
    void done(); // add to recycle

    void clear(); // clear queue

    unsigned int size() const; // size in bytes

    QMutex *mutex() { return &mtx; }
    QWaitCondition *cond() { return &cnd; }


private:
    unsigned int buffer_count, add_index, done_index, current_count;
    Buffer **buffers;
    QMutex mtx;
    QWaitCondition cnd;
};

#endif // __recycler_h