Esempio n. 1
0
VOID CRWLock::Done()
{
	ASSERT(m_nActive	 == 0);
	ASSERT(m_dwWriterTID == 0);

	CSEM* pSem	 = nullptr;
	LONG  lCount = 1;

	{
		CCriSecLock locallock(m_cs);

		if(m_nWaitingWriters > 0)
		{
			--m_nActive;
			--m_nWaitingWriters;
			pSem = &m_smWrite;
		}
		else if(m_nWaitingReaders > 0)
		{
			m_nActive	= m_nWaitingReaders;
			lCount		= m_nWaitingReaders;
			pSem		= &m_smRead;
			m_nWaitingReaders = 0;
		}
	}

	if(pSem != nullptr)
	{
		pSem->Release(lCount);
	}
}
Esempio n. 2
0
VOID CSWMR::Done()
{
	CSEM* pSem  = nullptr;
	LONG lCount = 1;

	{
		CSpinLock locallock(m_cs);

		if(m_nActive > 0)
			--m_nActive;
		else
			++m_nActive;

		if(m_nActive == 0)
		{
			if(m_nWaitingWriters > 0)
			{
				m_nActive = -1;
				--m_nWaitingWriters;
				pSem = &m_smWrite;
			}
			else if(m_nWaitingReaders > 0)
			{
				m_nActive = m_nWaitingReaders;
				m_nWaitingReaders = 0;
				pSem = &m_smRead;
				lCount = m_nActive;
			}
		}
	}

	if(pSem != nullptr)
		pSem->Release(lCount);
}
Esempio n. 3
0
VOID CRWLock::WriteDone()
{
	CSEM* pSem	 = nullptr;
	LONG  lCount = 0;

	{
		CSpinLock locallock(m_cs);

		ASSERT(m_nActive < 0);

		if(++m_nActive == 0)
		{
			DetachOwner();
			Done(&pSem, lCount);
		}
		else
			ASSERT(IsOwner());
	}

	if(pSem != nullptr)
		pSem->Release(lCount);
}
Esempio n. 4
0
VOID CRWLock::ReadDone()
{
	CSEM* pSem	 = nullptr;
	LONG  lCount = 0;

	{
		CSpinLock locallock(m_cs);

		ASSERT(m_nActive != 0);

		if(m_nActive > 0)
		{
			if(--m_nActive == 0)
				Done(&pSem, lCount);
		}
		else
			ASSERT(IsOwner());
	}

	if(pSem != nullptr)
		pSem->Release(lCount);
}