00001
00002
00003
00004
00005
00006
00007 #ifndef __recycler_h
00008 #define __recycler_h
00009
00010 #include <QMutex>
00011 #include <QWaitCondition>
00012
00013 class Buffer;
00014
00018 class Recycler
00019 {
00020 public:
00025 Recycler(unsigned int sz);
00029 ~Recycler();
00033 bool full() const;
00037 bool empty() const;
00041 int available() const;
00045 int used() const;
00049 Buffer *next();
00053 Buffer *get();
00057 void add();
00061 void done();
00065 void clear();
00069 unsigned int size() const;
00073 QMutex *mutex()
00074 {
00075 return &mtx;
00076 }
00080 QWaitCondition *cond()
00081 {
00082 return &cnd;
00083 }
00087 bool blocked();
00088
00089 private:
00090 unsigned int buffer_count, add_index, done_index, current_count;
00091 Buffer **buffers;
00092 QMutex mtx;
00093 QWaitCondition cnd;
00094 Buffer *m_blocked;
00095 };
00096
00097 #endif // __recycler_h