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