Esempio n. 1
0
void CCommMsgContainer::AddCommMsg( CCommMsg & msg )
{
	CSingleLock lock (&m_Mutex);
	lock.Lock();
	if (m_arrCommMsg.size() >= MAX_COMM_MSG_CNT)
	{
		lock.Unlock();
		return;
	}

	m_arrCommMsg.push_back(msg);
	lock.Unlock();
}
//--------------------------------------------------------------------------------
bool CLockedResource::GetExclusiveLock(CSingleLock& rLock, DWORD nWait)
	{
	nWait /= 2;

	if(! rLock.Lock(nWait))
		return false;

	// if there are still readers then wait til they're done reading
	if(m_nCurrentUserCount > 0)
		{
		CTime ctStart(CTime::GetCurrentTime());

		::Sleep(20);

		while(m_nCurrentUserCount > 0)
			{
			if(nWait != INFINITE)
				// if the wait time is exceeded then bail
				if(ctStart + nWait < CTime::GetCurrentTime())
					{
					rLock.Unlock();
					return false;
					}

			::Sleep(20);
			}
		}

	m_nCurrentUserCount = 0;
	return true;
	}
Esempio n. 3
0
bool  CPingMsgContainer::GetPingMsg(  CPingMsg & msg )
{
	CSingleLock lock (&m_Mutex);
	lock.Lock();
	if (m_arrPingMsg.empty())
	{
		lock.Unlock();
		return false;
	}
	CPingMsg  ret_msg = m_arrPingMsg.front();
	m_arrPingMsg.pop_front();
	msg = ret_msg;
	return true;
}
Esempio n. 4
0
void CPingMsgContainer::AddPingMsg(CPingMsg &msg)
{	
	GetSystemTime(& msg.m_stReply);
	m_nPingCnt ++;

	CSingleLock lock (&m_Mutex);
	lock.Lock();
	if (m_arrPingMsg.size() >= MAX_COMM_MSG_CNT)
	{
		lock.Unlock();
		return;
	}
	msg.m_nIdx = m_nPingCnt;
	if (msg.m_nStatus)
	{
		m_nLostCnt++;
	}
	else
	{
		m_nReplyCnt ++;
	}
	m_arrPingMsg.push_back(msg);
	lock.Unlock();
}