更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_list.h
浏览该文件的文档.
1/*!
2 * @file los_list.h
3 * @brief 双向链表由内联函数实现
4 * @link dll http://weharmonyos.com/openharmony/zh-cn/device-dev/kernel/kernel-small-apx-dll.html @endlink
5 @verbatim
6 基本概念
7 双向链表是指含有往前和往后两个方向的链表,即每个结点中除存放下一个节点指针外,
8 还增加一个指向前一个节点的指针。其头指针head是唯一确定的。
9
10 从双向链表中的任意一个结点开始,都可以很方便地访问它的前驱结点和后继结点,这种
11 数据结构形式使得双向链表在查找时更加方便,特别是大量数据的遍历。由于双向链表
12 具有对称性,能方便地完成各种插入、删除等操作,但需要注意前后方向的操作。
13
14 双向链表的典型开发流程:
15 调用LOS_ListInit/LOS_DL_LIST_HEAD初始双向链表。
16 调用LOS_ListAdd/LOS_ListHeadInsert向链表头部插入节点。
17 调用LOS_ListTailInsert向链表尾部插入节点。
18 调用LOS_ListDelete删除指定节点。
19 调用LOS_ListEmpty判断链表是否为空。
20 调用LOS_ListDelInit删除指定节点并以此节点初始化链表。
21
22 注意事项
23 需要注意节点指针前后方向的操作。
24 链表操作接口,为底层接口,不对入参进行判空,需要使用者确保传参合法。
25 如果链表节点的内存是动态申请的,删除节点时,要注意释放内存。
26 @endverbatim
27 * @version
28 * @author weharmonyos.com | 鸿蒙研究站 | 每天死磕一点点
29 * @date 2021-12-7
30 */
31/*
32 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
33 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
34 *
35 * Redistribution and use in source and binary forms, with or without modification,
36 * are permitted provided that the following conditions are met:
37 *
38 * 1. Redistributions of source code must retain the above copyright notice, this list of
39 * conditions and the following disclaimer.
40 *
41 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
42 * of conditions and the following disclaimer in the documentation and/or other materials
43 * provided with the distribution.
44 *
45 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
46 * to endorse or promote products derived from this software without specific prior written
47 * permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
50 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
51 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
52 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
53 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
54 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
55 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
56 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
57 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
58 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
59 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 */
61
62/**
63 * @defgroup los_list Doubly linked list
64 * @ingroup kernel
65 */
66
67#ifndef _LOS_LIST_H
68#define _LOS_LIST_H
69
70#include "los_typedef.h"
71
72#ifdef __cplusplus
73#if __cplusplus
74extern "C" {
75#endif /* __cplusplus */
76#endif /* __cplusplus */
77
78/**
79 * @ingroup los_list
80 * Structure of a node in a doubly linked list. | 双向链表,内核最重要结构体
81 */
82typedef struct LOS_DL_LIST {
83 struct LOS_DL_LIST *pstPrev; /**< Current node's pointer to the previous node | 前驱节点(左手)*/
84 struct LOS_DL_LIST *pstNext; /**< Current node's pointer to the next node | 后继节点(右手)*/
86
87/**
88 * @ingroup los_list
89 *
90 * @par Description:
91 * This API is used to initialize a doubly linked list. | 将指定节点初始化为双向链表节点
92 * @attention
93 * <ul>
94 * <li>The parameter passed in should be ensured to be a legal pointer.</li>
95 * </ul>
96 *
97 * @param list [IN] Node in a doubly linked list.
98 *
99 * @retval None.
100 * @par Dependency:
101 * <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
102 * @see
103 */
104LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
105{
106 list->pstNext = list;
107 list->pstPrev = list;
108}
109
110/**
111 * @ingroup los_list
112 * @brief Point to the next node pointed to by the current node.
113 *
114 * @par Description:
115 * <ul>
116 * <li>This API is used to point to the next node pointed to by the current node. | 获取指定节点的后继结点</li>
117 * </ul>
118 * @attention
119 * <ul>
120 * <li>None.</li>
121 * </ul>
122 *
123 * @param object [IN] Node in the doubly linked list.
124 *
125 * @retval None.
126 * @par Dependency:
127 * <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
128 * @see
129 */
130#define LOS_DL_LIST_FIRST(object) ((object)->pstNext)
131
132/**
133 * @ingroup los_list
134 * @brief Node is the end of the list.
135 *
136 * @par Description:
137 * <ul>
138 * <li>This API is used to test node is the end of the list.</li>
139 * </ul>
140 * @attention
141 * <ul>
142 * <li>None.</li>
143 * </ul>
144 *
145 * @param object [IN] Node in the doubly linked list.
146 *
147 * @retval None.
148 * @par Dependency:
149 * <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
150 * @see
151 *///判断指定链表节点是否为链表尾端
152#define LOS_DL_LIST_IS_END(list, node) ((list) == (node) ? TRUE : FALSE)
153
154/**
155 * @ingroup los_list
156 * @brief Node is on the list.
157 *
158 * @par Description:
159 * <ul>
160 * <li>This API is used to test node is on the list.</li>
161 * </ul>
162 * @attention
163 * <ul>
164 * <li>None.</li>
165 * </ul>
166 *
167 * @param object [IN] Node in the doubly linked list.
168 *
169 * @retval None.
170 * @par Dependency:
171 * <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
172 * @see
173 *///判断链表节点是否在双向链表里
174#define LOS_DL_LIST_IS_ON_QUEUE(node) ((node)->pstPrev != NULL && (node)->pstNext != NULL)
175
176/**
177 * @ingroup los_list
178 * @brief Point to the previous node pointed to by the current node.
179 *
180 * @par Description:
181 * <ul>
182 * <li>This API is used to point to the previous node pointed to by the current node. | 获取指定节点的前驱结点</li>
183 * </ul>
184 * @attention
185 * <ul>
186 * <li>None.</li>
187 * </ul>
188 *
189 * @param object [IN] Node in the doubly linked list.
190 *
191 * @retval None.
192 * @par Dependency:
193 * <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
194 * @see
195 */
196#define LOS_DL_LIST_LAST(object) ((object)->pstPrev)
197
198/**
199 * @ingroup los_list
200 * @brief Insert a new node to a doubly linked list.
201 *
202 * @par Description:
203 * This API is used to insert a new node to a doubly linked list. | 将指定节点插入到双向链表头端
204 * @attention
205 * <ul>
206 * <li>The parameters passed in should be ensured to be legal pointers.</li>
207 * </ul>
208 *
209 * @param list [IN] Doubly linked list where the new node is inserted.
210 * @param node [IN] New node to be inserted.
211 *
212 * @retval None
213 * @par Dependency:
214 * <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
215 * @see LOS_ListDelete
216 */
217LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListAdd(LOS_DL_LIST *list, LOS_DL_LIST *node)
218{
219 node->pstNext = list->pstNext;
220 node->pstPrev = list;
221 list->pstNext->pstPrev = node;
222 list->pstNext = node;
223}
224
225/**
226 * @ingroup los_list
227 * @brief Insert a node to the tail of a doubly linked list.
228 *
229 * @par Description:
230 * This API is used to insert a new node to the tail of a doubly linked list. | 将指定节点插入到双向链表尾端
231 * @attention
232 * <ul>
233 * <li>The parameters passed in should be ensured to be legal pointers.</li>
234 * </ul>
235 *
236 * @param list [IN] Doubly linked list where the new node is inserted.
237 * @param node [IN] New node to be inserted.
238 *
239 * @retval None.
240 * @par Dependency:
241 * <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
242 * @see LOS_ListAdd | LOS_ListHeadInsert
243 */
244LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListTailInsert(LOS_DL_LIST *list, LOS_DL_LIST *node)
245{
246 LOS_ListAdd(list->pstPrev, node);
247}
248
249/**
250 * @ingroup los_list
251 * @brief Insert a node to the head of a doubly linked list.
252 *
253 * @par Description:
254 * This API is used to insert a new node to the head of a doubly linked list. | 将指定节点插入到双向链表头端
255 * @attention
256 * <ul>
257 * <li>The parameters passed in should be ensured to be legal pointers.</li>
258 * </ul>
259 *
260 * @param list [IN] Doubly linked list where the new node is inserted.
261 * @param node [IN] New node to be inserted.
262 *
263 * @retval None.
264 * @par Dependency:
265 * <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
266 * @see LOS_ListAdd | LOS_ListTailInsert
267 */
268LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListHeadInsert(LOS_DL_LIST *list, LOS_DL_LIST *node)
269{
270 LOS_ListAdd(list, node);
271}
272
273/**
274 * @ingroup los_list
275 *
276 * @par Description:
277 * <ul>
278 * <li>This API is used to delete a specified node from a doubly linked list. | 将指定节点从链表中删除</li>
279 * </ul>
280 * @attention
281 * <ul>
282 * <li>The parameter passed in should be ensured to be a legal pointer.</li>
283 * </ul>
284 *
285 * @param node [IN] Node to be deleted.
286 *
287 * @retval None.
288 * @par Dependency:
289 * <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
290 * @see LOS_ListAdd
291 *///将指定节点从链表中删除
292LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListDelete(LOS_DL_LIST *node)
293{
294 node->pstNext->pstPrev = node->pstPrev;
295 node->pstPrev->pstNext = node->pstNext;
296 node->pstNext = NULL;
297 node->pstPrev = NULL;
298}
299
300/**
301 * @ingroup los_list
302 * @brief Identify whether a specified doubly linked list is empty. | 判断链表是否为空
303 *
304 * @par Description:
305 * <ul>
306 * <li>This API is used to return whether a doubly linked list is empty.</li>
307 * </ul>
308 * @attention
309 * <ul>
310 * <li>The parameter passed in should be ensured to be a legal pointer.</li>
311 * </ul>
312 *
313 * @param list [IN] Doubly linked list.
314 *
315 * @retval TRUE The doubly linked list is empty.
316 * @retval FALSE The doubly linked list is not empty.
317 * @par Dependency:
318 * <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
319 * @see
320 *///判断链表是否为空
321LITE_OS_SEC_ALW_INLINE STATIC INLINE BOOL LOS_ListEmpty(LOS_DL_LIST *list)
322{
323 return (BOOL)(list->pstNext == list);
324}
325
326/**
327 * @ingroup los_list
328 * @brief Insert a new list to a doubly linked list.
329 *
330 * @par Description:
331 * This API is used to insert a new list to a doubly linked list.
332 * @attention
333 * <ul>
334 * <li>The parameters passed in should be ensured to be legal pointers.</li>
335 * </ul>
336 *
337 * @param oldList [IN] Doubly linked list where the new list is inserted.
338 * @param newList [IN] New list to be inserted.
339 *
340 * @retval None
341 * @par Dependency:
342 * <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
343 * @see LOS_ListDelete
344 *///将指定链表的头端插入到双向链表头端
345LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListAddList(LOS_DL_LIST *oldList, LOS_DL_LIST *newList)
346{
347 LOS_DL_LIST *oldListHead = oldList->pstNext;
348 LOS_DL_LIST *oldListTail = oldList;
349 LOS_DL_LIST *newListHead = newList;
350 LOS_DL_LIST *newListTail = newList->pstPrev;
351
352 oldListTail->pstNext = newListHead;
353 newListHead->pstPrev = oldListTail;
354 oldListHead->pstPrev = newListTail;
355 newListTail->pstNext = oldListHead;
356}
357
358/**
359 * @ingroup los_list
360 * @brief Insert a doubly list to the tail of a doubly linked list.
361 *
362 * @par Description:
363 * This API is used to insert a new doubly list to the tail of a doubly linked list.
364 * @attention
365 * <ul>
366 * <li>The parameters passed in should be ensured to be legal pointers.</li>
367 * </ul>
368 *
369 * @param oldList [IN] Doubly linked list where the new list is inserted.
370 * @param newList [IN] New list to be inserted.
371 *
372 * @retval None.
373 * @par Dependency:
374 * <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
375 * @see LOS_ListAddList | LOS_ListHeadInsertList
376 */
377LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListTailInsertList(LOS_DL_LIST *oldList, LOS_DL_LIST *newList)
378{
379 LOS_ListAddList(oldList->pstPrev, newList);
380}
381
382/**
383 * @ingroup los_list
384 * @brief Insert a doubly list to the head of a doubly linked list.
385 *
386 * @par Description:
387 * This API is used to insert a new doubly list to the head of a doubly linked list.
388 * @attention
389 * <ul>
390 * <li>The parameters passed in should be ensured to be legal pointers.</li>
391 * </ul>
392 *
393 * @param oldList [IN] Doubly linked list where the new list is inserted.
394 * @param newList [IN] New list to be inserted.
395 *
396 * @retval None.
397 * @par Dependency:
398 * <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
399 * @see LOS_ListAddList | LOS_ListTailInsertList
400 */
401LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListHeadInsertList(LOS_DL_LIST *oldList, LOS_DL_LIST *newList)
402{
403 LOS_ListAddList(oldList, newList);
404}
405
406/**
407 * @ingroup los_list
408 * @brief Obtain the offset of a field to a structure address. | 获取指定结构体内的成员相对于结构体起始地址的偏移量
409 *
410 * @par Description:
411 * This API is used to obtain the offset of a field to a structure address.
412 * @attention
413 * <ul>
414 * <li>None.</li>
415 * </ul>
416 *
417 * @param type [IN] Structure name.
418 * @param member [IN] Name of the member of which the offset is to be measured.
419 *
420 * @retval Offset of the field to the structure address.
421 * @par Dependency:
422 * <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
423 * @see
424 */
425#define LOS_OFF_SET_OF(type, member) ((UINTPTR)&((type *)0)->member)
426
427/**
428 * @ingroup los_list
429 * @brief Obtain the pointer to a structure that contains a doubly linked list. | 获取包含链表的结构体地址,接口的第一个入参表示的是链表中的下一个节点,第二个入参是要获取的结构体名称,第三个入参是链表在该结构体中的名称
430 *
431 * @par Description:
432 * This API is used to obtain the pointer to a structure that contains a doubly linked list.
433 * <ul>
434 * <li>None.</li>
435 * </ul>
436 * @attention
437 * <ul>
438 * <li>None.</li>
439 * </ul>
440 *
441 * @param item [IN] Current node's pointer to the next node.
442 * @param type [IN] Structure name.
443 * @param member [IN] Member name of the doubly linked list in the structure.
444 *
445 * @retval Pointer to the structure that contains the doubly linked list.
446 * @par Dependency:
447 * <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
448 * @see
449 *///获取双向链表中第一个链表节点所在的结构体地址,接口的第一个入参表示的是链表中的头节点,第二个入参是要获取的结构体名称,第三个入参是链表在该结构体中的名称
450#define LOS_DL_LIST_ENTRY(item, type, member) \
451 ((type *)(VOID *)((CHAR *)(item) - LOS_OFF_SET_OF(type, member)))
452
453/**
454 * @ingroup los_list
455 * @brief Iterate over a doubly linked list of given type. | 遍历指定双向链表,获取包含该链表节点的结构体地址
456 *
457 * @par Description:
458 * This API is used to iterate over a doubly linked list of given type.
459 * @attention
460 * <ul>
461 * <li>None.</li>
462 * </ul>
463 *
464 * @param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed.
465 * @param list [IN] Pointer to the doubly linked list to be traversed.
466 * @param type [IN] Structure name.
467 * @param member [IN] Member name of the doubly linked list in the structure.
468 *
469 * @retval None.
470 * @par Dependency:
471 * <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
472 * @see
473 *///遍历指定双向链表,获取包含该链表节点的结构体地址
474#define LOS_DL_LIST_FOR_EACH_ENTRY(item, list, type, member) \
475 for (item = LOS_DL_LIST_ENTRY((list)->pstNext, type, member); \
476 &(item)->member != (list); \
477 item = LOS_DL_LIST_ENTRY((item)->member.pstNext, type, member))
478
479/**
480 * @ingroup los_list
481 * @brief iterate over a doubly linked list safe against removal of list entry. | 遍历指定双向链表,获取包含该链表节点的结构体地址,并存储包含当前节点的后继节点的结构体地址
482 *
483 * @par Description:
484 * This API is used to iterate over a doubly linked list safe against removal of list entry.
485 * @attention
486 * <ul>
487 * <li>None.</li>
488 * </ul>
489 *
490 * @param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed.
491 * @param next [IN] Save the next node.
492 * @param list [IN] Pointer to the doubly linked list to be traversed.
493 * @param type [IN] Structure name.
494 * @param member [IN] Member name of the doubly linked list in the structure.
495 *
496 * @retval None.
497 * @par Dependency:
498 * <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
499 * @see
500 *///遍历指定双向链表,获取包含该链表节点的结构体地址,并存储包含当前节点的后继节点的结构体地址
501#define LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, next, list, type, member) \
502 for (item = LOS_DL_LIST_ENTRY((list)->pstNext, type, member), \
503 next = LOS_DL_LIST_ENTRY((item)->member.pstNext, type, member); \
504 &(item)->member != (list); \
505 item = next, next = LOS_DL_LIST_ENTRY((item)->member.pstNext, type, member))
506
507/**
508 * @ingroup los_list
509 * @brief Delete initialize a doubly linked list. | 将指定节点从链表中删除,并使用该节点初始化链表
510 *
511 * @par Description:
512 * This API is used to delete initialize a doubly linked list.
513 * @attention
514 * <ul>
515 * <li>The parameter passed in should be ensured to be s legal pointer.</li>
516 * </ul>
517 *
518 * @param list [IN] Doubly linked list.
519 *
520 * @retval None.
521 * @par Dependency:
522 * <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
523 * @see
524 *///将指定节点从链表中删除,并使用该节点初始化链表
525LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListDelInit(LOS_DL_LIST *list)
526{
527 list->pstNext->pstPrev = list->pstPrev;
528 list->pstPrev->pstNext = list->pstNext;
529 LOS_ListInit(list);
530}
531
532/**
533 * @ingroup los_list
534 * @brief iterate over a doubly linked list. | 遍历双向链表
535 *
536 * @par Description:
537 * This API is used to iterate over a doubly linked list.
538 * @attention
539 * <ul>
540 * <li>None.</li>
541 * </ul>
542 *
543 * @param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed.
544 * @param list [IN] Pointer to the doubly linked list to be traversed.
545 *
546 * @retval None.
547 * @par Dependency:
548 * <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
549 * @see
550 */ //遍历双向链表
551#define LOS_DL_LIST_FOR_EACH(item, list) \
552 for (item = (list)->pstNext; \
553 (item) != (list); \
554 item = (item)->pstNext)
555
556/**
557 * @ingroup los_list
558 * @brief Iterate over a doubly linked list safe against removal of list entry. | 遍历双向链表,并存储当前节点的后继节点用于安全校验
559 *
560 * @par Description:
561 * This API is used to iterate over a doubly linked list safe against removal of list entry.
562 * @attention
563 * <ul>
564 * <li>None.</li>
565 * </ul>
566 *
567 * @param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed.
568 * @param next [IN] Save the next node.
569 * @param list [IN] Pointer to the doubly linked list to be traversed.
570 *
571 * @retval None.
572 * @par Dependency:
573 * <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
574 * @see
575 *///遍历双向链表,并存储当前节点的后继节点用于安全校验
576#define LOS_DL_LIST_FOR_EACH_SAFE(item, next, list) \
577 for (item = (list)->pstNext, next = (item)->pstNext; \
578 (item) != (list); \
579 item = next, next = (item)->pstNext)
580
581/**
582 * @ingroup los_list
583 * @brief Initialize a double linked list. | 定义一个节点并初始化为双向链表节点
584 *
585 * @par Description:
586 * This API is used to initialize a double linked list.
587 * @attention
588 * <ul>
589 * <li>None.</li>
590 * </ul>
591 *
592 * @param list [IN] Pointer to the doubly linked list to be traversed.
593 *
594 * @retval None.
595 * @par Dependency:
596 * <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
597 * @see
598 *///定义一个节点并初始化为双向链表节点
599#define LOS_DL_LIST_HEAD(list) LOS_DL_LIST list = { &(list), &(list) }
600
601//获取双向链表中第一个链表节点所在的结构体地址,接口的第一个入参表示的是链表中的头节点,
602//第二个入参是要获取的结构体名称,第三个入参是链表在该结构体中的名称。如果链表为空,返回NULL。
603#define LOS_ListPeekHeadType(list, type, element) ({ \
604 type *__t; \
605 if ((list)->pstNext == list) { \
606 __t = NULL; \
607 } else { \
608 __t = LOS_DL_LIST_ENTRY((list)->pstNext, type, element); \
609 } \
610 __t; \
611})
612
613//获取双向链表中第一个链表节点所在的结构体地址,并把第一个链表节点从链表中删除。
614//接口的第一个入参表示的是链表中的头节点,第二个入参是要获取的结构体名称,
615//第三个入参是链表在该结构体中的名称。如果链表为空,返回NULL。
616#define LOS_ListRemoveHeadType(list, type, element) ({ \
617 type *__t; \
618 if ((list)->pstNext == list) { \
619 __t = NULL; \
620 } else { \
621 __t = LOS_DL_LIST_ENTRY((list)->pstNext, type, element); \
622 LOS_ListDelete((list)->pstNext); \
623 } \
624 __t; \
625})
626
627//获取双向链表中指定链表节点的下一个节点所在的结构体地址。
628//接口的第一个入参表示的是链表中的头节点,第二个入参是指定的链表节点,
629//第三个入参是要获取的结构体名称,第四个入参是链表在该结构体中的名称。
630//如果链表节点下一个为链表头结点为空,返回NULL。
631#define LOS_ListNextType(list, item, type, element) ({ \
632 type *__t; \
633 if ((item)->pstNext == list) { \
634 __t = NULL; \
635 } else { \
636 __t = LOS_DL_LIST_ENTRY((item)->pstNext, type, element); \
637 } \
638 __t; \
639})
640
641#ifdef __cplusplus
642#if __cplusplus
643}
644#endif /* __cplusplus */
645#endif /* __cplusplus */
646
647#endif /* _LOS_LIST_H */
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListDelInit(LOS_DL_LIST *list)
Delete initialize a doubly linked list. | 将指定节点从链表中删除,并使用该节点初始化链表
Definition: los_list.h:525
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
Definition: los_list.h:104
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListTailInsert(LOS_DL_LIST *list, LOS_DL_LIST *node)
Insert a node to the tail of a doubly linked list.
Definition: los_list.h:244
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListAddList(LOS_DL_LIST *oldList, LOS_DL_LIST *newList)
Insert a new list to a doubly linked list.
Definition: los_list.h:345
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListHeadInsert(LOS_DL_LIST *list, LOS_DL_LIST *node)
Insert a node to the head of a doubly linked list.
Definition: los_list.h:268
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListTailInsertList(LOS_DL_LIST *oldList, LOS_DL_LIST *newList)
Insert a doubly list to the tail of a doubly linked list.
Definition: los_list.h:377
struct LOS_DL_LIST LOS_DL_LIST
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListDelete(LOS_DL_LIST *node)
Definition: los_list.h:292
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListAdd(LOS_DL_LIST *list, LOS_DL_LIST *node)
Insert a new node to a doubly linked list.
Definition: los_list.h:217
LITE_OS_SEC_ALW_INLINE STATIC INLINE BOOL LOS_ListEmpty(LOS_DL_LIST *list)
Identify whether a specified doubly linked list is empty. | 判断链表是否为空
Definition: los_list.h:321
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListHeadInsertList(LOS_DL_LIST *oldList, LOS_DL_LIST *newList)
Insert a doubly list to the head of a doubly linked list.
Definition: los_list.h:401
size_t BOOL
Definition: los_typedef.h:88
struct LOS_DL_LIST * pstPrev
Definition: los_list.h:83
struct LOS_DL_LIST * pstNext
Definition: los_list.h:84