mirror of
https://github.com/Artikash/Textractor.git
synced 2024-12-24 01:14:12 +08:00
34 lines
643 B
C++
34 lines
643 B
C++
#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
|
|
|
|
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); }
|
|
};
|
|
|
|
// EOF
|