2015-04-02 23:29:31 +09:00
|
|
|
#pragma once
|
|
|
|
// winmutex.h
|
|
|
|
// 12/11/2011 jichi
|
|
|
|
|
|
|
|
#include <windows.h>
|
2018-08-22 12:24:55 -04:00
|
|
|
#include "common.h"
|
2015-04-02 23:29:31 +09:00
|
|
|
|
2018-08-21 22:43:30 -04:00
|
|
|
// Artikash 7/20/2018: similar to std::lock guard but use Winapi objects for cross process comms
|
2015-04-02 23:29:31 +09:00
|
|
|
|
2018-07-20 17:36:58 -04:00
|
|
|
class MutexLocker
|
|
|
|
{
|
2018-08-08 23:56:36 -04:00
|
|
|
HANDLE mutex;
|
2018-07-20 17:36:58 -04:00
|
|
|
public:
|
2018-08-22 12:24:55 -04:00
|
|
|
MutexLocker(HANDLE mutex) : mutex(mutex) { WaitForSingleObject(mutex, 0); }
|
2018-08-08 23:56:36 -04:00
|
|
|
~MutexLocker() { if (mutex != INVALID_HANDLE_VALUE && mutex != nullptr) ReleaseMutex(mutex); }
|
2018-07-20 17:36:58 -04:00
|
|
|
};
|
|
|
|
|
2015-04-02 23:29:31 +09:00
|
|
|
// EOF
|