Zephyr Project API 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
24
25#ifndef ZEPHYR_INCLUDE_SYS_SLIST_H_
26#define ZEPHYR_INCLUDE_SYS_SLIST_H_
27
28#include <stddef.h>
29#include <stdbool.h>
30#include "list_gen.h"
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36
38struct _snode {
39 struct _snode *next;
40};
42
44typedef struct _snode sys_snode_t;
45
47struct _slist {
48 sys_snode_t *head;
49 sys_snode_t *tail;
50};
52
54typedef struct _slist sys_slist_t;
55
71#define SYS_SLIST_FOR_EACH_NODE(__sl, __sn) \
72 Z_GENLIST_FOR_EACH_NODE(slist, __sl, __sn)
73
94#define SYS_SLIST_ITERATE_FROM_NODE(__sl, __sn) \
95 Z_GENLIST_ITERATE_FROM_NODE(slist, __sl, __sn)
96
113#define SYS_SLIST_FOR_EACH_NODE_SAFE(__sl, __sn, __sns) \
114 Z_GENLIST_FOR_EACH_NODE_SAFE(slist, __sl, __sn, __sns)
115
124#define SYS_SLIST_CONTAINER(__ln, __cn, __n) \
125 Z_GENLIST_CONTAINER(__ln, __cn, __n)
126
134#define SYS_SLIST_PEEK_HEAD_CONTAINER(__sl, __cn, __n) \
135 Z_GENLIST_PEEK_HEAD_CONTAINER(slist, __sl, __cn, __n)
136
144#define SYS_SLIST_PEEK_TAIL_CONTAINER(__sl, __cn, __n) \
145 Z_GENLIST_PEEK_TAIL_CONTAINER(slist, __sl, __cn, __n)
146
153#define SYS_SLIST_PEEK_NEXT_CONTAINER(__cn, __n) \
154 Z_GENLIST_PEEK_NEXT_CONTAINER(slist, __cn, __n)
155
170#define SYS_SLIST_FOR_EACH_CONTAINER(__sl, __cn, __n) \
171 Z_GENLIST_FOR_EACH_CONTAINER(slist, __sl, __cn, __n)
172
188#define SYS_SLIST_FOR_EACH_CONTAINER_SAFE(__sl, __cn, __cns, __n) \
189 Z_GENLIST_FOR_EACH_CONTAINER_SAFE(slist, __sl, __cn, __cns, __n)
190
191
192/*
193 * Required function definitions for the list_gen.h interface
194 *
195 * These are the only functions that do not treat the list/node pointers
196 * as completely opaque types.
197 */
198
204static inline void sys_slist_init(sys_slist_t *list)
205{
206 list->head = NULL;
207 list->tail = NULL;
208}
209
214#define SYS_SLIST_STATIC_INIT(ptr_to_list) {NULL, NULL}
215
216static inline sys_snode_t *z_snode_next_peek(const sys_snode_t *node)
217{
218 return node->next;
219}
220
221static inline void z_snode_next_set(sys_snode_t *parent, sys_snode_t *child)
222{
223 parent->next = child;
224}
225
226static inline void z_slist_head_set(sys_slist_t *list, sys_snode_t *node)
227{
228 list->head = node;
229}
230
231static inline void z_slist_tail_set(sys_slist_t *list, sys_snode_t *node)
232{
233 list->tail = node;
234}
235
243static inline sys_snode_t *sys_slist_peek_head(const sys_slist_t *list)
244{
245 return list->head;
246}
247
255static inline sys_snode_t *sys_slist_peek_tail(const sys_slist_t *list)
256{
257 return list->tail;
258}
259
260/*
261 * Derived, generated APIs
262 */
263
271static inline bool sys_slist_is_empty(const sys_slist_t *list);
272
273Z_GENLIST_IS_EMPTY(slist)
274
275
284static inline sys_snode_t *sys_slist_peek_next_no_check(const sys_snode_t *node);
285
286Z_GENLIST_PEEK_NEXT_NO_CHECK(slist, snode)
287
288
295static inline sys_snode_t *sys_slist_peek_next(const sys_snode_t *node);
296
297Z_GENLIST_PEEK_NEXT(slist, snode)
298
299
307static inline void sys_slist_prepend(sys_slist_t *list,
308 sys_snode_t *node);
309
310Z_GENLIST_PREPEND(slist, snode)
311
312
320static inline void sys_slist_append(sys_slist_t *list,
321 sys_snode_t *node);
322
323Z_GENLIST_APPEND(slist, snode)
324
325
336static inline void sys_slist_append_list(sys_slist_t *list,
337 void *head, void *tail);
338
339Z_GENLIST_APPEND_LIST(slist, snode)
340
341
350static inline void sys_slist_merge_slist(sys_slist_t *list,
351 sys_slist_t *list_to_append);
352
353Z_GENLIST_MERGE_LIST(slist, snode)
354
355
364static inline void sys_slist_insert(sys_slist_t *list,
365 sys_snode_t *prev,
366 sys_snode_t *node);
367
368Z_GENLIST_INSERT(slist, snode)
369
370
381
382Z_GENLIST_GET_NOT_EMPTY(slist, snode)
383
384
393static inline sys_snode_t *sys_slist_get(sys_slist_t *list);
394
395Z_GENLIST_GET(slist, snode)
396
397
407static inline void sys_slist_remove(sys_slist_t *list,
408 sys_snode_t *prev_node,
409 sys_snode_t *node);
410
411Z_GENLIST_REMOVE(slist, snode)
412
413
423static inline bool sys_slist_find_and_remove(sys_slist_t *list,
424 sys_snode_t *node);
425
437static inline bool sys_slist_find(const sys_slist_t *list, const sys_snode_t *node,
438 sys_snode_t **prev);
439Z_GENLIST_FIND(slist, snode)
440
441
448static inline size_t sys_slist_len(const sys_slist_t *list);
449
450Z_GENLIST_LEN(slist, snode)
451
452
453Z_GENLIST_FIND_AND_REMOVE(slist, snode)
454
455#ifdef __cplusplus
456}
457#endif
458
459#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:382
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:353
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:286
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:439
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:453
struct _slist sys_slist_t
Single-linked list structure.
Definition slist.h:54
static sys_snode_t * sys_slist_get(sys_slist_t *list)
Fetch and remove the first node of the given list.
Definition slist.h:395
static sys_snode_t * sys_slist_peek_tail(const sys_slist_t *list)
Peek the last node from the list.
Definition slist.h:255
static sys_snode_t * sys_slist_peek_head(const sys_slist_t *list)
Peek the first node from the list.
Definition slist.h:243
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:44
static void sys_slist_append(sys_slist_t *list, sys_snode_t *node)
Append a node to the given list.
Definition slist.h:323
static void sys_slist_init(sys_slist_t *list)
Initialize a list.
Definition slist.h:204
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:450
static void sys_slist_append_list(sys_slist_t *list, void *head, void *tail)
Append a list to the given list.
Definition slist.h:339
static sys_snode_t * sys_slist_peek_next(const sys_snode_t *node)
Peek the next node from current node.
Definition slist.h:297
static void sys_slist_prepend(sys_slist_t *list, sys_snode_t *node)
Prepend a node to the given list.
Definition slist.h:310
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:368
static void sys_slist_remove(sys_slist_t *list, sys_snode_t *prev_node, sys_snode_t *node)
Remove a node.
Definition slist.h:411
static bool sys_slist_is_empty(const sys_slist_t *list)
Test if the given list is empty.
Definition slist.h:273
#define NULL
Definition iar_missing_defs.h:20
Internal generic linked-list macro generators shared by slist/dlist/sflist.