00001
00002
00003
00004
00005
00006
00007 #ifndef __recycler_h
00008 #define __recycler_h
00009
00010 #include <qmutex.h>
00011 #include <qwaitcondition.h>
00012
00013 class Buffer;
00014
00015
00016 class Recycler
00017 {
00018 public:
00019 Recycler(unsigned int sz);
00020 ~Recycler();
00021
00022 bool full() const;
00023 bool empty() const;
00024
00025 int available() const;
00026 int used() const;
00027
00028 Buffer *next();
00029 Buffer *get();
00030
00031 void add();
00032 void done();
00033
00034 void clear();
00035
00036 unsigned int size() const;
00037
00038 QMutex *mutex() { return &mtx; }
00039 QWaitCondition *cond() { return &cnd; }
00040
00041
00042 private:
00043 unsigned int buffer_count, add_index, done_index, current_count;
00044 Buffer **buffers;
00045 QMutex mtx;
00046 QWaitCondition cnd;
00047 };
00048
00049 #endif // __recycler_h