/////////////////////////////////////////////////////////////////////////////
//
//	Copyright (c) 1996-1997 Microsoft Corporation
//
//	Module Name:
//		CritSec.h
//
//	Abstract:
//		Definition of the CCritSec class.
//
//	Author:
//		David Potter (davidp)	November 18, 1997
//
//	Revision History:
//
//	Notes:
//
/////////////////////////////////////////////////////////////////////////////

#ifndef __CRITSEC_H_
#define __CRITSEC_H_

/////////////////////////////////////////////////////////////////////////////
// Forward Class Declarations
/////////////////////////////////////////////////////////////////////////////

class CCritSec;

/////////////////////////////////////////////////////////////////////////////
// External Class Declarations
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// Include Files
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// class CCritSec
/////////////////////////////////////////////////////////////////////////////

class CCritSec
{
protected:
	CRITICAL_SECTION	m_critsec;	// Critical section data.

public:
	CCritSec(void)
	{
		InitializeCriticalSection(&m_critsec);
	}

	~CCritSec(void)
	{
		// Make sure no one is holding the critical section
		// before we delete it.
		Lock();
		Unlock();
		DeleteCriticalSection(&m_critsec);
	}

	// Acquire the critical section
	void Lock(void)
	{
		EnterCriticalSection(&m_critsec);
	}

	// Release the critical section
	void Unlock(void)
	{
		LeaveCriticalSection(&m_critsec);
	}

};  //*** class CCritSec

/////////////////////////////////////////////////////////////////////////////

#endif // __CRITSEC_H_
