O-CU-UP
[scp/ocu/5gnr.git] / Include / vos_sem.h
1 /******************************************************************************
2 ###############################################################################
3 #   Copyright (c) [2017-2020] [ICT/CAS]                                        #
4 #   Licensed under the ORAN Software License v1.0 (License)             #
5 ###############################################################################
6 ******************************************************************************/
7
8
9
10
11 #ifndef __VOS_SEM_H__
12 #define __VOS_SEM_H__
13
14 #ifdef    __cplusplus
15 extern "C"
16 {
17 #endif /* __cplusplus */
18
19 /** 阻塞  */
20 #define VOS_WAIT_FOREVER   -1
21
22 /** 非阻塞  */
23 #define VOS_WAIT_NO_WAIT    0
24
25
26 /** 信号量状态 */
27 typedef enum
28 {
29     VOS_SEM_EMPTY,                      ///<  0: semaphore not available
30     VOS_SEM_FULL                        ///<  1: semaphore available
31 }VOS_SEM_B_STATE;
32
33 /** 信号量选项,linux 中无效,使用 VOS_SEM_Q_FIFO */
34 typedef enum{
35     VOS_SEM_Q_FIFO           = 0x0,     ///< first in first out queue
36     VOS_SEM_Q_PRIORITY       = 0x1,     ///< priority sorted queue
37     VOS_SEM_DELETE_SAFE      = 0x4,     ///< owner delete safe (mutex opt.)
38     VOS_SEM_INVERSION_SAFE   = 0x8,     ///< no priority inversion (mutex opt.)
39 }VOS_sem_option_t;
40
41
42 /** 
43  * 创建Bianary类型的信号量,linux中 与Count类型 一致
44  * @param[in]   lOption             信号量选项,linux 中无效,使用 VOS_SEM_Q_FIFO
45  * @param[in]   enInitialState      初始化状态,VOS_SEM_B_STATE 类型的枚举值
46  * @return      返回SEM_ID,失败则返回 0
47  */ 
48 #define VOS_SemBCreate(lOption, enInitialState)     __VOS_SemBCreate(lOption, enInitialState, __FUNCTION__, __LINE__)
49
50
51 /** 
52  * 创建Count类型的信号量
53  * @param[in]   lOption             信号量选项,linux 中无效,使用 VOS_SEM_Q_FIFO
54  * @param[in]   enInitialState      初始化状态,VOS_SEM_B_STATE 类型的枚举值
55  * @return      返回SEM_ID,失败则返回 0
56  */ 
57 #define VOS_SemCCreate(lOption, enInitialState)     __VOS_SemCCreate(lOption, enInitialState, __FUNCTION__, __LINE__)
58
59
60 /** 
61  * 创建互斥锁
62  * @param[in]   lOption             信号量选项,linux 中无效,使用 VOS_SEM_Q_FIFO
63  * @return      返回SEM_ID,失败则返回 0
64  */ 
65 #define VOS_SemMCreate(lOption)                            __VOS_SemMCreate(lOption, __FUNCTION__, __LINE__)
66
67
68 /** 
69  * 获取信号量
70  * @param[in]   semID      信号量ID
71  * @param[in]   lMsec      超时等待的时间,单位毫秒,也可以为VOS_WAIT_FOREVER或VOS_NO_WAIT
72  * @return      VOS_OK - 成功,其他 - 失败/超时
73  */ 
74 LONG VOS_SemTake(ULONG semID, LONG lMsec);
75
76
77 /** 
78  * 释放信号量
79  * @param[in]   semID      信号量ID
80  * @return      VOS_OK - 成功,其他 - 失败
81  */ 
82 LONG VOS_SemGive(ULONG semID);
83
84
85 /** 
86  * 删除信号量
87  * @param[in]   semID      信号量ID
88  * @return      VOS_OK - 成功,其他 - 失败
89  */ 
90 LONG VOS_SemDelete(ULONG semID);
91
92
93
94
95
96
97 /* ###### 下面的函数不要直接调用,使用上面提供的宏 ###### */
98
99
100 /** 
101  * 不要直接调用该API,通过宏 VOS_SemBCreate 使用
102  * 创建Bianary类型的信号量,linux中 与Count类型 一致
103  * @param[in]   lOption             信号量选项,linux 中无效,使用 VOS_SEM_Q_FIFO
104  * @param[in]   enInitialState      初始化状态,VOS_SEM_B_STATE 类型
105  * @param[in]   pFunc               调用该API的文件名
106  * @param[in]   iLine               调用该API的行号
107  * @return      返回SEM_ID,失败则返回 0
108  */ 
109 ULONG __VOS_SemBCreate(LONG lOption, VOS_SEM_B_STATE enInitialState,const CHAR *pFunc, INT iLine);
110
111
112 /** 
113  * 不要直接调用该API,通过宏 VOS_SemCCreate 使用
114  * 创建Count类型的信号量,linux中 与Count类型 一致
115  * @param[in]   lOption             信号量选项,linux 中无效,使用 VOS_SEM_Q_FIFO
116  * @param[in]   lInitialCount       初始值
117  * @param[in]   pFunc               调用该API的文件名
118  * @param[in]   iLine               调用该API的行号
119  * @return      返回SEM_ID,失败则返回 0
120  */ 
121 ULONG  __VOS_SemCCreate(LONG lOption, LONG lInitialCount,const CHAR *pFunc, INT iLine);
122
123
124 /** 
125  * 不要直接调用该API,通过宏 VOS_SemMCreate 使用
126  * 创建互斥锁
127  * @param[in]   lOption             信号量选项,linux 中无效,使用 VOS_SEM_Q_FIFO
128  * @param[in]   pFunc               调用该API的文件名
129  * @param[in]   iLine               调用该API的行号
130  * @return      返回SEM_ID,失败则返回 0
131  */ 
132 ULONG  __VOS_SemMCreate(LONG lOption,const CHAR *pFunc, INT iLine);
133
134 #ifdef __cplusplus
135 }
136 #endif /* __cplusplus */
137
138
139 #endif /* __VOS_SEM_H__ */