xt-sdk 文档
v1.0.3
xt-sdk 嵌入式 SDK API 参考
Toggle main menu visibility
载入中...
搜索中...
未找到
xt_list.h
浏览该文件的文档.
1
12
13
#ifndef __XT_LIST_H__
14
#define __XT_LIST_H__
15
16
#include <stddef.h>
17
#include <stdint.h>
18
19
#ifdef __cplusplus
20
extern
"C"
{
21
#endif
22
29
33
struct
xt_list_node
{
34
struct
xt_list_node
*
next
;
35
struct
xt_list_node
*
prev
;
36
};
37
41
struct
xt_slist_node
{
42
struct
xt_slist_node
*
next
;
43
};
44
49
#define xt_container_of(ptr, type, member) \
50
((type *)((char *)(ptr) - (uintptr_t)(&((type *)0)->member)))
51
55
#define XT_LIST_OBJECT_INIT(object) { &(object), &(object) }
56
62
static
inline
void
xt_list_init
(
struct
xt_list_node
*l)
63
{
64
l->
next
= l->
prev
= l;
65
}
66
73
static
inline
void
xt_list_insert_after
(
struct
xt_list_node
*l,
struct
xt_list_node
*n)
74
{
75
l->
next
->
prev
= n;
76
n->
next
= l->
next
;
77
78
l->
next
= n;
79
n->
prev
= l;
80
}
81
88
static
inline
void
xt_list_insert_before
(
struct
xt_list_node
*l,
struct
xt_list_node
*n)
89
{
90
l->
prev
->
next
= n;
91
n->
prev
= l->
prev
;
92
93
l->
prev
= n;
94
n->
next
= l;
95
}
96
101
static
inline
void
xt_list_remove
(
struct
xt_list_node
*n)
102
{
103
n->
next
->
prev
= n->
prev
;
104
n->
prev
->
next
= n->
next
;
105
106
n->
next
= n->
prev
= n;
107
}
108
113
static
inline
int
xt_list_isempty
(
const
struct
xt_list_node
*l)
114
{
115
return
l->
next
== l;
116
}
117
122
static
inline
unsigned
int
xt_list_len
(
const
struct
xt_list_node
*l)
123
{
124
unsigned
int
len = 0;
125
const
struct
xt_list_node
*p = l;
126
while
(p->
next
!= l) {
127
p = p->
next
;
128
len ++;
129
}
130
131
return
len;
132
}
133
140
#define xt_list_entry(node, type, member) \
141
xt_container_of(node, type, member)
142
148
#define xt_list_for_each(pos, head) \
149
for (pos = (head)->next; pos != (head); pos = pos->next)
150
157
#define xt_list_for_each_safe(pos, n, head) \
158
for (pos = (head)->next, n = pos->next; pos != (head); \
159
pos = n, n = pos->next)
160
167
#define xt_list_for_each_entry(pos, head, member) \
168
for (pos = xt_list_entry((head)->next, typeof(*pos), member); \
169
&pos->member != (head); \
170
pos = xt_list_entry(pos->member.next, typeof(*pos), member))
171
179
#define xt_list_for_each_entry_safe(pos, n, head, member) \
180
for (pos = xt_list_entry((head)->next, typeof(*pos), member), \
181
n = xt_list_entry(pos->member.next, typeof(*pos), member); \
182
&pos->member != (head); \
183
pos = n, n = xt_list_entry(n->member.next, typeof(*n), member))
184
193
#define xt_list_first_entry(ptr, type, member) \
194
xt_list_entry((ptr)->next, type, member)
195
196
#define XT_SLIST_OBJECT_INIT(object) { NULL }
197
203
static
inline
void
xt_slist_init
(
struct
xt_slist_node
*l)
204
{
205
l->
next
= NULL;
206
}
207
208
static
inline
void
xt_slist_append
(
struct
xt_slist_node
*l,
struct
xt_slist_node
*n)
209
{
210
struct
xt_slist_node
*node;
211
212
node = l;
213
while
(node->
next
) {
214
node = node->
next
;
215
}
216
217
/* append the node to the tail */
218
node->
next
= n;
219
n->
next
= NULL;
220
}
221
222
static
inline
void
xt_slist_insert
(
struct
xt_slist_node
*l,
struct
xt_slist_node
*n)
223
{
224
n->
next
= l->
next
;
225
l->
next
= n;
226
}
227
228
static
inline
unsigned
int
xt_slist_len
(
const
struct
xt_slist_node
*l)
229
{
230
unsigned
int
len = 0;
231
const
struct
xt_slist_node
*list = l->
next
;
232
while
(list != NULL) {
233
list = list->
next
;
234
len ++;
235
}
236
237
return
len;
238
}
239
240
static
inline
struct
xt_slist_node
*
xt_slist_remove
(
struct
xt_slist_node
*l,
struct
xt_slist_node
*n)
241
{
242
/* remove slist head */
243
struct
xt_slist_node
*node = l;
244
while
(node->
next
&& node->
next
!= n) {
245
node = node->
next
;
246
}
247
248
/* remove node */
249
if
(node->
next
!= (
struct
xt_slist_node
*)0) {
250
node->
next
= node->
next
->
next
;
251
}
252
253
return
l;
254
}
255
256
static
inline
struct
xt_slist_node
*
xt_slist_first
(
struct
xt_slist_node
*l)
257
{
258
return
l->
next
;
259
}
260
261
static
inline
struct
xt_slist_node
*
xt_slist_tail
(
struct
xt_slist_node
*l)
262
{
263
while
(l->
next
) {
264
l = l->
next
;
265
}
266
267
return
l;
268
}
269
270
static
inline
struct
xt_slist_node
*
xt_slist_next
(
struct
xt_slist_node
*n)
271
{
272
return
n->
next
;
273
}
274
275
static
inline
int
xt_slist_isempty
(
struct
xt_slist_node
*l)
276
{
277
return
l->
next
== NULL;
278
}
279
286
#define xt_slist_entry(node, type, member) \
287
xt_container_of(node, type, member)
288
294
#define xt_slist_for_each(pos, head) \
295
for (pos = (head)->next; pos != NULL; pos = pos->next)
296
303
#define xt_slist_for_each_entry(pos, head, member) \
304
for (pos = xt_slist_entry((head)->next, typeof(*pos), member); \
305
&pos->member != (NULL); \
306
pos = xt_slist_entry(pos->member.next, typeof(*pos), member))
307
316
#define xt_slist_first_entry(ptr, type, member) \
317
xt_slist_entry((ptr)->next, type, member)
318
327
#define xt_slist_tail_entry(ptr, type, member) \
328
xt_slist_entry(xt_slist_tail(ptr), type, member)
329
/* xt_list */
331
332
#ifdef __cplusplus
333
}
/* extern "C" */
334
#endif
335
336
#endif
/* __XT_LIST_H__ */
xt_list_len
static unsigned int xt_list_len(const struct xt_list_node *l)
get the list length
定义
xt_list.h:122
xt_slist_first
static struct xt_slist_node * xt_slist_first(struct xt_slist_node *l)
定义
xt_list.h:256
xt_list_init
static void xt_list_init(struct xt_list_node *l)
initialize a list
定义
xt_list.h:62
xt_list_remove
static void xt_list_remove(struct xt_list_node *n)
remove node from list.
定义
xt_list.h:101
xt_list_insert_before
static void xt_list_insert_before(struct xt_list_node *l, struct xt_list_node *n)
insert a node before a list
定义
xt_list.h:88
xt_slist_tail
static struct xt_slist_node * xt_slist_tail(struct xt_slist_node *l)
定义
xt_list.h:261
xt_slist_insert
static void xt_slist_insert(struct xt_slist_node *l, struct xt_slist_node *n)
定义
xt_list.h:222
xt_slist_len
static unsigned int xt_slist_len(const struct xt_slist_node *l)
定义
xt_list.h:228
xt_list_insert_after
static void xt_list_insert_after(struct xt_list_node *l, struct xt_list_node *n)
insert a node after a list
定义
xt_list.h:73
xt_slist_next
static struct xt_slist_node * xt_slist_next(struct xt_slist_node *n)
定义
xt_list.h:270
xt_slist_init
static void xt_slist_init(struct xt_slist_node *l)
initialize a single list
定义
xt_list.h:203
xt_slist_append
static void xt_slist_append(struct xt_slist_node *l, struct xt_slist_node *n)
定义
xt_list.h:208
xt_slist_isempty
static int xt_slist_isempty(struct xt_slist_node *l)
定义
xt_list.h:275
xt_list_isempty
static int xt_list_isempty(const struct xt_list_node *l)
tests whether a list is empty
定义
xt_list.h:113
xt_slist_remove
static struct xt_slist_node * xt_slist_remove(struct xt_slist_node *l, struct xt_slist_node *n)
定义
xt_list.h:240
xt_list_node
定义
xt_list.h:33
xt_list_node::prev
struct xt_list_node * prev
定义
xt_list.h:35
xt_list_node::next
struct xt_list_node * next
定义
xt_list.h:34
xt_slist_node
定义
xt_list.h:41
xt_slist_node::next
struct xt_slist_node * next
定义
xt_list.h:42
components
xt_std
xt_list.h
生成于
, 为 xt-sdk 文档使用
1.17.0