Zephyr API Documentation 4.0.0-rc2
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
slist.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
20#ifndef ZEPHYR_INCLUDE_SYS_SLIST_H_
21#define ZEPHYR_INCLUDE_SYS_SLIST_H_
22
23#include <stddef.h>
24#include <stdbool.h>
25#include "list_gen.h"
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31
33struct _snode {
34 struct _snode *next;
35};
39typedef struct _snode sys_snode_t;
40
42struct _slist {
43 sys_snode_t *head;
44 sys_snode_t *tail;
45};
49typedef struct _slist sys_slist_t;
50
66#define SYS_SLIST_FOR_EACH_NODE(__sl, __sn) \
67 Z_GENLIST_FOR_EACH_NODE(slist, __sl, __sn)
68
89#define SYS_SLIST_ITERATE_FROM_NODE(__sl, __sn) \
90 Z_GENLIST_ITERATE_FROM_NODE(slist, __sl, __sn)
91
108#define SYS_SLIST_FOR_EACH_NODE_SAFE(__sl, __sn, __sns) \
109 Z_GENLIST_FOR_EACH_NODE_SAFE(slist, __sl, __sn, __sns)
110
119#define SYS_SLIST_CONTAINER(__ln, __cn, __n) \
120 Z_GENLIST_CONTAINER(__ln, __cn, __n)
121
129#define SYS_SLIST_PEEK_HEAD_CONTAINER(__sl, __cn, __n) \
130 Z_GENLIST_PEEK_HEAD_CONTAINER(slist, __sl, __cn, __n)
131
139#define SYS_SLIST_PEEK_TAIL_CONTAINER(__sl, __cn, __n) \
140 Z_GENLIST_PEEK_TAIL_CONTAINER(slist, __sl, __cn, __n)
141
148#define SYS_SLIST_PEEK_NEXT_CONTAINER(__cn, __n) \
149 Z_GENLIST_PEEK_NEXT_CONTAINER(slist, __cn, __n)
150
165#define SYS_SLIST_FOR_EACH_CONTAINER(__sl, __cn, __n) \
166 Z_GENLIST_FOR_EACH_CONTAINER(slist, __sl, __cn, __n)
167
183#define SYS_SLIST_FOR_EACH_CONTAINER_SAFE(__sl, __cn, __cns, __n) \
184 Z_GENLIST_FOR_EACH_CONTAINER_SAFE(slist, __sl, __cn, __cns, __n)
185
186
187/*
188 * Required function definitions for the list_gen.h interface
189 *
190 * These are the only functions that do not treat the list/node pointers
191 * as completely opaque types.
192 */
193
199static inline void sys_slist_init(sys_slist_t *list)
200{
201 list->head = NULL;
202 list->tail = NULL;
203}
204
209#define SYS_SLIST_STATIC_INIT(ptr_to_list) {NULL, NULL}
210
211static inline sys_snode_t *z_snode_next_peek(sys_snode_t *node)
212{
213 return node->next;
214}
215
216static inline void z_snode_next_set(sys_snode_t *parent, sys_snode_t *child)
217{
218 parent->next = child;
219}
220
221static inline void z_slist_head_set(sys_slist_t *list, sys_snode_t *node)
222{
223 list->head = node;
224}
225
226static inline void z_slist_tail_set(sys_slist_t *list, sys_snode_t *node)
227{
228 list->tail = node;
229}
230
239{
240 return list->head;
241}
242
251{
252 return list->tail;
253}
254
255/*
256 * Derived, generated APIs
257 */
258
266static inline bool sys_slist_is_empty(sys_slist_t *list);
267
268Z_GENLIST_IS_EMPTY(slist)
269
270
280
281Z_GENLIST_PEEK_NEXT_NO_CHECK(slist, snode)
282
283
290static inline sys_snode_t *sys_slist_peek_next(sys_snode_t *node);
291
292Z_GENLIST_PEEK_NEXT(slist, snode)
293
294
302static inline void sys_slist_prepend(sys_slist_t *list,
303 sys_snode_t *node);
304
305Z_GENLIST_PREPEND(slist, snode)
306
307
315static inline void sys_slist_append(sys_slist_t *list,
316 sys_snode_t *node);
317
318Z_GENLIST_APPEND(slist, snode)
319
320
333static inline void sys_slist_append_list(sys_slist_t *list,
334 void *head, void *tail);
335
336Z_GENLIST_APPEND_LIST(slist, snode)
337
338
347static inline void sys_slist_merge_slist(sys_slist_t *list,
348 sys_slist_t *list_to_append);
349
350Z_GENLIST_MERGE_LIST(slist, snode)
351
352
361static inline void sys_slist_insert(sys_slist_t *list,
362 sys_snode_t *prev,
363 sys_snode_t *node);
364
365Z_GENLIST_INSERT(slist, snode)
366
367
378
379Z_GENLIST_GET_NOT_EMPTY(slist, snode)
380
381
390static inline sys_snode_t *sys_slist_get(sys_slist_t *list);
391
392Z_GENLIST_GET(slist, snode)
393
394
404static inline void sys_slist_remove(sys_slist_t *list,
405 sys_snode_t *prev_node,
406 sys_snode_t *node);
407
408Z_GENLIST_REMOVE(slist, snode)
409
410
420static inline bool sys_slist_find_and_remove(sys_slist_t *list,
421 sys_snode_t *node);
422
434static inline bool sys_slist_find(sys_slist_t *list, sys_snode_t *node,
435 sys_snode_t **prev);
436Z_GENLIST_FIND(slist, snode)
437
438
445static inline size_t sys_slist_len(sys_slist_t *list);
446
447Z_GENLIST_LEN(slist, snode)
448
449
450Z_GENLIST_FIND_AND_REMOVE(slist, snode)
451
452#ifdef __cplusplus
453}
454#endif
455
456#endif /* ZEPHYR_INCLUDE_SYS_SLIST_H_ */
static size_t sys_slist_len(sys_slist_t *list)
Compute the size of the given list in O(n) time.
Definition slist.h:447
static sys_snode_t * sys_slist_get_not_empty(sys_slist_t *list)
Fetch and remove the first node of the given list.
Definition slist.h:379
static void sys_slist_merge_slist(sys_slist_t *list, sys_slist_t *list_to_append)
merge two slists, appending the second one to the first
Definition slist.h:350
static sys_snode_t * sys_slist_peek_head(sys_slist_t *list)
Peek the first node from the list.
Definition slist.h:238
static bool sys_slist_find_and_remove(sys_slist_t *list, sys_snode_t *node)
Find and remove a node from a list.
Definition slist.h:450
struct _slist sys_slist_t
Single-linked list structure.
Definition slist.h:49
static sys_snode_t * sys_slist_get(sys_slist_t *list)
Fetch and remove the first node of the given list.
Definition slist.h:392
static sys_snode_t * sys_slist_peek_tail(sys_slist_t *list)
Peek the last node from the list.
Definition slist.h:250
static sys_snode_t * sys_slist_peek_next_no_check(sys_snode_t *node)
Peek the next node from current node, node is not NULL.
Definition slist.h:281
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:39
static sys_snode_t * sys_slist_peek_next(sys_snode_t *node)
Peek the next node from current node.
Definition slist.h:292
static bool sys_slist_is_empty(sys_slist_t *list)
Test if the given list is empty.
Definition slist.h:268
static void sys_slist_append(sys_slist_t *list, sys_snode_t *node)
Append a node to the given list.
Definition slist.h:318
static void sys_slist_init(sys_slist_t *list)
Initialize a list.
Definition slist.h:199
static void sys_slist_append_list(sys_slist_t *list, void *head, void *tail)
Append a list to the given list.
Definition slist.h:336
static void sys_slist_prepend(sys_slist_t *list, sys_snode_t *node)
Prepend a node to the given list.
Definition slist.h:305
static bool sys_slist_find(sys_slist_t *list, sys_snode_t *node, sys_snode_t **prev)
Find if a node is already linked in a singly linked list.
Definition slist.h:436
static void sys_slist_insert(sys_slist_t *list, sys_snode_t *prev, sys_snode_t *node)
Insert a node to the given list.
Definition slist.h:365
static void sys_slist_remove(sys_slist_t *list, sys_snode_t *prev_node, sys_snode_t *node)
Remove a node.
Definition slist.h:408