/////////////////////////////////////////////////////////////////////
// This open-source software sample is offered free of charge and without guarantee.
// Polhemus accepts no responsibility or liability for any use of this code.
/////////////////////////////////////////////////////////////////////
//  VSS $Header: /Viper/VPCmdIF/VPCmdIF/CriticalSection.h 1     8/18/17 5:12p Suzanne $  
///@cond
#pragma once


#ifdef _WINDOWS_
/////////////////////////////////////////////////////////////////////
// CLASS CPiCriticalSection
/////////////////////////////////////////////////////////////////////
class CPiCriticalSection
{
public:
	CPiCriticalSection( void )
	{  
		::InitializeCriticalSection( &m_cs ); 
	}

	void	Enter	( void )
	{
		::EnterCriticalSection( &m_cs );
	}

	void	Leave	( void )
	{
		::LeaveCriticalSection( &m_cs );
	}

	~CPiCriticalSection( void )
	{
		::LeaveCriticalSection( &m_cs );
		::DeleteCriticalSection( &m_cs );
	}

protected:
	CRITICAL_SECTION m_cs;
};

class CPiUseCriticalSection
{
public:
	CPiUseCriticalSection( CPiCriticalSection * pCS ) : m_pCS(0)
	{
		_ASSERT( pCS );
		m_pCS = pCS;

		pCS->Enter();
	}

	~CPiUseCriticalSection( void )
	{
		_ASSERT(m_pCS);
		m_pCS->Leave();
	}
protected:
	CPiCriticalSection * m_pCS;
};

#else
class CPiCriticalSection
{
public:
	CPiCriticalSection(void)
	{
	}

	void	Enter(void)
	{
	}

	void	Leave(void)
	{
	}

	~CPiCriticalSection(void)
	{
	}

protected:
	//CRITICAL_SECTION m_cs;
};

#endif
///@endcond
