-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnamed_mutex.h
54 lines (44 loc) · 1.02 KB
/
named_mutex.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* THOR - THOR Template Library
* Joshua M. Kriegshauser
*
* mutex.h
*
* Defines a platform-agnostic mutex class. This mutex can be given a system-wide
* name to synchronize between multiple processes.
*/
#ifndef THOR_NAMED_MUTEX_H
#define THOR_NAMED_MUTEX_H
#pragma once
#ifndef THOR_BASETYPES_H
#include "basetypes.h"
#endif
#if defined(THOR_DEBUG) && !defined(THOR_BASIC_STRING_H)
#include "basic_string.h"
#endif
#if defined(_WIN32)
#include "win/named_mutex_win.inl"
#else
#error Unsupported platform!
#endif
namespace thor
{
class named_mutex : public internal::named_mutex_base
{
THOR_DECLARE_NOCOPY(named_mutex);
public:
explicit named_mutex(const char* name);
explicit named_mutex(const wchar_t* name);
~named_mutex();
bool lock(size_type timeout_ms = size_type(-1));
bool try_lock();
bool unlock();
private:
#ifdef THOR_DEBUG
thor::wstring debug_name_;
void set_debug_name(const wchar_t* name) { debug_name_ = name; }
#else
void set_debug_name(const wchar_t*) {}
#endif
};
}
#endif