forked from awwit/httpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobalMutex.h
More file actions
45 lines (35 loc) · 709 Bytes
/
GlobalMutex.h
File metadata and controls
45 lines (35 loc) · 709 Bytes
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
#pragma once
#ifdef WIN32
#include <wtypes.h>
#include <WinDef.h>
#elif POSIX
#include <semaphore.h>
#endif
#include <string>
namespace System
{
class GlobalMutex
{
private:
#ifdef WIN32
::HANDLE mtx_desc;
#elif POSIX
::sem_t *mtx_desc;
#else
#error "Undefined platform"
#endif
std::string mtx_name;
public:
GlobalMutex() noexcept;
~GlobalMutex() noexcept;
bool create(const std::string &mutexName);
bool destory();
static bool destory(const std::string &mutexName);
bool open(const std::string &mutexName);
bool close() noexcept;
bool is_open() const noexcept;
bool lock() const noexcept;
bool try_lock() const noexcept;
bool unlock() const noexcept;
};
}