-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCritSec.h
More file actions
47 lines (36 loc) · 1.15 KB
/
CritSec.h
File metadata and controls
47 lines (36 loc) · 1.15 KB
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
#pragma once
NS_BEGIN
//#################################################################################################
class CCritSec final
{
public:
CCritSec(void);
CCritSec(const CCritSec &src) = delete;
CCritSec(CCritSec &&src) = delete;
~CCritSec(void);
CCritSec &operator=(const CCritSec &src) = delete;
CCritSec &operator=(CCritSec &&src) = delete;
inline void Lock(void) {EnterCriticalSection(&m_cs);}
inline bool TryLock(void) {return (TryEnterCriticalSection(&m_cs) != FALSE);}
inline void Unlock(void) {LeaveCriticalSection(&m_cs);}
private:
CRITICAL_SECTION m_cs;
};
//#################################################################################################
class CCritSecMgr final
{
public:
explicit CCritSecMgr(CCritSec &cs, const bool bLock = true);
CCritSecMgr(const CCritSecMgr &src) = delete;
CCritSecMgr(CCritSecMgr &&src) = delete;
~CCritSecMgr(void);
CCritSecMgr &operator=(const CCritSecMgr &src) = delete;
CCritSecMgr &operator=(CCritSecMgr &&src) = delete;
void Lock(void);
bool TryLock(void);
void Unlock(void);
private:
CCritSec &m_cs;
bool m_bLocked;
};
NS_END