2014-11-10 01:48:16 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#if !defined(__cplusplus) && !defined(inline)
|
|
|
|
#define inline __inline
|
|
|
|
#endif
|
|
|
|
|
2016-10-31 01:41:01 -07:00
|
|
|
#define GC_EVENT_FLAGS (EVENT_MODIFY_STATE | SYNCHRONIZE)
|
|
|
|
#define GC_MUTEX_FLAGS (SYNCHRONIZE)
|
|
|
|
|
2016-11-01 02:34:17 -07:00
|
|
|
static inline HANDLE create_event(const wchar_t *name)
|
2014-11-10 01:48:16 -08:00
|
|
|
{
|
2016-11-01 02:34:17 -07:00
|
|
|
return CreateEventW(NULL, false, false, name);
|
2016-11-01 00:21:42 -07:00
|
|
|
}
|
2014-11-10 01:48:16 -08:00
|
|
|
|
2016-11-01 02:34:17 -07:00
|
|
|
static inline HANDLE open_event(const wchar_t *name)
|
2016-11-01 00:21:42 -07:00
|
|
|
{
|
2016-11-01 02:34:17 -07:00
|
|
|
return OpenEventW(GC_EVENT_FLAGS, false, name);
|
2014-11-10 01:48:16 -08:00
|
|
|
}
|
|
|
|
|
2016-11-01 02:34:17 -07:00
|
|
|
static inline HANDLE create_mutex(const wchar_t *name)
|
2014-11-10 01:48:16 -08:00
|
|
|
{
|
2016-11-01 02:34:17 -07:00
|
|
|
return CreateMutexW(NULL, false, name);
|
2016-11-01 00:21:42 -07:00
|
|
|
}
|
|
|
|
|
2016-11-01 02:34:17 -07:00
|
|
|
static inline HANDLE open_mutex(const wchar_t *name)
|
2016-11-01 00:21:42 -07:00
|
|
|
{
|
2016-11-01 02:34:17 -07:00
|
|
|
return OpenMutexW(GC_MUTEX_FLAGS, false, name);
|
2016-11-01 00:21:42 -07:00
|
|
|
}
|
2014-11-10 01:48:16 -08:00
|
|
|
|
2016-11-01 02:34:17 -07:00
|
|
|
static inline HANDLE create_event_plus_id(const wchar_t *name, DWORD id)
|
2016-11-01 00:21:42 -07:00
|
|
|
{
|
2016-11-01 02:34:17 -07:00
|
|
|
wchar_t new_name[64];
|
|
|
|
_snwprintf(new_name, 64, L"%s%lu", name, id);
|
2016-11-01 00:21:42 -07:00
|
|
|
return create_event(new_name);
|
|
|
|
}
|
|
|
|
|
2016-11-01 02:34:17 -07:00
|
|
|
static inline HANDLE create_mutex_plus_id(const wchar_t *name, DWORD id)
|
2014-11-10 01:48:16 -08:00
|
|
|
{
|
2016-11-01 02:34:17 -07:00
|
|
|
wchar_t new_name[64];
|
|
|
|
_snwprintf(new_name, 64, L"%s%lu", name, id);
|
2016-11-01 00:21:42 -07:00
|
|
|
return create_mutex(new_name);
|
2014-11-10 01:48:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool object_signalled(HANDLE event)
|
|
|
|
{
|
|
|
|
if (!event)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return WaitForSingleObject(event, 0) == WAIT_OBJECT_0;
|
|
|
|
}
|
|
|
|
|