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
|
|
|
|
|
2017-03-10 15:12:52 +00:00
|
|
|
class FInternalCriticalSection
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-03-10 15:12:52 +00:00
|
|
|
FInternalCriticalSection()
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
InitializeCriticalSection(&CritSec);
|
|
|
|
}
|
2017-03-10 15:12:52 +00:00
|
|
|
~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;
|
|
|
|
};
|
|
|
|
|
2017-03-10 15:12:52 +00:00
|
|
|
|
|
|
|
FInternalCriticalSection *CreateCriticalSection()
|
|
|
|
{
|
|
|
|
return new FInternalCriticalSection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeleteCriticalSection(FInternalCriticalSection *c)
|
|
|
|
{
|
|
|
|
delete c;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnterCriticalSection(FInternalCriticalSection *c)
|
|
|
|
{
|
|
|
|
c->Enter();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LeaveCriticalSection(FInternalCriticalSection *c)
|
|
|
|
{
|
|
|
|
c->Leave();
|
|
|
|
}
|