www.pudn.com > GDIyuvplayer.rar > CirQueue.cpp
// CirQueue.cpp: implementation of the CCirQueue class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "YUVPlayer.h"
#include "CirQueue.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
typedef unsigned char *CharPtr;
const int nDefaultQueueSize = 5;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CCirQueue::CCirQueue(int initSize = nDefaultQueueSize)
{
if (initSize < 1)
initSize = 1;
front = 0;
rear = 0;
count = 0;
size = initSize;
}
BOOL CCirQueue::CreateinHeap()
{
qlist = new CharPtr[size];
if (!qlist)
{
AfxMessageBox("memory allocate failed! ");
return FALSE;
}
return TRUE;
}
CCirQueue::~CCirQueue()
{
if (qlist) delete []qlist;
front = 0;
rear = 0;
count = 0;
size = 0;
}
void CCirQueue::QInsert(unsigned char *Queue)
{
if (count == size) return;
else
{
g_cs.Lock();
qlist[rear] = Queue;
rear = (rear+1) % size;
count ++;
g_cs.Unlock();
}
}
BOOL CCirQueue::QEmpty()
{
return count == 0;
}
BOOL CCirQueue::QFull()
{
return count == size;
}
int CCirQueue::QLength()
{
return count;
}
unsigned char * CCirQueue::QOut()
{
unsigned char* Tempory;
if (count == 0 ) return NULL;
else
{
g_cs.Lock();
Tempory = qlist[front];
front = (front + 1) % size;
count--;
g_cs.Unlock();
}
return Tempory;
}
unsigned char * CCirQueue::QFront()
{
unsigned char *data;
if (count > 0)
{
data = qlist[front];
return data;
}
else
return NULL;
}
void CCirQueue::ClearQueue()
{
g_cs.Lock();
front = 0;
rear = 0;
count = 0;
g_cs.Unlock();
}