00001 /*---------------------------------------------------------------------------- 00002 * Copyright (c) <2013-2015>, <Huawei Technologies Co., Ltd> 00003 * All rights reserved. 00004 * Redistribution and use in source and binary forms, with or without modification, 00005 * are permitted provided that the following conditions are met: 00006 * 1. Redistributions of source code must retain the above copyright notice, this list of 00007 * conditions and the following disclaimer. 00008 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 00009 * of conditions and the following disclaimer in the documentation and/or other materials 00010 * provided with the distribution. 00011 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 00012 * to endorse or promote products derived from this software without specific prior written 00013 * permission. 00014 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00015 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 00016 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00017 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00018 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00019 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00020 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 00021 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00022 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 00023 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 00024 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00025 *---------------------------------------------------------------------------*/ 00026 /*---------------------------------------------------------------------------- 00027 * Notice of Export Control Law 00028 * =============================================== 00029 * Huawei LiteOS may be subject to applicable export control laws and regulations, which might 00030 * include those applicable to Huawei LiteOS of U.S. and the country in which you are located. 00031 * Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance with such 00032 * applicable export control laws and regulations. 00033 *---------------------------------------------------------------------------*/ 00034 00035 /** @defgroup los_list Doubly linked list 00036 * @ingroup kernel 00037 */ 00038 00039 #ifndef _LOS_LIST_H 00040 #define _LOS_LIST_H 00041 00042 #include "los_typedef.h" 00043 00044 #ifdef __cplusplus 00045 #if __cplusplus 00046 extern "C" { 00047 #endif /* __cplusplus */ 00048 #endif /* __cplusplus */ 00049 00050 00051 /** 00052 *@ingroup los_list 00053 *Structure of a node in a doubly linked list. 00054 */ 00055 typedef struct LOS_DL_LIST 00056 { 00057 struct LOS_DL_LIST *pstPrev; /**< Current node's pointer to the previous node*/ 00058 struct LOS_DL_LIST *pstNext; /**< Current node's pointer to the next node*/ 00059 } LOS_DL_LIST; 00060 00061 /** 00062 *@ingroup los_list 00063 *@brief Initialize a doubly linked list. 00064 * 00065 *@par Description: 00066 *This API is used to initialize a doubly linked list. 00067 *@attention 00068 *<ul> 00069 *<li>The parameter passed in should be ensured to be a legal pointer.</li> 00070 *</ul> 00071 * 00072 *@param pstList [IN] Node in a doubly linked list. 00073 * 00074 *@retval None. 00075 *@par Dependency: 00076 *<ul><li>los_list.h: the header file that contains the API declaration.</li></ul> 00077 *@see 00078 *@since Huawei LiteOS V100R001C00 00079 */ 00080 LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListInit(LOS_DL_LIST *pstList) 00081 { 00082 pstList->pstNext = pstList; 00083 pstList->pstPrev = pstList; 00084 } 00085 00086 /** 00087 *@ingroup los_list 00088 *@brief Point to the next node pointed to by the current node. 00089 * 00090 *@par Description: 00091 *<ul> 00092 *<li>This API is used to point to the next node pointed to by the current node.</li> 00093 *</ul> 00094 *@attention 00095 *<ul> 00096 *<li>None.</li> 00097 *</ul> 00098 * 00099 *@param pstObject [IN] Node in the doubly linked list. 00100 * 00101 *@retval None. 00102 *@par Dependency: 00103 *<ul><li>los_list.h: the header file that contains the API declaration.</li></ul> 00104 *@see 00105 *@since Huawei LiteOS V100R001C00 00106 */ 00107 #define LOS_DL_LIST_FIRST(pstObject) ((pstObject)->pstNext) 00108 00109 /** 00110 *@ingroup los_list 00111 *@brief Insert a new node to a doubly linked list. 00112 * 00113 *@par Description: 00114 *This API is used to insert a new node to a doubly linked list. 00115 *@attention 00116 *<ul> 00117 *<li>The parameters passed in should be ensured to be legal pointers.</li> 00118 *</ul> 00119 * 00120 *@param pstList [IN] Doubly linked list where the new node is inserted. 00121 *@param pstNode [IN] New node to be inserted. 00122 * 00123 *@retval None 00124 *@par Dependency: 00125 *<ul><li>los_list.h: the header file that contains the API declaration.</li></ul> 00126 *@see LOS_ListDelete 00127 *@since Huawei LiteOS V100R001C00 00128 */ 00129 LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListAdd(LOS_DL_LIST *pstList, LOS_DL_LIST *pstNode) 00130 { 00131 pstNode->pstNext = pstList->pstNext; 00132 pstNode->pstPrev = pstList; 00133 pstList->pstNext->pstPrev = pstNode; 00134 pstList->pstNext = pstNode; 00135 } 00136 00137 /** 00138 *@ingroup los_list 00139 *@brief Insert a node to the tail of a doubly linked list. 00140 * 00141 *@par Description: 00142 *This API is used to insert a new node to the tail of a doubly linked list. 00143 *@attention 00144 *<ul> 00145 *<li>The parameters passed in should be ensured to be legal pointers.</li> 00146 *</ul> 00147 * 00148 *@param pstList [IN] Doubly linked list where the new node is inserted. 00149 *@param pstNode [IN] New node to be inserted. 00150 * 00151 *@retval None. 00152 *@par Dependency: 00153 *<ul><li>los_list.h: the header file that contains the API declaration.</li></ul> 00154 *@see LOS_ListAdd | LOS_ListHeadInsert 00155 *@since Huawei LiteOS V100R001C00 00156 */ 00157 LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListTailInsert(LOS_DL_LIST *pstList, LOS_DL_LIST *pstNode) 00158 { 00159 LOS_ListAdd(pstList->pstPrev, pstNode); 00160 } 00161 00162 /** 00163 *@ingroup los_list 00164 *@brief Delete a specified node from a doubly linked list. 00165 * 00166 *@par Description: 00167 *<ul> 00168 *<li>This API is used to delete a specified node from a doubly linked list.</li> 00169 *</ul> 00170 *@attention 00171 *<ul> 00172 *<li>The parameter passed in should be ensured to be a legal pointer.</li> 00173 *</ul> 00174 * 00175 *@param pstNode [IN] Node to be deleted. 00176 * 00177 *@retval None. 00178 *@par Dependency: 00179 *<ul><li>los_list.h: the header file that contains the API declaration.</li></ul> 00180 *@see LOS_ListAdd 00181 *@since Huawei LiteOS V100R001C00 00182 */ 00183 LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListDelete(LOS_DL_LIST *pstNode) 00184 { 00185 pstNode->pstNext->pstPrev = pstNode->pstPrev; 00186 pstNode->pstPrev->pstNext = pstNode->pstNext; 00187 pstNode->pstNext = (LOS_DL_LIST *)NULL; 00188 pstNode->pstPrev = (LOS_DL_LIST *)NULL; 00189 } 00190 00191 /** 00192 *@ingroup los_list 00193 *@brief Identify whether a specified doubly linked list is empty. 00194 * 00195 *@par Description: 00196 *<ul> 00197 *<li>This API is used to return whether a doubly linked list is empty.</li> 00198 *</ul> 00199 *@attention 00200 *<ul> 00201 *<li>The parameter passed in should be ensured to be a legal pointer.</li> 00202 *</ul> 00203 * 00204 *@param pstList [IN] Doubly linked list. 00205 * 00206 *@retval TRUE The doubly linked list is empty. 00207 *@retval FALSE The doubly linked list is not empty. 00208 *@par Dependency: 00209 *<ul><li>los_list.h: the header file that contains the API declaration.</li></ul> 00210 *@see 00211 *@since Huawei LiteOS V100R001C00 00212 */ 00213 LITE_OS_SEC_ALW_INLINE STATIC_INLINE BOOL LOS_ListEmpty(LOS_DL_LIST *pstNode) 00214 { 00215 return (BOOL)(pstNode->pstNext == pstNode); 00216 } 00217 00218 /** 00219 * @ingroup los_list 00220 * @brief Obtain the offset of a field to a structure address. 00221 * 00222 *@par Description: 00223 *This API is used to obtain the offset of a field to a structure address. 00224 *@attention 00225 *<ul> 00226 *<li>None.</li> 00227 *</ul> 00228 * 00229 *@param type [IN] Structure name. 00230 *@param field [IN] Name of the field of which the offset is to be measured. 00231 * 00232 *@retval Offset of the field to the structure address. 00233 *@par Dependency: 00234 *<ul><li>los_list.h: the header file that contains the API declaration.</li></ul> 00235 *@see 00236 *@since Huawei LiteOS V100R001C00 00237 */ 00238 #define OFFSET_OF_FIELD(type, field) ((UINT32)&(((type *)0)->field)) 00239 00240 /** 00241 *@ingroup los_list 00242 *@brief Obtain the pointer to a doubly linked list in a structure. 00243 * 00244 *@par Description: 00245 *This API is used to obtain the pointer to a doubly linked list in a structure. 00246 *@attention 00247 *<ul> 00248 *<li>None.</li> 00249 *</ul> 00250 * 00251 *@param type [IN] Structure name. 00252 *@param member [IN] Member name of the doubly linked list in the structure. 00253 * 00254 *@retval Pointer to the doubly linked list in the structure. 00255 *@par Dependency: 00256 *<ul><li>los_list.h: the header file that contains the API declaration.</li></ul> 00257 *@see 00258 *@since Huawei LiteOS V100R001C00 00259 */ 00260 #define LOS_OFF_SET_OF(type, member) ((long)&((type *)0)->member) /*lint -e(413) */ 00261 00262 /** 00263 *@ingroup los_list 00264 *@brief Obtain the pointer to a structure that contains a doubly linked list. 00265 * 00266 *@par Description: 00267 *This API is used to obtain the pointer to a structure that contains a doubly linked list. 00268 *<ul> 00269 *<li>None.</li> 00270 *</ul> 00271 *@attention 00272 *<ul> 00273 *<li>None.</li> 00274 *</ul> 00275 * 00276 *@param item [IN] Current node's pointer to the next node. 00277 *@param type [IN] Structure name. 00278 *@param member [IN] Member name of the doubly linked list in the structure. 00279 * 00280 *@retval Pointer to the structure that contains the doubly linked list. 00281 *@par Dependency: 00282 *<ul><li>los_list.h: the header file that contains the API declaration.</li></ul> 00283 *@see 00284 *@since Huawei LiteOS V100R001C00 00285 */ 00286 #define LOS_DL_LIST_ENTRY(item, type, member) \ 00287 ((type *)((char *)item - LOS_OFF_SET_OF(type, member))) \ 00288 00289 /** 00290 *@ingroup los_list 00291 *@brief Iterate over a doubly linked list of given type. 00292 * 00293 *@par Description: 00294 *This API is used to iterate over a doubly linked list of given type. 00295 *@attention 00296 *<ul> 00297 *<li>None.</li> 00298 *</ul> 00299 * 00300 *@param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed. 00301 *@param list [IN] Pointer to the doubly linked list to be traversed. 00302 *@param type [IN] Structure name. 00303 *@param member [IN] Member name of the doubly linked list in the structure. 00304 * 00305 *@retval None. 00306 *@par Dependency: 00307 *<ul><li>los_list.h: the header file that contains the API declaration.</li></ul> 00308 *@see 00309 *@since Huawei LiteOS V100R001C00 00310 */ 00311 #define LOS_DL_LIST_FOR_EACH_ENTRY(item, list, type, member) \ 00312 for (item = LOS_DL_LIST_ENTRY((list)->pstNext, type, member); \ 00313 &item->member != (list); \ 00314 item = LOS_DL_LIST_ENTRY(item->member.pstNext, type, member)) 00315 00316 /** 00317 *@ingroup los_list 00318 *@brief iterate over a doubly linked list safe against removal of list entry. 00319 * 00320 *@par Description: 00321 *This API is used to iterate over a doubly linked list safe against removal of list entry. 00322 *@attention 00323 *<ul> 00324 *<li>None.</li> 00325 *</ul> 00326 * 00327 *@param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed. 00328 *@param next [IN] Save the next node. 00329 *@param list [IN] Pointer to the doubly linked list to be traversed. 00330 *@param type [IN] Structure name. 00331 *@param member [IN] Member name of the doubly linked list in the structure. 00332 * 00333 *@retval None. 00334 *@par Dependency: 00335 *<ul><li>los_list.h: the header file that contains the API declaration.</li></ul> 00336 *@see 00337 *@since Huawei LiteOS V100R001C00 00338 */ 00339 #define LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, next, list, type, member) \ 00340 for (item = LOS_DL_LIST_ENTRY((list)->pstNext, type, member), \ 00341 next = LOS_DL_LIST_ENTRY(item->member.pstNext, type, member); \ 00342 &item->member != (list); \ 00343 item = next, next = LOS_DL_LIST_ENTRY(item->member.pstNext, type, member)) 00344 00345 LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID osListDel(LOS_DL_LIST *pstPrevNode, LOS_DL_LIST *pstNextNode) 00346 { 00347 pstNextNode->pstPrev = pstPrevNode; 00348 pstPrevNode->pstNext = pstNextNode; 00349 } 00350 00351 /** 00352 *@ingroup los_list 00353 *@brief Delete initialize a doubly linked list. 00354 * 00355 *@par Description: 00356 *This API is used to delete initialize a doubly linked list. 00357 *@attention 00358 *<ul> 00359 *<li>The parameter passed in should be ensured to be s legal pointer.</li> 00360 *</ul> 00361 * 00362 *@param pstList [IN] Doubly linked list. 00363 * 00364 *@retval None. 00365 *@par Dependency: 00366 *<ul><li>los_list.h: the header file that contains the API declaration.</li></ul> 00367 *@see 00368 *@since Huawei LiteOS V100R001C00 00369 */ 00370 LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListDelInit(LOS_DL_LIST *pstList) 00371 { 00372 osListDel(pstList->pstPrev, pstList->pstNext); 00373 LOS_ListInit(pstList); 00374 } 00375 00376 /** 00377 *@ingroup los_list 00378 *@brief iterate over a doubly linked list. 00379 * 00380 *@par Description: 00381 *This API is used to iterate over a doubly linked list. 00382 *@attention 00383 *<ul> 00384 *<li>None.</li> 00385 *</ul> 00386 * 00387 *@param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed. 00388 *@param list [IN] Pointer to the doubly linked list to be traversed. 00389 * 00390 *@retval None. 00391 *@par Dependency: 00392 *<ul><li>los_list.h: the header file that contains the API declaration.</li></ul> 00393 *@see 00394 *@since Huawei LiteOS V100R001C00 00395 */ 00396 #define LOS_DL_LIST_FOR_EACH(item, list) \ 00397 for ((item) = (list)->pstNext; \ 00398 (item) != (list); \ 00399 (item) = (item)->pstNext) 00400 00401 /** 00402 *@ingroup los_list 00403 *@brief Iterate over a doubly linked list safe against removal of list entry. 00404 * 00405 *@par Description: 00406 *This API is used to iterate over a doubly linked list safe against removal of list entry. 00407 *@attention 00408 *<ul> 00409 *<li>None.</li> 00410 *</ul> 00411 * 00412 *@param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed. 00413 *@param next [IN] Save the next node. 00414 *@param list [IN] Pointer to the doubly linked list to be traversed. 00415 * 00416 *@retval None. 00417 *@par Dependency: 00418 *<ul><li>los_list.h: the header file that contains the API declaration.</li></ul> 00419 *@see 00420 *@since Huawei LiteOS V100R001C00 00421 */ 00422 #define LOS_DL_LIST_FOR_EACH_SAFE(item, next, list) \ 00423 for (item = (list)->pstNext, next = item->pstNext; item != (list); \ 00424 item = next, next = item->pstNext) 00425 00426 /** 00427 *@ingroup los_list 00428 *@brief Initialize a double linked list. 00429 * 00430 *@par Description: 00431 *This API is used to initialize a double linked list. 00432 *@attention 00433 *<ul> 00434 *<li>None.</li> 00435 *</ul> 00436 * 00437 *@param list [IN] Pointer to the doubly linked list to be traversed. 00438 * 00439 *@retval None. 00440 *@par Dependency: 00441 *<ul><li>los_list.h: the header file that contains the API declaration.</li></ul> 00442 *@see 00443 *@since Huawei LiteOS V100R001C00 00444 */ 00445 #define LOS_DL_LIST_HEAD(list) \ 00446 LOS_DL_LIST list = { &(list), &(list) } 00447 00448 00449 #ifdef __cplusplus 00450 #if __cplusplus 00451 } 00452 #endif /* __cplusplus */ 00453 #endif /* __cplusplus */ 00454 00455 #endif /* _LOS_LIST_H */