-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththread.h
54 lines (48 loc) · 1.61 KB
/
thread.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
//////////////////////////////////////////////////////////////////////////
/// COPYRIGHT NOTICE
/// Copyright (c) 2010, 浙江共创技术有限公司
/// All rights reserved.
///
/// @file thread.h
/// @brief 线程库函数头文件
///
///
///
/// @version 2.0
/// @author xuliang<[email protected]>
/// @date 2010-04-24
///
///
/// 修订说明:最初版本
//////////////////////////////////////////////////////////////////////////
#ifndef _TRD_H_
#define _TRD_H_
#include <pthread.h>
#include <semaphore.h>
#include "include.h"
typedef pthread_t TRD_t;
typedef sem_t SEM_t;
typedef pthread_mutex_t LOCK_t;
// for thread safe
#define TS_LOCK(lock) pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock, (void*)lock ); pthread_mutex_lock( lock )
#define TS_UNLOCK(lock) pthread_cleanup_pop( 1 )
//////////////////////////////////////////////////////////////////////////
///
/// 创建并分离线程
/// @param trd_id
/// @param *func 目标线程
/// @param *arg 函数参数
/// @return 0-成功<0 失败
/// @author xuliang<[email protected]>
/// @date 2010-04-24
//////////////////////////////////////////////////////////////////////////
extern int trd_create(TRD_t *trd_id, void *(*func)(void *), void *arg);
//////////////////////////////////////////////////////////////////////////
///
/// 互斥量初始化
/// @param *lock
/// @author xuliang<[email protected]>
/// @date 2010-04-24
//////////////////////////////////////////////////////////////////////////
//inline void trd_lock_init(LOCK_t *lock);
#endif