windows-nt/Source/XPSP1/NT/multimedia/directx/dplay/dnet/common/dvcslock.h

50 lines
974 B
C
Raw Normal View History

2020-09-26 03:20:57 -05:00
/*==========================================================================
* Copyright (C) 1999, 2000 Microsoft Corporation. All Rights Reserved.
*
* File: dvcslock.h
* Content: Class to handle auto-leave of critical sections
* History:
* Date By Reason
* ==== == ======
* 07/05/00 rodtoll Created It
*
***************************************************************************/
#ifndef __DVCSLOCK_H
#define __DVCSLOCK_H
// CDVCSLock
//
// A class to provide automatic unlocking of critical sections when the object
// passes out of scope.
//
class CDVCSLock
{
public:
CDVCSLock( DNCRITICAL_SECTION *pcs ): m_pcs( pcs ), m_fLocked( FALSE )
{
};
~CDVCSLock()
{
if( m_fLocked ) DNLeaveCriticalSection( m_pcs );
}
void Lock()
{
DNEnterCriticalSection( m_pcs );
m_fLocked = TRUE;
}
void Unlock()
{
DNLeaveCriticalSection( m_pcs );
m_fLocked = FALSE;
}
private:
DNCRITICAL_SECTION *m_pcs;
BOOL m_fLocked;
};
#endif