Textractor_test/vnr/winmutex/winmutex.h

34 lines
643 B
C
Raw Normal View History

2015-04-02 22:29:31 +08: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-06-12 07:49:28 +08:00
class MutexLocker
2015-04-02 22:29:31 +08:00
{
2018-06-12 07:49:28 +08:00
HANDLE m;
2015-04-02 22:29:31 +08:00
public:
2018-06-12 07:49:28 +08:00
explicit MutexLocker(HANDLE mutex) : m(mutex)
{
WaitForSingleObject(m, 0);
}
~MutexLocker() { if (m != INVALID_HANDLE_VALUE && m != nullptr) ReleaseMutex(m); }
2015-04-02 22:29:31 +08:00
};
2018-06-13 05:31:24 +08:00
class CriticalSectionLocker
{
CRITICAL_SECTION cs;
public:
explicit CriticalSectionLocker(CRITICAL_SECTION cs) : cs(cs)
{
EnterCriticalSection(&cs);
}
~CriticalSectionLocker() { LeaveCriticalSection(&cs); }
};
2015-04-02 22:29:31 +08:00
// EOF