//初始化,创建对列
template <class T>
TMultiRWQueue<T>::TMultiRWQueue()
{
m_bInit =FALSE;
m_Head = NULL ; //队列起点
m_Tail = NULL; //对列终点
m_Put = NULL; //下一个写入位置
m_Get = NULL; //下一个读取位置
m_uiCount = 0;
}
template <class T>
bool TMultiRWQueue<T>::init(int iSize)
{
if (m_bInit)
{
return true;
}
m_bInit = TRUE;
m_uiSize = iSize;
if (m_uiSize <= 0)
{
m_uiSize = 1;
}
//分配空间
Element *buff = new Element[m_uiSize];
if (buff)
{
m_Head = buff;
m_Get = m_Put = m_Head;
m_Tail = m_Head + m_uiSize ;
if (!m_semaGet.Create(0,m_uiSize) ||
!m_semaPut.Create(m_uiSize,m_uiSize))
{
return false;
}
}
return false;
}
//读写队列析构函数,释放读写队列中的资源
template <class T>
TMultiRWQueue<T>::~TMultiRWQueue()
{
if (!m_bInit)
{
return ;
}
if (m_Head)
{
delete []m_Head;
}
}