-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCritSec.cpp
More file actions
70 lines (58 loc) · 1.6 KB
/
CritSec.cpp
File metadata and controls
70 lines (58 loc) · 1.6 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "Base.h"
#include "CritSec.h"
NS_BEGIN
/////////////////////////////////////////////////
// CCritSec
/////////////////////////////////////////////////
//#################################################################################################
CCritSec::CCritSec(void)
{
InitializeCriticalSectionEx(&m_cs, 0, 0);
}
//#################################################################################################
CCritSec::~CCritSec(void)
{
DeleteCriticalSection(&m_cs);
}
/////////////////////////////////////////////////
// CCritSecMgr
/////////////////////////////////////////////////
//#################################################################################################
CCritSecMgr::CCritSecMgr(CCritSec &cs, const bool bLock)
: m_cs(cs),
m_bLocked(false)
{
if(bLock)
Lock();
}
//#################################################################################################
CCritSecMgr::~CCritSecMgr(void)
{
Unlock();
}
//#################################################################################################
void CCritSecMgr::Lock(void)
{
if(!m_bLocked)
{
m_cs.Lock();
m_bLocked = true;
}
}
//#################################################################################################
bool CCritSecMgr::TryLock(void)
{
if(!m_bLocked)
m_bLocked = m_cs.TryLock();
return m_bLocked;
}
//#################################################################################################
void CCritSecMgr::Unlock(void)
{
if(m_bLocked)
{
m_cs.Unlock();
m_bLocked = false;
}
}
NS_END