API参考
载入中...
搜索中...
未找到
bsl_module_list.h
1/*
2 * This file is part of the openHiTLS project.
3 *
4 * openHiTLS is licensed under the Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:
7 *
8 * http://license.coscl.org.cn/MulanPSL2
9 *
10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13 * See the Mulan PSL v2 for more details.
14 */
15
16#ifndef BSL_MODULE_LIST_H
17#define BSL_MODULE_LIST_H
18
19#include <stdint.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25/*
26 * This structure is used to store the forward and backward pointers of nodes in the bidirectional linked list.
27 * This linked list does not contain substantial data areas and is generally used to organize (concatenate) data nodes.
28 */
29typedef struct ListHeadSt {
30 struct ListHeadSt *next, *prev;
31} ListHead;
32
38#define LIST_INIT(head) (head)->next = (head)->prev = (head)
39
47#define LIST_ADD_AFTER(where, item) do { \
48 (item)->next = (where)->next; \
49 (item)->prev = (where); \
50 (where)->next = (item); \
51 (item)->next->prev = (item); \
52} while (0)
53
61#define LIST_ADD_BEFORE(where, item) LIST_ADD_AFTER((where)->prev, (item))
62
68#define LIST_REMOVE(item) do { \
69 (item)->prev->next = (item)->next; \
70 (item)->next->prev = (item)->prev; \
71} while (0)
72
78#define LIST_IS_EMPTY(head) ((head)->next == (head))
79
87#define LIST_FOR_EACH_ITEM_SAFE(item, temp, head) \
88 for ((item) = (head)->next, (temp) = (item)->next; (item) != (head); (item) = (temp), (temp) = (item)->next)
89
112#define LIST_ENTRY(item, type, member) \
113 ((type *)((uintptr_t)(char *)(item) - (uintptr_t)(&((type *)0)->member)))
114
115#ifdef __cplusplus
116}
117#endif
118#endif // BSL_MODULE_LIST_H
定义 bsl_module_list.h:29