Zephyr API Documentation 4.4.99
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
22
23#ifndef ZEPHYR_INCLUDE_SYS_SLIST_H_
24#define ZEPHYR_INCLUDE_SYS_SLIST_H_
25
26#include <stddef.h>
27#include <stdbool.h>
28#include "list_gen.h"
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34
36struct _snode {
37 struct _snode *next;
38};
40
42typedef struct _snode sys_snode_t;
43
45struct _slist {
46 sys_snode_t *head;
47 sys_snode_t *tail;
48};
50
52typedef struct _slist sys_slist_t;
53
69#define SYS_SLIST_FOR_EACH_NODE(__sl, __sn) \
70 Z_GENLIST_FOR_EACH_NODE(slist, __sl, __sn)
71
92#define SYS_SLIST_ITERATE_FROM_NODE(__sl, __sn) \
93 Z_GENLIST_ITERATE_FROM_NODE(slist, __sl, __sn)
94
111#define SYS_SLIST_FOR_EACH_NODE_SAFE(__sl, __sn, __sns) \
112 Z_GENLIST_FOR_EACH_NODE_SAFE(slist, __sl, __sn, __sns)
113
122#define SYS_SLIST_CONTAINER(__ln, __cn, __n) \
123 Z_GENLIST_CONTAINER(__ln, __cn, __n)
124
132#define SYS_SLIST_PEEK_HEAD_CONTAINER(__sl, __cn, __n) \
133 Z_GENLIST_PEEK_HEAD_CONTAINER(slist, __sl, __cn, __n)
134
142#define SYS_SLIST_PEEK_TAIL_CONTAINER(__sl, __cn, __n) \
143 Z_GENLIST_PEEK_TAIL_CONTAINER(slist, __sl, __cn, __n)
144
151#define SYS_SLIST_PEEK_NEXT_CONTAINER(__cn, __n) \
152 Z_GENLIST_PEEK_NEXT_CONTAINER(slist, __cn, __n)
153
168#define SYS_SLIST_FOR_EACH_CONTAINER(__sl, __cn, __n) \
169 Z_GENLIST_FOR_EACH_CONTAINER(slist, __sl, __cn, __n)
170
186#define SYS_SLIST_FOR_EACH_CONTAINER_SAFE(__sl, __cn, __cns, __n) \
187 Z_GENLIST_FOR_EACH_CONTAINER_SAFE(slist, __sl, __cn, __cns, __n)
188
189
190/*
191 * Required function definitions for the list_gen.h interface
192 *
193 * These are the only functions that do not treat the list/node pointers
194 * as completely opaque types.
195 */
196
202static inline void sys_slist_init(sys_slist_t *list)
203{
204 list->head = NULL;
205 list->tail = NULL;
206}
207
212#define SYS_SLIST_STATIC_INIT(ptr_to_list) {NULL, NULL}
213
214static inline sys_snode_t *z_snode_next_peek(const sys_snode_t *node)
215{
216 return node->next;
217}
218
219static inline void z_snode_next_set(sys_snode_t *parent, sys_snode_t *child)
220{
221 parent->next = child;
222}
223
224static inline void z_slist_head_set(sys_slist_t *list, sys_snode_t *node)
225{
226 list->head = node;
227}
228
229static inline void z_slist_tail_set(sys_slist_t *list, sys_snode_t *node)
230{
231 list->tail = node;
232}
233
241static inline sys_snode_t *sys_slist_peek_head(const sys_slist_t *list)
242{
243 return list->head;
244}
245
253static inline sys_snode_t *sys_slist_peek_tail(const sys_slist_t *list)
254{
255 return list->tail;
256}
257
258/*
259 * Derived, generated APIs
260 */
261
269static inline bool sys_slist_is_empty(const sys_slist_t *list);
270
271Z_GENLIST_IS_EMPTY(slist)
272
273
282static inline sys_snode_t *sys_slist_peek_next_no_check(const sys_snode_t *node);
283
284Z_GENLIST_PEEK_NEXT_NO_CHECK(slist, snode)
285
286
293static inline sys_snode_t *sys_slist_peek_next(const sys_snode_t *node);
294
295Z_GENLIST_PEEK_NEXT(slist, snode)
296
297
305static inline void sys_slist_prepend(sys_slist_t *list,
306 sys_snode_t *node);
307
308Z_GENLIST_PREPEND(slist, snode)
309
310
318static inline void sys_slist_append(sys_slist_t *list,
319 sys_snode_t *node);
320
321Z_GENLIST_APPEND(slist, snode)
322
323
334static inline void sys_slist_append_list(sys_slist_t *list,
335 void *head, void *tail);
336
337Z_GENLIST_APPEND_LIST(slist, snode)
338
339
348static inline void sys_slist_merge_slist(sys_slist_t *list,
349 sys_slist_t *list_to_append);
350
351Z_GENLIST_MERGE_LIST(slist, snode)
352
353
362static inline void sys_slist_insert(sys_slist_t *list,
363 sys_snode_t *prev,
364 sys_snode_t *node);
365
366Z_GENLIST_INSERT(slist, snode)
367
368
379
380Z_GENLIST_GET_NOT_EMPTY(slist, snode)
381
382
391static inline sys_snode_t *sys_slist_get(sys_slist_t *list);
392
393Z_GENLIST_GET(slist, snode)
394
395
405static inline void sys_slist_remove(sys_slist_t *list,
406 sys_snode_t *prev_node,
407 sys_snode_t *node);
408
409Z_GENLIST_REMOVE(slist, snode)
410
411
421static inline bool sys_slist_find_and_remove(sys_slist_t *list,
422 sys_snode_t *node);
423
435static inline bool sys_slist_find(const sys_slist_t *list, const sys_snode_t *node,
436 sys_snode_t **prev);
437Z_GENLIST_FIND(slist, snode)
438
439
446static inline size_t sys_slist_len(const sys_slist_t *list);
447
448Z_GENLIST_LEN(slist, snode)
449
450
451Z_GENLIST_FIND_AND_REMOVE(slist, snode)
452
453#ifdef __cplusplus
454}
455#endif
456
457#endif /* ZEPHYR_INCLUDE_SYS_SLIST_H_ */
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:380
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:351
static sys_snode_t * sys_slist_peek_next_no_check(const sys_snode_t *node)
Peek the next node from current node, node is not NULL.
Definition slist.h:284
static bool sys_slist_find(const sys_slist_t *list, const sys_snode_t *node, sys_snode_t **prev)
Find if a node is already linked in a singly linked list.
Definition slist.h:437
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:451
struct _slist sys_slist_t
Single-linked list structure.
Definition slist.h:52
static sys_snode_t * sys_slist_get(sys_slist_t *list)
Fetch and remove the first node of the given list.
Definition slist.h:393
static sys_snode_t * sys_slist_peek_tail(const sys_slist_t *list)
Peek the last node from the list.
Definition slist.h:253
static sys_snode_t * sys_slist_peek_head(const sys_slist_t *list)
Peek the first node from the list.
Definition slist.h:241
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:42
static void sys_slist_append(sys_slist_t *list, sys_snode_t *node)
Append a node to the given list.
Definition slist.h:321
static void sys_slist_init(sys_slist_t *list)
Initialize a list.
Definition slist.h:202
static size_t sys_slist_len(const sys_slist_t *list)
Compute the size of the given list in O(n) time.
Definition slist.h:448
static void sys_slist_append_list(sys_slist_t *list, void *head, void *tail)
Append a list to the given list.
Definition slist.h:337
static sys_snode_t * sys_slist_peek_next(const sys_snode_t *node)
Peek the next node from current node.
Definition slist.h:295
static void sys_slist_prepend(sys_slist_t *list, sys_snode_t *node)
Prepend a node to the given list.
Definition slist.h:308
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:366
static void sys_slist_remove(sys_slist_t *list, sys_snode_t *prev_node, sys_snode_t *node)
Remove a node.
Definition slist.h:409
static bool sys_slist_is_empty(const sys_slist_t *list)
Test if the given list is empty.
Definition slist.h:271
Internal generic linked-list macro generators shared by slist/dlist/sflist.