Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
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
17#ifndef ZEPHYR_INCLUDE_SYS_SFLIST_H_
18#define ZEPHYR_INCLUDE_SYS_SFLIST_H_
19
20#include <stddef.h>
21#include <stdbool.h>
22#include <sys/__assert.h>
23#include "list_gen.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29#ifdef __LP64__
30typedef uint64_t unative_t;
31#else
33#endif
34
35struct _sfnode {
36 unative_t next_and_flags;
37};
38
39typedef struct _sfnode sys_sfnode_t;
40
41struct _sflist {
42 sys_sfnode_t *head;
43 sys_sfnode_t *tail;
44};
45
46typedef struct _sflist sys_sflist_t;
47
69#define SYS_SFLIST_FOR_EACH_NODE(__sl, __sn) \
70 Z_GENLIST_FOR_EACH_NODE(sflist, __sl, __sn)
71
92#define SYS_SFLIST_ITERATE_FROM_NODE(__sl, __sn) \
93 Z_GENLIST_ITERATE_FROM_NODE(sflist, __sl, __sn)
94
111#define SYS_SFLIST_FOR_EACH_NODE_SAFE(__sl, __sn, __sns) \
112 Z_GENLIST_FOR_EACH_NODE_SAFE(sflist, __sl, __sn, __sns)
113
114/*
115 * @brief Provide the primitive to resolve the container of a list node
116 * Note: it is safe to use with NULL pointer nodes
117 *
118 * @param __ln A pointer on a sys_sfnode_t to get its container
119 * @param __cn Container struct type pointer
120 * @param __n The field name of sys_sfnode_t within the container struct
121 */
122#define SYS_SFLIST_CONTAINER(__ln, __cn, __n) \
123 Z_GENLIST_CONTAINER(__ln, __cn, __n)
124
125/*
126 * @brief Provide the primitive to peek container of the list head
127 *
128 * @param __sl A pointer on a sys_sflist_t to peek
129 * @param __cn Container struct type pointer
130 * @param __n The field name of sys_sfnode_t within the container struct
131 */
132#define SYS_SFLIST_PEEK_HEAD_CONTAINER(__sl, __cn, __n) \
133 Z_GENLIST_PEEK_HEAD_CONTAINER(sflist, __sl, __cn, __n)
134
135/*
136 * @brief Provide the primitive to peek container of the list tail
137 *
138 * @param __sl A pointer on a sys_sflist_t to peek
139 * @param __cn Container struct type pointer
140 * @param __n The field name of sys_sfnode_t within the container struct
141 */
142#define SYS_SFLIST_PEEK_TAIL_CONTAINER(__sl, __cn, __n) \
143 Z_GENLIST_PEEK_TAIL_CONTAINER(sflist, __sl, __cn, __n)
144
145/*
146 * @brief Provide the primitive to peek the next container
147 *
148 * @param __cn Container struct type pointer
149 * @param __n The field name of sys_sfnode_t within the container struct
150 */
151#define SYS_SFLIST_PEEK_NEXT_CONTAINER(__cn, __n) \
152 Z_GENLIST_PEEK_NEXT_CONTAINER(sflist, __cn, __n)
153
168#define SYS_SFLIST_FOR_EACH_CONTAINER(__sl, __cn, __n) \
169 Z_GENLIST_FOR_EACH_CONTAINER(sflist, __sl, __cn, __n)
170
186#define SYS_SFLIST_FOR_EACH_CONTAINER_SAFE(__sl, __cn, __cns, __n) \
187 Z_GENLIST_FOR_EACH_CONTAINER_SAFE(sflist, __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_sflist_init(sys_sflist_t *list)
203{
204 list->head = NULL;
205 list->tail = NULL;
206}
207
208#define SYS_SFLIST_STATIC_INIT(ptr_to_list) {NULL, NULL}
209#define SYS_SFLIST_FLAGS_MASK 0x3UL
210
211static inline sys_sfnode_t *z_sfnode_next_peek(sys_sfnode_t *node)
212{
213 return (sys_sfnode_t *)(node->next_and_flags & ~SYS_SFLIST_FLAGS_MASK);
214}
215
216static inline uint8_t sys_sfnode_flags_get(sys_sfnode_t *node);
217
218static inline void z_sfnode_next_set(sys_sfnode_t *parent,
219 sys_sfnode_t *child)
220{
221 uint8_t cur_flags = sys_sfnode_flags_get(parent);
222
223 parent->next_and_flags = cur_flags | (unative_t)child;
224}
225
226static inline void z_sflist_head_set(sys_sflist_t *list, sys_sfnode_t *node)
227{
228 list->head = node;
229}
230
231static inline void z_sflist_tail_set(sys_sflist_t *list, sys_sfnode_t *node)
232{
233 list->tail = node;
234}
235
244{
245 return list->head;
246}
247
256{
257 return list->tail;
258}
259
260/*
261 * APIs specific to sflist type
262 */
263
271{
272 return node->next_and_flags & SYS_SFLIST_FLAGS_MASK;
273}
274
288static inline void sys_sfnode_init(sys_sfnode_t *node, uint8_t flags)
289{
290 __ASSERT((flags & ~SYS_SFLIST_FLAGS_MASK) == 0UL, "flags too large");
291 node->next_and_flags = flags;
292}
293
305{
306 __ASSERT((flags & ~SYS_SFLIST_FLAGS_MASK) == 0UL, "flags too large");
307 node->next_and_flags = (unative_t)(z_sfnode_next_peek(node)) | flags;
308}
309
310/*
311 * Derived, generated APIs
312 */
313
321static inline bool sys_sflist_is_empty(sys_sflist_t *list);
322
323Z_GENLIST_IS_EMPTY(sflist)
324
325
335
336Z_GENLIST_PEEK_NEXT_NO_CHECK(sflist, sfnode)
337
338
346
347Z_GENLIST_PEEK_NEXT(sflist, sfnode)
348
349
357static inline void sys_sflist_prepend(sys_sflist_t *list,
358 sys_sfnode_t *node);
359
360Z_GENLIST_PREPEND(sflist, sfnode)
361
362
370static inline void sys_sflist_append(sys_sflist_t *list,
371 sys_sfnode_t *node);
372
373Z_GENLIST_APPEND(sflist, sfnode)
374
375
388static inline void sys_sflist_append_list(sys_sflist_t *list,
389 void *head, void *tail);
390
391Z_GENLIST_APPEND_LIST(sflist, sfnode)
392
393
402static inline void sys_sflist_merge_sflist(sys_sflist_t *list,
403 sys_sflist_t *list_to_append);
404
405Z_GENLIST_MERGE_LIST(sflist, sfnode)
406
407
416static inline void sys_sflist_insert(sys_sflist_t *list,
417 sys_sfnode_t *prev,
418 sys_sfnode_t *node);
419
420Z_GENLIST_INSERT(sflist, sfnode)
421
422
433
434Z_GENLIST_GET_NOT_EMPTY(sflist, sfnode)
435
436
445static inline sys_sfnode_t *sys_sflist_get(sys_sflist_t *list);
446
447Z_GENLIST_GET(sflist, sfnode)
448
449
459static inline void sys_sflist_remove(sys_sflist_t *list,
460 sys_sfnode_t *prev_node,
461 sys_sfnode_t *node);
462
463Z_GENLIST_REMOVE(sflist, sfnode)
464
465
475static inline bool sys_sflist_find_and_remove(sys_sflist_t *list,
476 sys_sfnode_t *node);
477
478Z_GENLIST_FIND_AND_REMOVE(sflist, sfnode)
479
480
482#ifdef __cplusplus
483}
484#endif
485
486#endif /* ZEPHYR_INCLUDE_SYS_SFLIST_H_ */
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:434
static uint8_t sys_sfnode_flags_get(sys_sfnode_t *node)
Fetch flags value for a particular sfnode.
Definition: sflist.h:270
static sys_sfnode_t * sys_sflist_get(sys_sflist_t *list)
Fetch and remove the first node of the given list.
Definition: sflist.h:447
#define SYS_SFLIST_FLAGS_MASK
Definition: sflist.h:209
static sys_sfnode_t * sys_sflist_peek_next(sys_sfnode_t *node)
Peek the next node from current node.
Definition: sflist.h:347
static void sys_sflist_remove(sys_sflist_t *list, sys_sfnode_t *prev_node, sys_sfnode_t *node)
Remove a node.
Definition: sflist.h:463
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:405
static sys_sfnode_t * sys_sflist_peek_head(sys_sflist_t *list)
Peek the first node from the list.
Definition: sflist.h:243
static void sys_sflist_append(sys_sflist_t *list, sys_sfnode_t *node)
Append a node to the given list.
Definition: sflist.h:373
static void sys_sflist_prepend(sys_sflist_t *list, sys_sfnode_t *node)
Prepend a node to the given list.
Definition: sflist.h:360
static void sys_sfnode_flags_set(sys_sfnode_t *node, uint8_t flags)
Set flags value for an sflist node.
Definition: sflist.h:304
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:420
static void sys_sflist_init(sys_sflist_t *list)
Initialize a list.
Definition: sflist.h:202
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:336
static void sys_sflist_append_list(sys_sflist_t *list, void *head, void *tail)
Append a list to the given list.
Definition: sflist.h:391
static sys_sfnode_t * sys_sflist_peek_tail(sys_sflist_t *list)
Peek the last node from the list.
Definition: sflist.h:255
static bool sys_sflist_is_empty(sys_sflist_t *list)
Test if the given list is empty.
Definition: sflist.h:323
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:478
static void sys_sfnode_init(sys_sfnode_t *node, uint8_t flags)
Initialize an sflist node.
Definition: sflist.h:288
flags
Definition: http_parser.h:131
struct _sfnode sys_sfnode_t
Definition: sflist.h:39
uint32_t unative_t
Definition: sflist.h:32
struct _sflist sys_sflist_t
Definition: sflist.h:46
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__UINT64_TYPE__ uint64_t
Definition: stdint.h:61
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58