Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
sflist.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
27
28#ifndef ZEPHYR_INCLUDE_SYS_SFLIST_H_
29#define ZEPHYR_INCLUDE_SYS_SFLIST_H_
30
31#include <stdint.h>
32#include <stdbool.h>
33#include <zephyr/sys/__assert.h>
34#include "list_gen.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
41/*
42 * Flag bits are stored in the low bits of the node address, so a node must be
43 * aligned to at least 4 bytes. Not every ABI gives uintptr_t that alignment
44 * naturally, so require it explicitly. See SYS_SFLIST_FLAGS_MASK below.
45 */
46struct _sfnode {
47 uintptr_t next_and_flags;
48} __aligned(sizeof(void *));
50
52typedef struct _sfnode sys_sfnode_t;
53
55struct _sflist {
56 sys_sfnode_t *head;
57 sys_sfnode_t *tail;
58};
60
62typedef struct _sflist sys_sflist_t;
63
79#define SYS_SFLIST_FOR_EACH_NODE(__sl, __sn) \
80 Z_GENLIST_FOR_EACH_NODE(sflist, __sl, __sn)
81
102#define SYS_SFLIST_ITERATE_FROM_NODE(__sl, __sn) \
103 Z_GENLIST_ITERATE_FROM_NODE(sflist, __sl, __sn)
104
121#define SYS_SFLIST_FOR_EACH_NODE_SAFE(__sl, __sn, __sns) \
122 Z_GENLIST_FOR_EACH_NODE_SAFE(sflist, __sl, __sn, __sns)
123
132#define SYS_SFLIST_CONTAINER(__ln, __cn, __n) \
133 Z_GENLIST_CONTAINER(__ln, __cn, __n)
134
142#define SYS_SFLIST_PEEK_HEAD_CONTAINER(__sl, __cn, __n) \
143 Z_GENLIST_PEEK_HEAD_CONTAINER(sflist, __sl, __cn, __n)
144
152#define SYS_SFLIST_PEEK_TAIL_CONTAINER(__sl, __cn, __n) \
153 Z_GENLIST_PEEK_TAIL_CONTAINER(sflist, __sl, __cn, __n)
154
161#define SYS_SFLIST_PEEK_NEXT_CONTAINER(__cn, __n) \
162 Z_GENLIST_PEEK_NEXT_CONTAINER(sflist, __cn, __n)
163
178#define SYS_SFLIST_FOR_EACH_CONTAINER(__sl, __cn, __n) \
179 Z_GENLIST_FOR_EACH_CONTAINER(sflist, __sl, __cn, __n)
180
196#define SYS_SFLIST_FOR_EACH_CONTAINER_SAFE(__sl, __cn, __cns, __n) \
197 Z_GENLIST_FOR_EACH_CONTAINER_SAFE(sflist, __sl, __cn, __cns, __n)
198
199
200/*
201 * Required function definitions for the list_gen.h interface
202 *
203 * These are the only functions that do not treat the list/node pointers
204 * as completely opaque types.
205 */
206
212static inline void sys_sflist_init(sys_sflist_t *list)
213{
214 list->head = NULL;
215 list->tail = NULL;
216}
217
222#define SYS_SFLIST_STATIC_INIT(ptr_to_list) {NULL, NULL}
223
224/* Flag bits are stored in unused LSB of the sys_sfnode_t pointer */
225#define SYS_SFLIST_FLAGS_MASK ((uintptr_t)(__alignof__(sys_sfnode_t) - 1))
226/* At least 2 available flag bits are expected */
227BUILD_ASSERT(SYS_SFLIST_FLAGS_MASK >= 0x3);
228
229static inline sys_sfnode_t *z_sfnode_next_peek(const sys_sfnode_t *node)
230{
231 return (sys_sfnode_t *)(node->next_and_flags & ~SYS_SFLIST_FLAGS_MASK);
232}
233
234static inline uint8_t sys_sfnode_flags_get(const sys_sfnode_t *node);
235
236static inline void z_sfnode_next_set(sys_sfnode_t *parent,
237 sys_sfnode_t *child)
238{
239 uint8_t cur_flags = sys_sfnode_flags_get(parent);
240
241 parent->next_and_flags = cur_flags | (uintptr_t)child;
242}
243
244static inline void z_sflist_head_set(sys_sflist_t *list, sys_sfnode_t *node)
245{
246 list->head = node;
247}
248
249static inline void z_sflist_tail_set(sys_sflist_t *list, sys_sfnode_t *node)
250{
251 list->tail = node;
252}
253
262{
263 return list->head;
264}
265
274{
275 return list->tail;
276}
277
278/*
279 * APIs specific to sflist type
280 */
281
289static inline uint8_t sys_sfnode_flags_get(const sys_sfnode_t *node)
290{
291 return node->next_and_flags & SYS_SFLIST_FLAGS_MASK;
292}
293
308static inline void sys_sfnode_init(sys_sfnode_t *node, uint8_t flags)
309{
310 __ASSERT((flags & ~SYS_SFLIST_FLAGS_MASK) == 0UL, "flags too large");
311 node->next_and_flags = flags;
312}
313
326{
327 __ASSERT((flags & ~SYS_SFLIST_FLAGS_MASK) == 0UL, "flags too large");
328 node->next_and_flags = (uintptr_t)(z_sfnode_next_peek(node)) | flags;
329}
330
331/*
332 * Derived, generated APIs
333 */
334
342static inline bool sys_sflist_is_empty(const sys_sflist_t *list);
343
344Z_GENLIST_IS_EMPTY(sflist)
345
346
356
357Z_GENLIST_PEEK_NEXT_NO_CHECK(sflist, sfnode)
358
359
366static inline sys_sfnode_t *sys_sflist_peek_next(const sys_sfnode_t *node);
367
368Z_GENLIST_PEEK_NEXT(sflist, sfnode)
369
370
378static inline void sys_sflist_prepend(sys_sflist_t *list,
379 sys_sfnode_t *node);
380
381Z_GENLIST_PREPEND(sflist, sfnode)
382
383
391static inline void sys_sflist_append(sys_sflist_t *list,
392 sys_sfnode_t *node);
393
394Z_GENLIST_APPEND(sflist, sfnode)
395
396
407static inline void sys_sflist_append_list(sys_sflist_t *list,
408 void *head, void *tail);
409
410Z_GENLIST_APPEND_LIST(sflist, sfnode)
411
412
421static inline void sys_sflist_merge_sflist(sys_sflist_t *list,
422 sys_sflist_t *list_to_append);
423
424Z_GENLIST_MERGE_LIST(sflist, sfnode)
425
426
435static inline void sys_sflist_insert(sys_sflist_t *list,
436 sys_sfnode_t *prev,
437 sys_sfnode_t *node);
438
439Z_GENLIST_INSERT(sflist, sfnode)
440
441
452
453Z_GENLIST_GET_NOT_EMPTY(sflist, sfnode)
454
455
464static inline sys_sfnode_t *sys_sflist_get(sys_sflist_t *list);
465
466Z_GENLIST_GET(sflist, sfnode)
467
468
478static inline void sys_sflist_remove(sys_sflist_t *list,
479 sys_sfnode_t *prev_node,
480 sys_sfnode_t *node);
481
482Z_GENLIST_REMOVE(sflist, sfnode)
483
484
494static inline bool sys_sflist_find_and_remove(sys_sflist_t *list,
495 sys_sfnode_t *node);
496
497Z_GENLIST_FIND_AND_REMOVE(sflist, sfnode)
498
499
506static inline size_t sys_sflist_len(const sys_sflist_t *list);
507
508Z_GENLIST_LEN(sflist, sfnode)
509
510
511
512#ifdef __cplusplus
513}
514#endif
515
516#endif /* ZEPHYR_INCLUDE_SYS_SFLIST_H_ */
struct _sfnode sys_sfnode_t
Flagged single-linked list node structure.
Definition sflist.h:52
static bool sys_sflist_is_empty(const sys_sflist_t *list)
Test if the given list is empty.
Definition sflist.h:344
static sys_sfnode_t * sys_sflist_get_not_empty(sys_sflist_t *list)
Fetch and remove the first node of the given list.
Definition sflist.h:453
static sys_sfnode_t * sys_sflist_get(sys_sflist_t *list)
Fetch and remove the first node of the given list.
Definition sflist.h:466
static sys_sfnode_t * sys_sflist_peek_next_no_check(const sys_sfnode_t *node)
Peek the next node from current node, node is not NULL.
Definition sflist.h:357
static size_t sys_sflist_len(const sys_sflist_t *list)
Compute the size of the given list in O(n) time.
Definition sflist.h:508
#define SYS_SFLIST_FLAGS_MASK
Definition sflist.h:225
static void sys_sflist_remove(sys_sflist_t *list, sys_sfnode_t *prev_node, sys_sfnode_t *node)
Remove a node.
Definition sflist.h:482
static void sys_sflist_merge_sflist(sys_sflist_t *list, sys_sflist_t *list_to_append)
merge two sflists, appending the second one to the first
Definition sflist.h:424
static void sys_sflist_append(sys_sflist_t *list, sys_sfnode_t *node)
Append a node to the given list.
Definition sflist.h:394
static void sys_sflist_prepend(sys_sflist_t *list, sys_sfnode_t *node)
Prepend a node to the given list.
Definition sflist.h:381
static void sys_sfnode_flags_set(sys_sfnode_t *node, uint8_t flags)
Set flags value for an sflist node.
Definition sflist.h:325
static void sys_sflist_insert(sys_sflist_t *list, sys_sfnode_t *prev, sys_sfnode_t *node)
Insert a node to the given list.
Definition sflist.h:439
static sys_sfnode_t * sys_sflist_peek_tail(const sys_sflist_t *list)
Peek the last node from the list.
Definition sflist.h:273
static void sys_sflist_init(sys_sflist_t *list)
Initialize a list.
Definition sflist.h:212
struct _sflist sys_sflist_t
Flagged single-linked list structure.
Definition sflist.h:62
static sys_sfnode_t * sys_sflist_peek_head(const sys_sflist_t *list)
Peek the first node from the list.
Definition sflist.h:261
static sys_sfnode_t * sys_sflist_peek_next(const sys_sfnode_t *node)
Peek the next node from current node.
Definition sflist.h:368
static void sys_sflist_append_list(sys_sflist_t *list, void *head, void *tail)
Append a list to the given list.
Definition sflist.h:410
static uint8_t sys_sfnode_flags_get(const sys_sfnode_t *node)
Fetch flags value for a particular sfnode.
Definition sflist.h:289
static bool sys_sflist_find_and_remove(sys_sflist_t *list, sys_sfnode_t *node)
Find and remove a node from a list.
Definition sflist.h:497
static void sys_sfnode_init(sys_sfnode_t *node, uint8_t flags)
Initialize an sflist node.
Definition sflist.h:308
Internal generic linked-list macro generators shared by slist/dlist/sflist.
flags
Definition parser.h:97
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105