00001 // Copyright (c) 2000-2001 Brad Hughes <bhughes@trolltech.com> 00002 // 00003 // Use, modification and distribution is allowed without limitation, 00004 // warranty, or liability of any kind. 00005 // 00006 00007 #ifndef __recycler_h 00008 #define __recycler_h 00009 00010 #include <QWaitCondition> 00011 #include <QMutex> 00012 00013 class Buffer; 00014 00015 00016 class Recycler 00017 { 00018 public: 00019 Recycler(unsigned int sz); // sz = size in bytes 00020 ~Recycler(); 00021 00022 bool full() const; 00023 bool empty() const; 00024 00025 int available() const; 00026 int used() const; 00027 00028 Buffer *next(); // get next in queue 00029 Buffer *get(); // get next in recycle 00030 00031 void add(); // add to queue 00032 void done(); // add to recycle 00033 00034 void clear(); // clear queue 00035 00036 unsigned int size() const; // size in bytes 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
1.6.3