qzdoom/src/win32/critsec.cpp

58 lines
922 B
C++
Raw Normal View History

2016-03-01 15:47:10 +00:00
// Wraps a Windows critical section object.
#ifndef _WINNT_
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
class FInternalCriticalSection
2016-03-01 15:47:10 +00:00
{
public:
FInternalCriticalSection()
2016-03-01 15:47:10 +00:00
{
InitializeCriticalSection(&CritSec);
}
~FInternalCriticalSection()
2016-03-01 15:47:10 +00:00
{
DeleteCriticalSection(&CritSec);
}
void Enter()
{
EnterCriticalSection(&CritSec);
}
void Leave()
{
LeaveCriticalSection(&CritSec);
}
#if 0
// SDL has no equivalent functionality, so better not use it on Windows.
bool TryEnter()
{
return TryEnterCriticalSection(&CritSec) != 0;
}
#endif
private:
CRITICAL_SECTION CritSec;
};
FInternalCriticalSection *CreateCriticalSection()
{
return new FInternalCriticalSection();
}
void DeleteCriticalSection(FInternalCriticalSection *c)
{
delete c;
}
void EnterCriticalSection(FInternalCriticalSection *c)
{
c->Enter();
}
void LeaveCriticalSection(FInternalCriticalSection *c)
{
c->Leave();
}