36 lines
687 B
C
Raw Normal View History

2015-04-02 23:29:31 +09:00
#pragma once
// winmutex.h
// 12/11/2011 jichi
#include <windows.h>
#ifdef _MSC_VER
# pragma warning(disable:4800) // C4800: forcing value to bool
#endif // _MSC_VER
2018-07-20 17:36:58 -04:00
// Artikash 7/20/2018: these are similar to std::lock guard but use Winapi objects
2015-04-02 23:29:31 +09:00
2018-07-20 17:36:58 -04:00
class MutexLocker
{
HANDLE m;
public:
explicit MutexLocker(HANDLE mutex) : m(mutex)
{
WaitForSingleObject(m, 0);
}
~MutexLocker() { if (m != INVALID_HANDLE_VALUE && m != nullptr) ReleaseMutex(m); }
};
class CriticalSectionLocker
{
CRITICAL_SECTION cs;
public:
explicit CriticalSectionLocker(CRITICAL_SECTION cs) : cs(cs)
{
EnterCriticalSection(&cs);
}
~CriticalSectionLocker() { LeaveCriticalSection(&cs); }
};
2018-06-12 17:31:24 -04:00
2015-04-02 23:29:31 +09:00
// EOF