?? msgbuff.cpp
字號:
// MsgBuff.cpp: implementation of the CMsgBuff class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "SimSensor.h"
#include "MsgBuff.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMsgBuff::CMsgBuff()
{
pHead = NULL;
pTail = NULL;
InitializeCriticalSection(&Locked);
}
CMsgBuff::~CMsgBuff()
{
EnterCriticalSection(&Locked);
while ( !IsEmpty() ) {
CMsg *pMsg = GetMsg();
DELETE_OBJECT(pMsg);
}
LeaveCriticalSection(&Locked);
}
void CMsgBuff::AddMsg(CMsg *pMsg)
{
CMsgStrain *pMsgStrain = new CMsgStrain;
pMsgStrain->Message = pMsg;
EnterCriticalSection(&Locked);
if ( pTail!=NULL ) {
pTail->pNext = pMsgStrain;
pTail = pTail->pNext;
}else {
pHead = pMsgStrain;
pTail = pMsgStrain;
}
LeaveCriticalSection(&Locked);
}
CMsg * CMsgBuff::GetMsg()
{
EnterCriticalSection(&Locked);
if ( pHead == NULL) {
LeaveCriticalSection(&Locked);
return NULL;
}
CMsgStrain *pMsgStrain = pHead;
pHead = pHead->pNext;
if ( pHead==NULL ) pTail=NULL;
CMsg * pMsg = pMsgStrain->Message;
LeaveCriticalSection(&Locked);
DELETE_OBJECT(pMsgStrain);
return pMsg;
}
void CMsgBuff::InsertMsg(CMsg *pMsg)
{
CMsgStrain *pMsgStrain = new CMsgStrain;
pMsgStrain->Message = pMsg;
EnterCriticalSection(&Locked);
if (pHead!=NULL) {
pMsgStrain->pNext = pHead;
pHead = pMsgStrain;
}else {
pHead = pMsgStrain;
pTail = pMsgStrain;
}
LeaveCriticalSection(&Locked);
}
BOOL CMsgBuff::IsEmpty()
{
BOOL Rtn;
EnterCriticalSection(&Locked);
if ( pHead == NULL) Rtn = TRUE;
else Rtn = FALSE;
LeaveCriticalSection(&Locked);
return Rtn;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -