00001 #ifndef BLOCKQUEUE_H
00002 #define BLOCKQUEUE_H
00003 #include <string.h>
00004
00005 class blockQueue
00006 {
00007 public:
00008 blockQueue(int blockSize = 16*16*3, int queueSize = 512);
00009 ~blockQueue();
00010
00011 int Enqueue(void *block);
00012 void *GetTailBlock();
00013 int Dequeue();
00014 bool isEmpty();
00015 inline bool isFull();
00016
00017 private:
00018 int updateCurrentSize();
00019
00020 unsigned char* data;
00021 int currentSize;
00022 int blockSize;
00023 int queueSize;
00024 long int tail;
00025 long int head;
00026 };
00027
00028
00029
00030 inline int blockQueue::Enqueue(void *block)
00031 {
00032
00033
00034
00035
00036
00037 if (!isFull())
00038 {
00039 memcpy(data + (head%queueSize)*blockSize, block, blockSize);
00040 ++head;
00041 return updateCurrentSize();
00042 }
00043 else
00044 return -1;
00045 }
00046
00047 inline void *blockQueue::GetTailBlock()
00048 {
00049 return (void *)(data + (tail%queueSize)*blockSize);
00050 }
00051
00052 inline int blockQueue::Dequeue()
00053 {
00054
00055
00056
00057 if (!isEmpty())
00058 {
00059 ++tail;
00060 return updateCurrentSize();
00061 }
00062 else
00063 return -1;
00064 }
00065
00066 inline bool blockQueue::isEmpty()
00067 {
00068 return (currentSize <= 0);
00069 }
00070
00071 inline bool blockQueue::isFull()
00072 {
00073 return (currentSize >= queueSize);
00074 }
00075
00076 inline int blockQueue::updateCurrentSize()
00077 {
00078 return (currentSize = head - tail);
00079 }
00080
00081 #endif // blockQueue.h