windows-nt/Source/XPSP1/NT/com/mobile/sens/conn/senslogn/mutex.hxx

85 lines
1.1 KiB
C++
Raw Normal View History

2020-09-26 03:20:57 -05:00
//+-------------------------------------------------------------------------
//
// Microsoft Windows
//
// Copyright (C) Microsoft Corporation, 1998 - 1999
//
// File: mutex.hxx
//
//--------------------------------------------------------------------------
class MUTEX
{
public:
MUTEX( DWORD * pStatus )
{
*pStatus = RtlInitializeCriticalSection(&c);
}
~MUTEX()
{
RtlDeleteCriticalSection(&c);
}
void Enter()
{
RtlEnterCriticalSection(&c);
}
void Leave()
{
RtlLeaveCriticalSection(&c);
}
private:
RTL_CRITICAL_SECTION c;
};
class CLAIM_MUTEX
{
public:
CLAIM_MUTEX( MUTEX & Mutex )
: Lock( Mutex )
{
Taken = 0;
Enter();
}
void Enter()
{
Lock.Enter();
++Taken;
}
void Leave()
{
ASSERT( Taken > 0 );
Lock.Leave();
--Taken;
}
~CLAIM_MUTEX()
{
ASSERT( Taken >= 0 );
while (Taken > 0)
{
Leave();
}
}
private:
signed Taken;
MUTEX & Lock;
};