Zephyr API Documentation 4.0.0
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
25#ifndef ZEPHYR_INCLUDE_SYS_SFLIST_H_
26#define ZEPHYR_INCLUDE_SYS_SFLIST_H_
27
28#include <stdint.h>
29#include <stdbool.h>
30#include <zephyr/sys/__assert.h>
31#include "list_gen.h"
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
38struct _sfnode {
39 uintptr_t next_and_flags;
40};
44typedef struct _sfnode sys_sfnode_t;
45
47struct _sflist {
48 sys_sfnode_t *head;
49 sys_sfnode_t *tail;
50};
54typedef struct _sflist sys_sflist_t;
55
71#define SYS_SFLIST_FOR_EACH_NODE(__sl, __sn) \
72 Z_GENLIST_FOR_EACH_NODE(sflist, __sl, __sn)
73
94#define SYS_SFLIST_ITERATE_FROM_NODE(__sl, __sn) \
95 Z_GENLIST_ITERATE_FROM_NODE(sflist, __sl, __sn)
96
113#define SYS_SFLIST_FOR_EACH_NODE_SAFE(__sl, __sn, __sns) \
114 Z_GENLIST_FOR_EACH_NODE_SAFE(sflist, __sl, __sn, __sns)
115
124#define SYS_SFLIST_CONTAINER(__ln, __cn, __n) \
125 Z_GENLIST_CONTAINER(__ln, __cn, __n)
126
134#define SYS_SFLIST_PEEK_HEAD_CONTAINER(__sl, __cn, __n) \
135 Z_GENLIST_PEEK_HEAD_CONTAINER(sflist, __sl, __cn, __n)
136
144#define SYS_SFLIST_PEEK_TAIL_CONTAINER(__sl, __cn, __n) \
145 Z_GENLIST_PEEK_TAIL_CONTAINER(sflist, __sl, __cn, __n)
146
153#define SYS_SFLIST_PEEK_NEXT_CONTAINER(__cn, __n) \
154 Z_GENLIST_PEEK_NEXT_CONTAINER(sflist, __cn, __n)
155
170#define SYS_SFLIST_FOR_EACH_CONTAINER(__sl, __cn, __n) \
171 Z_GENLIST_FOR_EACH_CONTAINER(sflist, __sl, __cn, __n)
172
188#define SYS_SFLIST_FOR_EACH_CONTAINER_SAFE(__sl, __cn, __cns, __n) \
189 Z_GENLIST_FOR_EACH_CONTAINER_SAFE(sflist, __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_sflist_init(sys_sflist_t *list)
205{
206 list->head = NULL;
207 list->tail = NULL;
208}
209
214#define SYS_SFLIST_STATIC_INIT(ptr_to_list) {NULL, NULL}
215
216/* Flag bits are stored in unused LSB of the sys_sfnode_t pointer */
217#define SYS_SFLIST_FLAGS_MASK ((uintptr_t)(__alignof__(sys_sfnode_t) - 1))
218/* At least 2 available flag bits are expected */
219BUILD_ASSERT(SYS_SFLIST_FLAGS_MASK >= 0x3);
220
221static inline sys_sfnode_t *z_sfnode_next_peek(sys_sfnode_t *node)
222{
223 return (sys_sfnode_t *)(node->next_and_flags & ~SYS_SFLIST_FLAGS_MASK);
224}
225
226static inline uint8_t sys_sfnode_flags_get(sys_sfnode_t *node);
227
228static inline void z_sfnode_next_set(sys_sfnode_t *parent,
229 sys_sfnode_t *child)
230{
231 uint8_t cur_flags = sys_sfnode_flags_get(parent);
232
233 parent->next_and_flags = cur_flags | (uintptr_t)child;
234}
235
236static inline void z_sflist_head_set(sys_sflist_t *list, sys_sfnode_t *node)
237{
238 list->head = node;
239}
240
241static inline void z_sflist_tail_set(sys_sflist_t *list, sys_sfnode_t *node)
242{
243 list->tail = node;
244}
245
254{
255 return list->head;
256}
257
266{
267 return list->tail;
268}
269
270/*
271 * APIs specific to sflist type
272 */
273
282{
283 return node->next_and_flags & SYS_SFLIST_FLAGS_MASK;
284}
285
300static inline void sys_sfnode_init(sys_sfnode_t *node, uint8_t flags)
301{
302 __ASSERT((flags & ~SYS_SFLIST_FLAGS_MASK) == 0UL, "flags too large");
303 node->next_and_flags = flags;
304}
305
318{
319 __ASSERT((flags & ~SYS_SFLIST_FLAGS_MASK) == 0UL, "flags too large");
320 node->next_and_flags = (uintptr_t)(z_sfnode_next_peek(node)) | flags;
321}
322
323/*
324 * Derived, generated APIs
325 */
326
334static inline bool sys_sflist_is_empty(sys_sflist_t *list);
335
336Z_GENLIST_IS_EMPTY(sflist)
337
338
348
349Z_GENLIST_PEEK_NEXT_NO_CHECK(sflist, sfnode)
350
351
359
360Z_GENLIST_PEEK_NEXT(sflist, sfnode)
361
362
370static inline void sys_sflist_prepend(sys_sflist_t *list,
371 sys_sfnode_t *node);
372
373Z_GENLIST_PREPEND(sflist, sfnode)
374
375
383static inline void sys_sflist_append(sys_sflist_t *list,
384 sys_sfnode_t *node);
385
386Z_GENLIST_APPEND(sflist, sfnode)
387
388
401static inline void sys_sflist_append_list(sys_sflist_t *list,
402 void *head, void *tail);
403
404Z_GENLIST_APPEND_LIST(sflist, sfnode)
405
406
415static inline void sys_sflist_merge_sflist(sys_sflist_t *list,
416 sys_sflist_t *list_to_append);
417
418Z_GENLIST_MERGE_LIST(sflist, sfnode)
419
420
429static inline void sys_sflist_insert(sys_sflist_t *list,
430 sys_sfnode_t *prev,
431 sys_sfnode_t *node);
432
433Z_GENLIST_INSERT(sflist, sfnode)
434
435
446
447Z_GENLIST_GET_NOT_EMPTY(sflist, sfnode)
448
449
458static inline sys_sfnode_t *sys_sflist_get(sys_sflist_t *list);
459
460Z_GENLIST_GET(sflist, sfnode)
461
462
472static inline void sys_sflist_remove(sys_sflist_t *list,
473 sys_sfnode_t *prev_node,
474 sys_sfnode_t *node);
475
476Z_GENLIST_REMOVE(sflist, sfnode)
477
478
488static inline bool sys_sflist_find_and_remove(sys_sflist_t *list,
489 sys_sfnode_t *node);
490
491Z_GENLIST_FIND_AND_REMOVE(sflist, sfnode)
492
493
500static inline size_t sys_sflist_len(sys_sflist_t *list);
501
502Z_GENLIST_LEN(sflist, sfnode)
503
504
506#ifdef __cplusplus
507}
508#endif
509
510#endif /* ZEPHYR_INCLUDE_SYS_SFLIST_H_ */
struct _sfnode sys_sfnode_t
Flagged single-linked list node structure.
Definition sflist.h:44
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:447
static uint8_t sys_sfnode_flags_get(sys_sfnode_t *node)
Fetch flags value for a particular sfnode.
Definition sflist.h:281
static sys_sfnode_t * sys_sflist_get(sys_sflist_t *list)
Fetch and remove the first node of the given list.
Definition sflist.h:460
#define SYS_SFLIST_FLAGS_MASK
Definition sflist.h:217
static sys_sfnode_t * sys_sflist_peek_next(sys_sfnode_t *node)
Peek the next node from current node.
Definition sflist.h:360
static void sys_sflist_remove(sys_sflist_t *list, sys_sfnode_t *prev_node, sys_sfnode_t *node)
Remove a node.
Definition sflist.h:476
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:418
static sys_sfnode_t * sys_sflist_peek_head(sys_sflist_t *list)
Peek the first node from the list.
Definition sflist.h:253
static void sys_sflist_append(sys_sflist_t *list, sys_sfnode_t *node)
Append a node to the given list.
Definition sflist.h:386
static void sys_sflist_prepend(sys_sflist_t *list, sys_sfnode_t *node)
Prepend a node to the given list.
Definition sflist.h:373
static void sys_sfnode_flags_set(sys_sfnode_t *node, uint8_t flags)
Set flags value for an sflist node.
Definition sflist.h:317
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:433
static void sys_sflist_init(sys_sflist_t *list)
Initialize a list.
Definition sflist.h:204
struct _sflist sys_sflist_t
Flagged single-linked list structure.
Definition sflist.h:54
static size_t sys_sflist_len(sys_sflist_t *list)
Compute the size of the given list in O(n) time.
Definition sflist.h:502
static sys_sfnode_t * sys_sflist_peek_next_no_check(sys_sfnode_t *node)
Peek the next node from current node, node is not NULL.
Definition sflist.h:349
static void sys_sflist_append_list(sys_sflist_t *list, void *head, void *tail)
Append a list to the given list.
Definition sflist.h:404
static sys_sfnode_t * sys_sflist_peek_tail(sys_sflist_t *list)
Peek the last node from the list.
Definition sflist.h:265
static bool sys_sflist_is_empty(sys_sflist_t *list)
Test if the given list is empty.
Definition sflist.h:336
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:491
static void sys_sfnode_init(sys_sfnode_t *node, uint8_t flags)
Initialize an sflist node.
Definition sflist.h:300
flags
Definition parser.h:96
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105