• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *   Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description: OS Abstract Layer.
15  */
16 
17 /**
18  * @defgroup osal_wait osal_wait
19  */
20 #ifndef __OSAL_WAIT_H__
21 #define __OSAL_WAIT_H__
22 
23 #ifdef __cplusplus
24 #if __cplusplus
25 extern "C" {
26 #endif
27 #endif
28 
29 #define OSAL_WAIT_FOREVER 0xFFFFFFFF
30 #define OSAL_WAIT_CONDITION_TRUE 1
31 
32 typedef struct {
33     void *wait;
34 } osal_wait;
35 
36 /* return value is a bool type */
37 typedef int (*osal_wait_condition_func)(const void *param);
38 
39 /**
40  * @ingroup osal_wait
41  * @brief Initialize a waiting queue.
42  *
43  * @par Description:
44  * This API is used to Initialize a waiting queue.
45  *
46  * @param wait [out] The wait queue to be initialized.
47  *
48  * @par Support System:
49  * linux liteos freertos.
50  */
51 int osal_wait_init(osal_wait *wait);
52 
53 /**
54  * @ingroup osal_wait
55  * @brief sleep until a condition gets true
56  *
57  * @par Description:
58  * sleep until a condition gets true.
59  * The process is put to sleep (TASK_INTERRUPTIBLE) until the func returned true or a signal is received.
60  * Return value of the func is checked each time the waitqueue wait is woken up.
61  *
62  * @attention
63  * wake_up() has to be called after changing any variable that could change the result of the wait condition.
64  * it is the same as osal_wait_uninterruptible on LiteOS.
65  * LiteOS does not support this interface, so it is the same as osal_wait_uninterruptible on LiteOS.
66  *
67  * @param wait  [in] The waitqueue to wait on.
68  * @param func  [in] Then function to be run.
69  * @param param [in] Param of the function to be run.
70  *
71  * @return OSAL_SUCCESS/OSAL_FAILURE.
72  * In linux, The function will return -ERESTARTSYS if it was interrupted by a signal. liteos
73  *
74  * @par Support System:
75  * linux liteos.
76  */
77 int osal_wait_interruptible(osal_wait *wait, osal_wait_condition_func func, const void *param);
78 
79 /**
80  * @ingroup osal_wait
81  * @brief sleep until a condition gets true
82  *
83  * @par Description:
84  * sleep until a condition gets true.
85  * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the func returned true.
86  * Return value of the func is checked each time the waitqueue wait is woken up.
87  *
88  * @attention
89  * wake_up() has to be called after changing any variable that could change the result of the wait condition.
90  *
91  * @return OSAL_SUCCESS/OSAL_FAILURE
92  *
93  * @par Support System:
94  * linux liteos freetos.
95  */
96 int osal_wait_uninterruptible(osal_wait *wait, osal_wait_condition_func func, const void *param);
97 
98 /**
99  * @ingroup osal_wait
100  * @brief sleep until a condition gets true or a timeout elapses.
101  *
102  * @par Description:
103  * sleep until a condition gets true or a timeout elapses.
104  * The process is put to sleep (TASK_INTERRUPTIBLE) until the func returned true or a signal is received.
105  * Return value of the func is checked each time the waitqueue wait is woken up.
106  *
107  * @param wait [in] the waitqueue to wait on.
108  * @param func [in] a C expression for the event to wait for.
109  * @param param [in] Param of the function to be run.
110  * @param ms [in] timeout, in ms.
111  *
112  * @par Support System:
113  * linux liteos freertos.
114  */
115 int osal_wait_timeout_interruptible(osal_wait *wait, osal_wait_condition_func func, const void *param,
116     unsigned long ms);
117 
118 /**
119  * @ingroup osal_wait
120  * @brief sleep until a condition gets true or a timeout elapses.
121  *
122  * @par Description:
123  * sleep until a condition gets true or a timeout elapses.
124  * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the func returned true.
125  * Return value of the func is checked each time the waitqueue wait is woken up.
126  *
127  * @param wait [in] The waitqueue to wait on.
128  * @param func [in] A C expression for the event to wait for.
129  * @param param [in] Param of the function to be run.
130  * @param ms [in] Timeout, in ms.
131  *
132  * @par Support System:
133  * linux liteos.
134  */
135 int osal_wait_timeout_uninterruptible(osal_wait *wait, osal_wait_condition_func func, const void *param,
136     unsigned long ms);
137 
138 /**
139  * @ingroup osal_wait
140  * @brief wake up threads blocked on a waitqueue.
141  *
142  * @par Description:
143  * Wake-up wait queue,pair to wait_event.
144  *
145  * @param wait [in] The wait to be wake up.
146  *
147  * @par Support System:
148  * linux liteos freertos.
149  */
150 void osal_wait_wakeup(osal_wait *wait); // same as wake_up_all
151 
152 /**
153  * @ingroup osal_wait
154  * @brief wake up threads blocked on a waitqueue.
155  *
156  * @par Description:
157  * Wake-up wait queue,pair to wait_event_interruptible.
158  *
159  * @param wait [in] The wait to be wake up.
160  *
161  * @par Support System:
162  * linux liteos.
163  */
164 void osal_wait_wakeup_interruptible(osal_wait *wait); // same as osal_wait_wakeup on liteos
165 
166 /**
167  * @ingroup osal_wait
168  * @brief to destroy the wait.
169  *
170  * @par Description:
171  * This API is used to destroy the wait.
172  *
173  * @param wait [in] The wait to be destroyed.
174  *
175  * @attention this api may free memory, wait should be from osal_complete_init.
176  * @par Support System:
177  * linux liteos freertos.
178  */
179 void osal_wait_destroy(osal_wait *wait);
180 
181 #ifdef __cplusplus
182 #if __cplusplus
183 }
184 #endif
185 #endif
186 #endif /* __OSAL_WAIT_H__ */