enderalse/SKSE/Plugins/fs_skse_plugin_functions/common/ICriticalSection.h
2021-10-06 02:45:46 +02:00

36 lines
674 B
C++

#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;
};