|
|
@ -50,6 +50,10 @@ typedef struct LOS_DL_LIST {
|
|
|
|
struct LOS_DL_LIST *pstPrev; /**< Current node's pointer to the previous node */
|
|
|
|
struct LOS_DL_LIST *pstPrev; /**< Current node's pointer to the previous node */
|
|
|
|
struct LOS_DL_LIST *pstNext; /**< Current node's pointer to the next node */
|
|
|
|
struct LOS_DL_LIST *pstNext; /**< Current node's pointer to the next node */
|
|
|
|
} LOS_DL_LIST;
|
|
|
|
} LOS_DL_LIST;
|
|
|
|
|
|
|
|
/*这种结构体通常用于实现双向链表数据结构。
|
|
|
|
|
|
|
|
通过在每个节点中嵌入LOS_DL_LIST结构体,
|
|
|
|
|
|
|
|
可以将多个节点连接起来形成链表。
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @ingroup los_list
|
|
|
|
* @ingroup los_list
|
|
|
@ -74,7 +78,11 @@ LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
|
|
|
|
list->pstNext = list;
|
|
|
|
list->pstNext = list;
|
|
|
|
list->pstPrev = list;
|
|
|
|
list->pstPrev = list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*这段代码定义了一个静态内联函数LOS_ListInit,
|
|
|
|
|
|
|
|
该函数接受一个指向LOS_DL_LIST结构体的指针list作为参数,没有返回值。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
函数的作用是将传入的链表初始化为空,即将链表头节点的pstNext和pstPrev指
|
|
|
|
|
|
|
|
针都指向头节点本身,表示链表中没有其他节点。*/
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @ingroup los_list
|
|
|
|
* @ingroup los_list
|
|
|
|
* @brief Point to the next node of the current node.
|
|
|
|
* @brief Point to the next node of the current node.
|
|
|
@ -93,7 +101,12 @@ LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
|
|
|
|
* @since Huawei LiteOS V100R001C00
|
|
|
|
* @since Huawei LiteOS V100R001C00
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#define LOS_DL_LIST_FIRST(object) ((object)->pstNext)
|
|
|
|
#define LOS_DL_LIST_FIRST(object) ((object)->pstNext)
|
|
|
|
|
|
|
|
/*这段代码定义了一个宏LOS_DL_LIST_FIRST(object),
|
|
|
|
|
|
|
|
它接受一个指向LOS_DL_LIST结构体的指针object作为参数,
|
|
|
|
|
|
|
|
并返回object指向的节点的下一个节点的指针,即链表中的第一个节点。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
这个宏的作用是方便地获取链表中的第一个节点,通过宏展开后,
|
|
|
|
|
|
|
|
可以直接访问链表头节点的下一个节点。*/
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @ingroup los_list
|
|
|
|
* @ingroup los_list
|
|
|
|
* @brief Point to the previous node of the current node.
|
|
|
|
* @brief Point to the previous node of the current node.
|
|
|
@ -112,7 +125,10 @@ LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
|
|
|
|
* @since Huawei LiteOS V100R001C00
|
|
|
|
* @since Huawei LiteOS V100R001C00
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#define LOS_DL_LIST_LAST(object) ((object)->pstPrev)
|
|
|
|
#define LOS_DL_LIST_LAST(object) ((object)->pstPrev)
|
|
|
|
|
|
|
|
/*这段代码是一个宏定义,用于获取双向链表中指定节点的前一个节点。
|
|
|
|
|
|
|
|
在这里,传入的参数 object 是一个指向双向链表节点的指针,
|
|
|
|
|
|
|
|
pstPrev 是该节点中指向前一个节点的指针。
|
|
|
|
|
|
|
|
该宏的功能是返回指定节点的前一个节点的指针。*/
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @ingroup los_list
|
|
|
|
* @ingroup los_list
|
|
|
|
* @brief Insert a new node to a doubly linked list.
|
|
|
|
* @brief Insert a new node to a doubly linked list.
|
|
|
@ -138,7 +154,13 @@ LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListAdd(LOS_DL_LIST *list, LOS_DL_
|
|
|
|
list->pstNext->pstPrev = node;
|
|
|
|
list->pstNext->pstPrev = node;
|
|
|
|
list->pstNext = node;
|
|
|
|
list->pstNext = node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*该函数将新节点插入到链表头部,具体步骤如下:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
把新节点的 next 指针指向链表头部的下一个节点。
|
|
|
|
|
|
|
|
把新节点的 prev 指针指向链表头部。
|
|
|
|
|
|
|
|
把原链表头部的下一个节点的 prev 指针指向新节点。
|
|
|
|
|
|
|
|
把链表头部的 next 指针指向新节点。
|
|
|
|
|
|
|
|
通过这些步骤,新节点就被成功地添加到了链表头部。*/
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @ingroup los_list
|
|
|
|
* @ingroup los_list
|
|
|
|
* @brief Insert a node to a doubly linked list.
|
|
|
|
* @brief Insert a node to a doubly linked list.
|
|
|
@ -161,7 +183,10 @@ LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListTailInsert(LOS_DL_LIST *list,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LOS_ListAdd(list->pstPrev, node);
|
|
|
|
LOS_ListAdd(list->pstPrev, node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*在该函数中,使用了宏定义 LOS_DL_LIST 来表示链表节点,
|
|
|
|
|
|
|
|
使用了 STATIC INLINE 关键字来定义内联函数,以提高代码执行效率。
|
|
|
|
|
|
|
|
函数的实现非常简单,只需调用双向链表的插入操作 LOS_ListAdd,
|
|
|
|
|
|
|
|
将新节点添加到链表头部的前一个节点即可。*/
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @ingroup los_list
|
|
|
|
* @ingroup los_list
|
|
|
|
* @brief Insert a node to a doubly linked list.
|
|
|
|
* @brief Insert a node to a doubly linked list.
|
|
|
@ -210,7 +235,12 @@ LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListDelete(LOS_DL_LIST *node)
|
|
|
|
node->pstNext = NULL;
|
|
|
|
node->pstNext = NULL;
|
|
|
|
node->pstPrev = NULL;
|
|
|
|
node->pstPrev = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*该函数的实现非常简单,具体步骤如下:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
把被删除节点的 next 节点的 prev 指针指向被删除节点的 prev 节点。
|
|
|
|
|
|
|
|
把被删除节点的 prev 节点的 next 指针指向被删除节点的 next 节点。
|
|
|
|
|
|
|
|
清空被删除节点的 next 指针和 prev 指针。
|
|
|
|
|
|
|
|
通过这些步骤,被指定的节点就从链表中被成功地删除了。*/
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @ingroup los_list
|
|
|
|
* @ingroup los_list
|
|
|
|
* @brief Identify whether a specified doubly linked list is empty or not.
|
|
|
|
* @brief Identify whether a specified doubly linked list is empty or not.
|
|
|
@ -233,7 +263,12 @@ LITE_OS_SEC_ALW_INLINE STATIC INLINE BOOL LOS_ListEmpty(LOS_DL_LIST *list)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return (BOOL)(list->pstNext == list);
|
|
|
|
return (BOOL)(list->pstNext == list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*具体步骤如下:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
判断链表头部的 pstNext 指针是否等于链表头部本身。
|
|
|
|
|
|
|
|
如果相等,返回 TRUE(表示链表为空)。
|
|
|
|
|
|
|
|
如果不相等,返回 FALSE(表示链表不为空)。
|
|
|
|
|
|
|
|
通过这些步骤,可以判断链表是否为空。*/
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @ingroup los_list
|
|
|
|
* @ingroup los_list
|
|
|
|
* @brief Obtain the offset of a structure member relative to the structure start address.
|
|
|
|
* @brief Obtain the offset of a structure member relative to the structure start address.
|
|
|
@ -256,7 +291,10 @@ LITE_OS_SEC_ALW_INLINE STATIC INLINE BOOL LOS_ListEmpty(LOS_DL_LIST *list)
|
|
|
|
|
|
|
|
|
|
|
|
/* Obsolete API, please use LOS_OFF_SET_OF instead */
|
|
|
|
/* Obsolete API, please use LOS_OFF_SET_OF instead */
|
|
|
|
#define OFFSET_OF_FIELD(type, field) LOS_OFF_SET_OF(type, field)
|
|
|
|
#define OFFSET_OF_FIELD(type, field) LOS_OFF_SET_OF(type, field)
|
|
|
|
|
|
|
|
/*这些宏的作用是帮助程序员在编写代码时可以方便地获取结构体成员的偏移量。
|
|
|
|
|
|
|
|
通常情况下,结构体成员的偏移量用于在程序中进行内存操作,
|
|
|
|
|
|
|
|
比如根据结构体的指针和成员的偏移量,
|
|
|
|
|
|
|
|
可以获取到该成员的地址或修改该成员的值。*/
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @ingroup los_list
|
|
|
|
* @ingroup los_list
|
|
|
|
* @brief Obtain the pointer to a structure that contains a doubly linked list.
|
|
|
|
* @brief Obtain the pointer to a structure that contains a doubly linked list.
|
|
|
@ -309,7 +347,12 @@ LITE_OS_SEC_ALW_INLINE STATIC INLINE BOOL LOS_ListEmpty(LOS_DL_LIST *list)
|
|
|
|
for (item = LOS_DL_LIST_ENTRY((list)->pstNext, type, member); \
|
|
|
|
for (item = LOS_DL_LIST_ENTRY((list)->pstNext, type, member); \
|
|
|
|
&(item)->member != (list); \
|
|
|
|
&(item)->member != (list); \
|
|
|
|
item = LOS_DL_LIST_ENTRY((item)->member.pstNext, type, member))
|
|
|
|
item = LOS_DL_LIST_ENTRY((item)->member.pstNext, type, member))
|
|
|
|
|
|
|
|
/*宏的实现通过 for 循环来实现链表的遍历,具体步骤如下:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
首先使用 LOS_DL_LIST_ENTRY 宏获取链表头部节点的指针,并将其赋值给 item 变量,从而初始化遍历的起始位置。
|
|
|
|
|
|
|
|
接着判断条件 &(item)->member != (list),当遍历到链表末尾时,即链表头部时结束遍历,否则继续循环。
|
|
|
|
|
|
|
|
在循环体内,执行对当前节点的操作,并使用 LOS_DL_LIST_ENTRY 宏获取下一个节点的指针,从而实现链表的顺序遍历。
|
|
|
|
|
|
|
|
通过这些步骤,可以方便地遍历双向链表中的每个节点,并对每个节点执行相应的操作。*/
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @ingroup los_list
|
|
|
|
* @ingroup los_list
|
|
|
|
* @brief Traverse a doubly linked list which is included in a given type structure. And
|
|
|
|
* @brief Traverse a doubly linked list which is included in a given type structure. And
|
|
|
@ -343,7 +386,13 @@ LITE_OS_SEC_ALW_INLINE STATIC INLINE BOOL LOS_ListEmpty(LOS_DL_LIST *list)
|
|
|
|
next = LOS_DL_LIST_ENTRY((item)->member.pstNext, type, member); \
|
|
|
|
next = LOS_DL_LIST_ENTRY((item)->member.pstNext, type, member); \
|
|
|
|
&(item)->member != (list); \
|
|
|
|
&(item)->member != (list); \
|
|
|
|
item = next, next = LOS_DL_LIST_ENTRY((item)->member.pstNext, type, member))
|
|
|
|
item = next, next = LOS_DL_LIST_ENTRY((item)->member.pstNext, type, member))
|
|
|
|
|
|
|
|
/*该宏的功能是按顺序遍历链表中的每个节点,并对每个节点执行指定的操作。其参数包括:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
item:表示当前遍历到的节点
|
|
|
|
|
|
|
|
next:表示下一个节点的指针
|
|
|
|
|
|
|
|
list:表示链表的头部
|
|
|
|
|
|
|
|
type:表示链表节点所在的结构体类型
|
|
|
|
|
|
|
|
member:表示链表节点在结构体中的成员名*/
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @ingroup los_list
|
|
|
|
* @ingroup los_list
|
|
|
|
* @brief Iterate over a doubly linked list of given type, and call hook for any extra procedures every time.
|
|
|
|
* @brief Iterate over a doubly linked list of given type, and call hook for any extra procedures every time.
|
|
|
@ -370,7 +419,13 @@ LITE_OS_SEC_ALW_INLINE STATIC INLINE BOOL LOS_ListEmpty(LOS_DL_LIST *list)
|
|
|
|
for (item = LOS_DL_LIST_ENTRY((list)->pstNext, type, member), hook; \
|
|
|
|
for (item = LOS_DL_LIST_ENTRY((list)->pstNext, type, member), hook; \
|
|
|
|
&(item)->member != (list); \
|
|
|
|
&(item)->member != (list); \
|
|
|
|
item = LOS_DL_LIST_ENTRY((item)->member.pstNext, type, member), hook)
|
|
|
|
item = LOS_DL_LIST_ENTRY((item)->member.pstNext, type, member), hook)
|
|
|
|
|
|
|
|
/*该宏的功能是按顺序遍历链表中的每个节点,并在每个节点遍历之前执行指定的钩子函数。其参数包括:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
item:表示当前遍历到的节点
|
|
|
|
|
|
|
|
list:表示链表的头部
|
|
|
|
|
|
|
|
type:表示链表节点所在的结构体类型
|
|
|
|
|
|
|
|
member:表示链表节点在结构体中的成员名
|
|
|
|
|
|
|
|
hook:表示要执行的钩子函数*/
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @ingroup los_list
|
|
|
|
* @ingroup los_list
|
|
|
|
* @brief Delete a specified node from a doubly linked list and reinitialize the node.
|
|
|
|
* @brief Delete a specified node from a doubly linked list and reinitialize the node.
|
|
|
@ -396,7 +451,7 @@ LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListDelInit(LOS_DL_LIST *list)
|
|
|
|
list->pstPrev->pstNext = list->pstNext;
|
|
|
|
list->pstPrev->pstNext = list->pstNext;
|
|
|
|
LOS_ListInit(list);
|
|
|
|
LOS_ListInit(list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**/
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @ingroup los_list
|
|
|
|
* @ingroup los_list
|
|
|
|
* @brief Traverse a doubly linked list.
|
|
|
|
* @brief Traverse a doubly linked list.
|
|
|
@ -423,7 +478,12 @@ LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListDelInit(LOS_DL_LIST *list)
|
|
|
|
for (item = (list)->pstNext; \
|
|
|
|
for (item = (list)->pstNext; \
|
|
|
|
(item) != (list); \
|
|
|
|
(item) != (list); \
|
|
|
|
item = (item)->pstNext)
|
|
|
|
item = (item)->pstNext)
|
|
|
|
|
|
|
|
/*宏的实现通过 for 循环来实现链表的遍历,具体步骤如下:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
在循环初始化部分,将 item 初始化为链表头部节点的下一个节点,即 (list)->pstNext。
|
|
|
|
|
|
|
|
在循环条件中,判断条件 (item) != (list),当 item 等于链表头部时,即遍历到链表末尾时结束遍历,否则继续循环。
|
|
|
|
|
|
|
|
在每次循环结束之后,将 item 更新为下一个节点的指针,即 (item)->pstNext。
|
|
|
|
|
|
|
|
通过这些步骤,可以方便地遍历双向链表中的每个节点,并在循环体内对每个节点执行指定的操作。*/
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @ingroup los_list
|
|
|
|
* @ingroup los_list
|
|
|
|
* @brief Traverse a doubly linked list safe against removal of list entry.
|
|
|
|
* @brief Traverse a doubly linked list safe against removal of list entry.
|
|
|
@ -475,7 +535,7 @@ LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListDelInit(LOS_DL_LIST *list)
|
|
|
|
* @since Huawei LiteOS V100R001C00
|
|
|
|
* @since Huawei LiteOS V100R001C00
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#define LOS_DL_LIST_HEAD(list) LOS_DL_LIST list = { &(list), &(list) }
|
|
|
|
#define LOS_DL_LIST_HEAD(list) LOS_DL_LIST list = { &(list), &(list) }
|
|
|
|
|
|
|
|
/*通过这个宏,可以方便地定义和初始化一个双向链表的头部节点,为链表的后续操作提供了便利。*/
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#if __cplusplus
|
|
|
|
#if __cplusplus
|
|
|
|
}
|
|
|
|
}
|
|
|
|