// ProcPADThread.cpp : implementation file // #include "StdAfx.h" #include "Thread_Send.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CThread_SendMSG CThread_SendMSG::CThread_SendMSG(DWORD dwPeriod) : CTimerThreadPool(dwPeriod,1) { m_pS2M = NULL; } CThread_SendMSG::~CThread_SendMSG() { ClearMSG(); } BOOL CThread_SendMSG::CreateThread() { BOOL bReturn = TRUE; // Thread 积己 饶 Thread 荐青 bReturn = CreateTimerThread(this); return bReturn; } void CThread_SendMSG::TimerThreadProcess(PVOID pParameter) { CThread_SendMSG* pSendThread = static_cast(pParameter); if(pSendThread == NULL) return; if(pSendThread->m_pS2M == NULL) { return; } std::vector *pVecNetMSG; std::vector vecMSG; std::vector::iterator it; std::vector *pVecDisableMSG; std::vector vecDisableMSG; std::vector::iterator itDis; CPostSendMessage SendNetMSG; CDisableSendMessage DisableMSG; CSingleLock MyLock(&pSendThread->m_csNetMSG); MyLock.Lock(); pVecNetMSG = pSendThread->GetVecSendMSG(); if(pVecNetMSG->empty() == FALSE) { vecMSG.resize(pVecNetMSG->size()); std::copy(pVecNetMSG->begin(),pVecNetMSG->end(),vecMSG.begin()); pVecNetMSG->clear(); } MyLock.Unlock(); Sleep(0); CSingleLock MyUnLock(&pSendThread->m_csDisableMSG); MyUnLock.Lock(); pVecDisableMSG = pSendThread->GetVecDisableMSG(); if(pVecDisableMSG->empty() == FALSE) { vecDisableMSG.resize(pVecDisableMSG->size()); std::copy(pVecDisableMSG->begin(),pVecDisableMSG->end(),vecDisableMSG.begin()); pVecDisableMSG->clear(); } MyUnLock.Unlock(); Sleep(0); for(it=vecMSG.begin();it!=vecMSG.end();it++) { SendNetMSG = *it; pSendThread->m_pS2M->SendMSG_Received(&SendNetMSG); } vecMSG.clear(); Sleep(0); DWORD dwTick; for(itDis=vecDisableMSG.begin();itDis!=vecDisableMSG.end();itDis++) { DisableMSG = *itDis; if(DisableMSG.dwStart <= 0 || DisableMSG.dwOntime <= 0) continue; dwTick = GetTickCount()-DisableMSG.dwStart; if(dwTick >= DisableMSG.dwOntime) { DisableMSG.nValue = 0; pSendThread->m_pS2M->SendMSG_Received(&DisableMSG); } else { CSingleLock MyUnLock(&pSendThread->m_csDisableMSG); MyUnLock.Lock(); pSendThread->m_VecDisableMSG.push_back(DisableMSG); MyUnLock.Unlock(); } } vecDisableMSG.clear(); } int CThread_SendMSG::AddDisableMSG(SEND_MESSAGE_SECTION emSection,int nSignal, int nValue, DWORD dwOntime) { CDisableSendMessage DisableMsg; DisableMsg.emSection = emSection; DisableMsg.nSignal = nSignal; DisableMsg.nValue = nValue; DisableMsg.dwOntime = dwOntime; DisableMsg.dwStart = GetTickCount(); CSingleLock MyLock(&m_csDisableMSG); MyLock.Lock(); m_VecDisableMSG.push_back(DisableMsg); int nCount = (int)m_VecDisableMSG.size(); MyLock.Unlock(); return nCount; } int CThread_SendMSG::AddSendMSG(SEND_MESSAGE_SECTION emSection,int nSignal, int nValue) { CPostSendMessage netMessage; netMessage.emSection = emSection; netMessage.nSignal = nSignal; netMessage.nValue = nValue; CSingleLock MyLock(&m_csNetMSG); MyLock.Lock(); m_VecSendMSG.push_back(netMessage); int nCount = (int)m_VecSendMSG.size(); MyLock.Unlock(); return nCount; } BOOL CThread_SendMSG::ClearMSG() { CSingleLock MyLock(&m_csNetMSG); MyLock.Lock(); m_VecSendMSG.clear(); MyLock.Unlock(); CSingleLock MyUnLock(&m_csDisableMSG); MyUnLock.Lock(); m_VecDisableMSG.clear(); MyUnLock.Unlock(); return TRUE; }