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