Morse Micro IoT SDK  2.6.4-esp32
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#endif
22
25{
27 struct mmpkt *volatile head;
29 struct mmpkt *volatile tail;
31 volatile uint32_t len;
32};
33
35#define MMPKT_LIST_INIT { NULL, NULL, 0 }
36
43static inline void mmpkt_list_init(struct mmpkt_list *list)
44{
45 list->head = NULL;
46 list->tail = NULL;
47 list->len = 0;
48}
49
56void mmpkt_list_prepend(struct mmpkt_list *list, struct mmpkt *mmpkt);
57
64void mmpkt_list_append(struct mmpkt_list *list, struct mmpkt *mmpkt);
65
72void mmpkt_list_remove(struct mmpkt_list *list, struct mmpkt *mmpkt);
73
81struct mmpkt *mmpkt_list_dequeue(struct mmpkt_list *list);
82
90struct mmpkt *mmpkt_list_dequeue_tail(struct mmpkt_list *list);
91
99static inline struct mmpkt *mmpkt_list_dequeue_all(struct mmpkt_list *list)
100{
101 struct mmpkt *head = list->head;
102 list->head = NULL;
103 list->tail = NULL;
104 list->len = 0;
105 return head;
106}
107
115static inline bool mmpkt_list_is_empty(struct mmpkt_list *list)
116{
117 return (list->head == NULL);
118}
119
127static inline struct mmpkt *mmpkt_list_peek(struct mmpkt_list *list)
128{
129 return list->head;
130}
131
139static inline struct mmpkt *mmpkt_list_peek_tail(struct mmpkt_list *list)
140{
141 return list->tail;
142}
143
149void mmpkt_list_clear(struct mmpkt_list *list);
150
159#define MMPKT_LIST_WALK(_lst, _wlk, _nxt) \
160 if ((_lst)->head != NULL) /* NOLINT(readability/braces) */ \
161 for (_wlk = (_lst)->head, _nxt = mmpkt_get_next(_wlk); \
162 _wlk != NULL; \
163 _wlk = _nxt, _nxt = _wlk ? mmpkt_get_next(_wlk) : NULL)
164
165#ifdef __cplusplus
166}
167#endif
168
Structure that can be used as the head of a linked list of mmpkts that counts its length.
Definition: mmpkt_list.h:25
struct mmpkt *volatile tail
Last mmpkt in the list.
Definition: mmpkt_list.h:29
volatile uint32_t len
Length of the list.
Definition: mmpkt_list.h:31
struct mmpkt *volatile head
First mmpkt in the list.
Definition: mmpkt_list.h:27
Core mmpkt data structure.
Definition: mmpkt.h:79