Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
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
17#ifndef ZEPHYR_INCLUDE_SYS_SLIST_H_
18#define ZEPHYR_INCLUDE_SYS_SLIST_H_
19
20#include <stddef.h>
21#include <stdbool.h>
22#include "list_gen.h"
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28
29struct _snode {
30 struct _snode *next;
31};
32
33typedef struct _snode sys_snode_t;
34
35struct _slist {
36 sys_snode_t *head;
37 sys_snode_t *tail;
38};
39
40typedef struct _slist sys_slist_t;
41
63#define SYS_SLIST_FOR_EACH_NODE(__sl, __sn) \
64 Z_GENLIST_FOR_EACH_NODE(slist, __sl, __sn)
65
86#define SYS_SLIST_ITERATE_FROM_NODE(__sl, __sn) \
87 Z_GENLIST_ITERATE_FROM_NODE(slist, __sl, __sn)
88
105#define SYS_SLIST_FOR_EACH_NODE_SAFE(__sl, __sn, __sns) \
106 Z_GENLIST_FOR_EACH_NODE_SAFE(slist, __sl, __sn, __sns)
107
108/*
109 * @brief Provide the primitive to resolve the container of a list node
110 * Note: it is safe to use with NULL pointer nodes
111 *
112 * @param __ln A pointer on a sys_node_t to get its container
113 * @param __cn Container struct type pointer
114 * @param __n The field name of sys_node_t within the container struct
115 */
116#define SYS_SLIST_CONTAINER(__ln, __cn, __n) \
117 Z_GENLIST_CONTAINER(__ln, __cn, __n)
118
119/*
120 * @brief Provide the primitive to peek container of the list head
121 *
122 * @param __sl A pointer on a sys_slist_t to peek
123 * @param __cn Container struct type pointer
124 * @param __n The field name of sys_node_t within the container struct
125 */
126#define SYS_SLIST_PEEK_HEAD_CONTAINER(__sl, __cn, __n) \
127 Z_GENLIST_PEEK_HEAD_CONTAINER(slist, __sl, __cn, __n)
128
129/*
130 * @brief Provide the primitive to peek container of the list tail
131 *
132 * @param __sl A pointer on a sys_slist_t to peek
133 * @param __cn Container struct type pointer
134 * @param __n The field name of sys_node_t within the container struct
135 */
136#define SYS_SLIST_PEEK_TAIL_CONTAINER(__sl, __cn, __n) \
137 Z_GENLIST_PEEK_TAIL_CONTAINER(slist, __sl, __cn, __n)
138
139/*
140 * @brief Provide the primitive to peek the next container
141 *
142 * @param __cn Container struct type pointer
143 * @param __n The field name of sys_node_t within the container struct
144 */
145#define SYS_SLIST_PEEK_NEXT_CONTAINER(__cn, __n) \
146 Z_GENLIST_PEEK_NEXT_CONTAINER(slist, __cn, __n)
147
162#define SYS_SLIST_FOR_EACH_CONTAINER(__sl, __cn, __n) \
163 Z_GENLIST_FOR_EACH_CONTAINER(slist, __sl, __cn, __n)
164
180#define SYS_SLIST_FOR_EACH_CONTAINER_SAFE(__sl, __cn, __cns, __n) \
181 Z_GENLIST_FOR_EACH_CONTAINER_SAFE(slist, __sl, __cn, __cns, __n)
182
183
184/*
185 * Required function definitions for the list_gen.h interface
186 *
187 * These are the only functions that do not treat the list/node pointers
188 * as completely opaque types.
189 */
190
196static inline void sys_slist_init(sys_slist_t *list)
197{
198 list->head = NULL;
199 list->tail = NULL;
200}
201
202#define SYS_SLIST_STATIC_INIT(ptr_to_list) {NULL, NULL}
203
204static inline sys_snode_t *z_snode_next_peek(sys_snode_t *node)
205{
206 return node->next;
207}
208
209static inline void z_snode_next_set(sys_snode_t *parent, sys_snode_t *child)
210{
211 parent->next = child;
212}
213
214static inline void z_slist_head_set(sys_slist_t *list, sys_snode_t *node)
215{
216 list->head = node;
217}
218
219static inline void z_slist_tail_set(sys_slist_t *list, sys_snode_t *node)
220{
221 list->tail = node;
222}
223
232{
233 return list->head;
234}
235
244{
245 return list->tail;
246}
247
248/*
249 * Derived, generated APIs
250 */
251
259static inline bool sys_slist_is_empty(sys_slist_t *list);
260
261Z_GENLIST_IS_EMPTY(slist)
262
263
273
274Z_GENLIST_PEEK_NEXT_NO_CHECK(slist, snode)
275
276
283static inline sys_snode_t *sys_slist_peek_next(sys_snode_t *node);
284
285Z_GENLIST_PEEK_NEXT(slist, snode)
286
287
295static inline void sys_slist_prepend(sys_slist_t *list,
296 sys_snode_t *node);
297
298Z_GENLIST_PREPEND(slist, snode)
299
300
308static inline void sys_slist_append(sys_slist_t *list,
309 sys_snode_t *node);
310
311Z_GENLIST_APPEND(slist, snode)
312
313
326static inline void sys_slist_append_list(sys_slist_t *list,
327 void *head, void *tail);
328
329Z_GENLIST_APPEND_LIST(slist, snode)
330
331
340static inline void sys_slist_merge_slist(sys_slist_t *list,
341 sys_slist_t *list_to_append);
342
343Z_GENLIST_MERGE_LIST(slist, snode)
344
345
354static inline void sys_slist_insert(sys_slist_t *list,
355 sys_snode_t *prev,
356 sys_snode_t *node);
357
358Z_GENLIST_INSERT(slist, snode)
359
360
371
372Z_GENLIST_GET_NOT_EMPTY(slist, snode)
373
374
383static inline sys_snode_t *sys_slist_get(sys_slist_t *list);
384
385Z_GENLIST_GET(slist, snode)
386
387
397static inline void sys_slist_remove(sys_slist_t *list,
398 sys_snode_t *prev_node,
399 sys_snode_t *node);
400
401Z_GENLIST_REMOVE(slist, snode)
402
403
413static inline bool sys_slist_find_and_remove(sys_slist_t *list,
414 sys_snode_t *node);
415
417Z_GENLIST_FIND_AND_REMOVE(slist, snode)
418
419#ifdef __cplusplus
420}
421#endif
422
423#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:372
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:343
static sys_snode_t * sys_slist_peek_head(sys_slist_t *list)
Peek the first node from the list.
Definition: slist.h:231
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:417
static sys_snode_t * sys_slist_get(sys_slist_t *list)
Fetch and remove the first node of the given list.
Definition: slist.h:385
static sys_snode_t * sys_slist_peek_tail(sys_slist_t *list)
Peek the last node from the list.
Definition: slist.h:243
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:274
static sys_snode_t * sys_slist_peek_next(sys_snode_t *node)
Peek the next node from current node.
Definition: slist.h:285
static bool sys_slist_is_empty(sys_slist_t *list)
Test if the given list is empty.
Definition: slist.h:261
static void sys_slist_append(sys_slist_t *list, sys_snode_t *node)
Append a node to the given list.
Definition: slist.h:311
static void sys_slist_init(sys_slist_t *list)
Initialize a list.
Definition: slist.h:196
static void sys_slist_append_list(sys_slist_t *list, void *head, void *tail)
Append a list to the given list.
Definition: slist.h:329
static void sys_slist_prepend(sys_slist_t *list, sys_snode_t *node)
Prepend a node to the given list.
Definition: slist.h:298
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:358
static void sys_slist_remove(sys_slist_t *list, sys_snode_t *prev_node, sys_snode_t *node)
Remove a node.
Definition: slist.h:401
struct _slist sys_slist_t
Definition: slist.h:40
struct _snode sys_snode_t
Definition: slist.h:33