AM263Px MCU+ SDK: ub_llist.h Source File

| AM263Px MCU+ SDK 26.00.00 |

ub_llist.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2023 Texas Instruments Incorporated
3 * Copyright (c) 2023 Excelfore Corporation (https://excelfore.com)
4 *
5 * All rights reserved not granted herein.
6 * Limited License.
7 *
8 * Texas Instruments Incorporated grants a world-wide, royalty-free,
9 * non-exclusive license under copyrights and patents it now or hereafter
10 * owns or controls to make, have made, use, import, offer to sell and sell ("Utilize")
11 * this software subject to the terms herein. With respect to the foregoing patent
12 * license, such license is granted solely to the extent that any such patent is necessary
13 * to Utilize the software alone. The patent license shall not apply to any combinations which
14 * include this software, other than combinations with devices manufactured by or for TI ("TI Devices").
15 * No hardware patent is licensed hereunder.
16 *
17 * Redistributions must preserve existing copyright notices and reproduce this license (including the
18 * above copyright notice and the disclaimer and (if applicable) source code license limitations below)
19 * in the documentation and/or other materials provided with the distribution
20 *
21 * Redistribution and use in binary form, without modification, are permitted provided that the following
22 * conditions are met:
23 *
24 * * No reverse engineering, decompilation, or disassembly of this software is permitted with respect to any
25 * software provided in binary form.
26 * * any redistribution and use are licensed by TI for use only with TI Devices.
27 * * Nothing shall obligate TI to provide you with source code for the software licensed and provided to you in object code.
28 *
29 * If software source code is provided to you, modification and redistribution of the source code are permitted
30 * provided that the following conditions are met:
31 *
32 * * any redistribution and use of the source code, including any resulting derivative works, are licensed by
33 * TI for use only with TI Devices.
34 * * any redistribution and use of any object code compiled from the source code and any resulting derivative
35 * works, are licensed by TI for use only with TI Devices.
36 *
37 * Neither the name of Texas Instruments Incorporated nor the names of its suppliers may be used to endorse or
38 * promote products derived from this software without specific prior written permission.
39 *
40 * DISCLAIMER.
41 *
42 * THIS SOFTWARE IS PROVIDED BY TI AND TI"S LICENSORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
43 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
44 * IN NO EVENT SHALL TI AND TI"S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
45 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
46 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
48 * POSSIBILITY OF SUCH DAMAGE.
49 */
59 #ifndef LUB_LIST_UTILS_H_
60 #define LUB_LIST_UTILS_H_
61
62 #include <stdint.h>
63 #include <stdlib.h>
64 #include <stdbool.h>
65
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69
73 struct ub_list_node {
74 struct ub_list_node *prev;
75 struct ub_list_node *next;
76 void *data;
77 };
78
82 #define UB_LIST_NODE_INIT {NULL, NULL, NULL}
83
87 struct ub_list {
88 struct ub_list_node *head;
89 struct ub_list_node *tail;
90 uint32_t count;
91 };
92
96 #define UB_LIST_INIT {NULL, NULL, 0}
97
102 void ub_list_init(struct ub_list *ub_list);
103
109 typedef void (ub_list_node_clear_h)(struct ub_list_node *node, void *arg);
110
117 void ub_list_clear(struct ub_list *ub_list, ub_list_node_clear_h node_clear,
118 void *arg);
119
125 void ub_list_append(struct ub_list *ub_list, struct ub_list_node *node);
126
132 void ub_list_prepend(struct ub_list *ub_list, struct ub_list_node *node);
133
140 void ub_list_insert_before(struct ub_list *ub_list, struct ub_list_node *refnode,
141 struct ub_list_node *node);
142
149 void ub_list_insert_after(struct ub_list *ub_list, struct ub_list_node *refnode,
150 struct ub_list_node *node);
151
157 void ub_list_unlink(struct ub_list *ub_list, struct ub_list_node *node);
158
166 typedef bool (ub_list_sort_h)(struct ub_list_node *node1,
167 struct ub_list_node *node2, void *arg);
168
175 void ub_list_sort(struct ub_list *ub_list, ub_list_sort_h *sh, void *arg);
176
182 typedef bool (ub_list_apply_h)(struct ub_list_node *node, void *arg);
183
191 struct ub_list_node *ub_list_apply(const struct ub_list *ub_list, bool fwd,
192 ub_list_apply_h *ah, void *arg);
193
198 struct ub_list_node *ub_list_head(const struct ub_list *ub_list);
199
204 struct ub_list_node *ub_list_tail(const struct ub_list *ub_list);
205
211 uint32_t ub_list_count(const struct ub_list *ub_list);
212
218 static inline void *ub_list_nodedata(const struct ub_list_node *node){
219 return node ? node->data : NULL;
220 }
221
227 static inline bool ub_list_isempty(const struct ub_list *ub_list){
228 return (ub_list!=NULL) ? (ub_list->head == NULL) : true;
229 }
230
234 #define UB_LIST_FOREACH_ITER(ub_list, node) \
235 (node) = ub_list_head((ub_list)); (node); (node) = (node)->next
236
237 #ifdef __cplusplus
238 }
239 #endif
240
241 #endif
242
ub_list_sort_h
bool() ub_list_sort_h(struct ub_list_node *node1, struct ub_list_node *node2, void *arg)
Comparator function handler for nodes.
Definition: ub_llist.h:166
ub_list_append
void ub_list_append(struct ub_list *ub_list, struct ub_list_node *node)
Append a node at the end of the ub_list.
ub_list
Link ub_list structure.
Definition: ub_llist.h:87
ub_list_apply
struct ub_list_node * ub_list_apply(const struct ub_list *ub_list, bool fwd, ub_list_apply_h *ah, void *arg)
Apply function to nodes in the ub_list.
ub_list_prepend
void ub_list_prepend(struct ub_list *ub_list, struct ub_list_node *node)
Append a node at the start of the ub_list.
ub_list_clear
void ub_list_clear(struct ub_list *ub_list, ub_list_node_clear_h node_clear, void *arg)
Clear the ub_list without freeing any nodes.
ub_list_apply_h
bool() ub_list_apply_h(struct ub_list_node *node, void *arg)
Apply function handler for nodes.
Definition: ub_llist.h:182
ub_list_isempty
static bool ub_list_isempty(const struct ub_list *ub_list)
Check if ub_list is empty.
Definition: ub_llist.h:227
ub_list_tail
struct ub_list_node * ub_list_tail(const struct ub_list *ub_list)
Get last entry of the ub_list.
ub_list_head
struct ub_list_node * ub_list_head(const struct ub_list *ub_list)
Get first entry of the ub_list.
ub_list_node_clear_h
void() ub_list_node_clear_h(struct ub_list_node *node, void *arg)
function to clean up node
Definition: ub_llist.h:109
ub_list_node::data
void * data
Definition: ub_llist.h:76
ub_list_count
uint32_t ub_list_count(const struct ub_list *ub_list)
Get number of entries.
ub_list_insert_before
void ub_list_insert_before(struct ub_list *ub_list, struct ub_list_node *refnode, struct ub_list_node *node)
Append a node before a reference node.
ub_list::tail
struct ub_list_node * tail
Definition: ub_llist.h:89
ub_list::head
struct ub_list_node * head
Definition: ub_llist.h:88
ub_list_sort
void ub_list_sort(struct ub_list *ub_list, ub_list_sort_h *sh, void *arg)
Sort entries in the ub_list based on comparator.
ub_list_insert_after
void ub_list_insert_after(struct ub_list *ub_list, struct ub_list_node *refnode, struct ub_list_node *node)
Append a node after a reference node.
ub_list_nodedata
static void * ub_list_nodedata(const struct ub_list_node *node)
Get data of node.
Definition: ub_llist.h:218
ub_list_node
ub_list node structure
Definition: ub_llist.h:73
ub_list_init
void ub_list_init(struct ub_list *ub_list)
Initialize ub_list.
ub_list_unlink
void ub_list_unlink(struct ub_list *ub_list, struct ub_list_node *node)
Remove a node from the ub_list.
ub_list::count
uint32_t count
Definition: ub_llist.h:90
ub_list_node::prev
struct ub_list_node * prev
Definition: ub_llist.h:74
ub_list_node::next
struct ub_list_node * next
Definition: ub_llist.h:75