Morse Micro IoT SDK  2.10.4
mmpkt_list.h
1/*
2 * Copyright 2022-2024 Morse Micro
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
13#pragma once
14
15#include <stddef.h>
16
17#include "mmpkt.h"
18
19#ifdef __cplusplus
20extern "C"
21{
22#endif
23
26{
28 struct mmpkt *volatile head;
30 struct mmpkt *volatile tail;
32 volatile uint32_t len;
33};
34
36#define MMPKT_LIST_INIT { NULL, NULL, 0 }
37
44static inline void mmpkt_list_init(struct mmpkt_list *list)
45{
46 list->head = NULL;
47 list->tail = NULL;
48 list->len = 0;
49}
50
58static inline uint32_t mmpkt_list_length(struct mmpkt_list *list)
59{
60 return list->len;
61}
62
69void mmpkt_list_prepend(struct mmpkt_list *list, struct mmpkt *mmpkt);
70
77void mmpkt_list_append(struct mmpkt_list *list, struct mmpkt *mmpkt);
78
86void mmpkt_list_insert_after(struct mmpkt_list *list, struct mmpkt *ref, struct mmpkt *mmpkt);
87
94void mmpkt_list_remove(struct mmpkt_list *list, struct mmpkt *mmpkt);
95
103struct mmpkt *mmpkt_list_dequeue(struct mmpkt_list *list);
104
112struct mmpkt *mmpkt_list_dequeue_tail(struct mmpkt_list *list);
113
121static inline struct mmpkt *mmpkt_list_dequeue_all(struct mmpkt_list *list)
122{
123 struct mmpkt *head = list->head;
124 list->head = NULL;
125 list->tail = NULL;
126 list->len = 0;
127 return head;
128}
129
137static inline bool mmpkt_list_is_empty(struct mmpkt_list *list)
138{
139 return (list->head == NULL);
140}
141
149static inline struct mmpkt *mmpkt_list_peek(struct mmpkt_list *list)
150{
151 return list->head;
152}
153
161static inline struct mmpkt *mmpkt_list_peek_tail(struct mmpkt_list *list)
162{
163 return list->tail;
164}
165
171void mmpkt_list_clear(struct mmpkt_list *list);
172
181void mmpkt_list_append_list(struct mmpkt_list *list, struct mmpkt_list *other);
182
191#define MMPKT_LIST_WALK(_lst, _wlk, _nxt) \
192 if ((_lst)->head != NULL) /* NOLINT(readability/braces) */ \
193 for (_wlk = (_lst)->head, _nxt = mmpkt_get_next(_wlk); _wlk != NULL; \
194 _wlk = _nxt, _nxt = _wlk ? mmpkt_get_next(_wlk) : NULL)
195
196#ifdef __cplusplus
197}
198#endif
199
Structure that can be used as the head of a linked list of mmpkts that counts its length.
Definition: mmpkt_list.h:26
struct mmpkt *volatile tail
Last mmpkt in the list.
Definition: mmpkt_list.h:30
volatile uint32_t len
Length of the list.
Definition: mmpkt_list.h:32
struct mmpkt *volatile head
First mmpkt in the list.
Definition: mmpkt_list.h:28