4
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

35 lines
674 B

#pragma once
class ICriticalSection
{
public:
ICriticalSection() { InitializeCriticalSection(&critSection); }
~ICriticalSection() { DeleteCriticalSection(&critSection); }
void Enter(void) { EnterCriticalSection(&critSection); }
void Leave(void) { LeaveCriticalSection(&critSection); }
bool TryEnter(void) { return TryEnterCriticalSection(&critSection) != 0; }
private:
CRITICAL_SECTION critSection;
};
class IScopedCriticalSection
{
public:
IScopedCriticalSection(ICriticalSection * cs)
:m_cs(cs)
{
m_cs->Enter();
}
~IScopedCriticalSection()
{
m_cs->Leave();
}
private:
IScopedCriticalSection(); // undefined
ICriticalSection * m_cs;
};