用途:双向链表和单向链表的节点结构
来源:kernel/include/os_list.h:41
struct os_list_node
{
struct os_list_node *next; /* Point to next node */
struct os_list_node *prev; /* point to previous node */
};
typedef struct os_list_node os_list_node_t;
| 字段 | 类型 | 说明 |
|---|
next | struct os_list_node * | 指向后续节点 |
prev | struct os_list_node * | 指向前面节点 |
- 环形双向链表结构
- 空链表时
node->next == node 且 node->prev == node - 通常作为嵌入式成员(
os_container_of)使用
struct my_struct
{
int data;
os_list_node_t list_node; /* 嵌入链表节点 */
};
os_list_node_t head;
os_list_init(&head); /* 初始化链表 */
struct my_struct entry;
os_list_add_tail(&head, &entry.list_node); /* 添加到链表尾部 */
struct os_slist_node
{
struct os_slist_node *next; /* Point to next node */
};
typedef struct os_slist_node os_slist_node_t;
| 字段 | 类型 | 说明 |
|---|
next | struct os_slist_node * | 指向后续节点 |
- 单向链表结构
- 空链表时
node->next == OS_NULL - 内存占用更小
struct my_struct
{
int data;
os_slist_node_t slist_node; /* 嵌入单向链表节点 */
};
os_slist_node_t head;
os_slist_init(&head); /* 初始化单向链表 */
struct my_struct entry;
os_slist_add(&head, &entry.slist_node); /* 添加到链表头部 */
| 函数 | 说明 |
|---|
os_list_init(node) | 初始化链表节点 |
os_list_add(head, entry) | 在 head 后添加节点 |
os_list_add_tail(head, entry) | 在 head 前添加节点 |
os_list_del(entry) | 删除节点 |
os_list_del_init(entry) | 删除节点并重新初始化 |
os_list_move(head, entry) | 移动节点到 head 后 |
os_list_move_tail(head, entry) | 移动节点到 head 前 |
os_list_empty(head) | 判断是否为空 |
os_list_len(head) | 获取链表长度 |
os_list_splice(head, list) | 合并链表 |
| 函数 | 说明 |
|---|
os_slist_init(node) | 初始化单向链表节点 |
os_slist_add(head, entry) | 在头部添加节点 |
os_slist_add_tail(head, entry) | 在尾部添加节点 |
os_slist_del(head, entry) | 删除节点 |
os_slist_empty(head) | 判断是否为空 |
os_slist_len(head) | 获取链表长度 |