forked from abcdls0905/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathios_lock.h
48 lines (39 loc) · 847 Bytes
/
ios_lock.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
//--------------------------------------------------------------------
// 文件名: ios_lock.h
// 内 容:
// 说 明:
// 创建日期: 2010年12月15日
// 创建人: 陆利民
// 版权所有: 苏州蜗牛电子有限公司
//--------------------------------------------------------------------
#ifndef _SYSTEM_IOS_LOCK_H
#define _SYSTEM_IOS_LOCK_H
#include <pthread.h>
// 共享资源互斥访问锁
class CLockUtil
{
public:
CLockUtil()
{
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&m_Handle, &attr); }
~CLockUtil()
{
pthread_mutex_destroy(&m_Handle);
}
// 锁定
void Lock()
{
pthread_mutex_lock(&m_Handle);
}
// 释放
void Unlock()
{
pthread_mutex_unlock(&m_Handle);
}
private:
pthread_mutex_t m_Handle;
};
#endif // _SYSTEM_IOS_LOCK_H