-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTLock.h
81 lines (66 loc) · 1.07 KB
/
TLock.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef __T_LOCK_H__
#define __T_LOCK_H__
#ifndef WIN32
#include <pthread.h>
#endif
class TLock
{
//protected:
pthread_mutex_t m_pCS;
protected:
#ifdef WIN32
CRITICAL_SECTION* m_pCS;
else
#endif
public:
TLock(void)
{
#ifdef WIN32
m_pCS = new CRITICAL_SECTION();
InitializeCriticalSection(m_pCS);
#else
pthread_mutex_init(&m_pCS, NULL);
#endif
};
virtual ~TLock(void)
{
#ifdef WIN32
DeleteCriticalSection(m_pCS);
delete m_pCS;
#else
pthread_mutex_destroy(&m_pCS);
#endif
};
virtual void Lock(void)
{
#ifdef WIN32
EnterCriticalSection(m_pCS);
#else
pthread_mutex_lock(&m_pCS);
#endif
};
virtual void UnLock(void)
{
#ifdef WIN32
LeaveCriticalSection(m_pCS);
#else
pthread_mutex_unlock(&m_pCS);
#endif
};
};
class ATLock
{
public:
ATLock(TLock* pTLock)
{
m_pTLock = pTLock;
m_pTLock->Lock();
};
virtual ~ATLock()
{
m_pTLock->UnLock();
};
protected:
TLock* m_pTLock;
};
#endif //__T_LOCK_H__