1 /*************************************************************************/ /*!
3 @Title Double linked list header
4 @Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description Double linked list interface
6 @License Dual MIT/GPLv2
8 The contents of this file are subject to the MIT license as set out below.
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
20 Alternatively, the contents of this file may be used under the terms of
21 the GNU General Public License Version 2 ("GPL") in which case the provisions
22 of GPL are applicable instead of those above.
24 If you wish to allow use of your version of this file only under the terms of
25 GPL, and not to allow others to use your version of this file under the terms
26 of the MIT license, indicate your decision by deleting the provisions above
27 and replace them with the notice and other provisions required by GPL as set
28 out in the file called "GPL-COPYING" included in this distribution. If you do
29 not delete the provisions above, a recipient may use your version of this file
30 under the terms of either the MIT license or GPL.
32 This License is also included in this distribution in the file called
35 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
36 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
37 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
38 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
39 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
40 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
41 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 */ /**************************************************************************/
47 #include "img_types.h"
50 Pointer to a linked list node
52 typedef struct _DLLIST_NODE_ *PDLLIST_NODE;
59 * Note: the following structure's size is architecture-dependent and
60 * clients may need to create a mirror the structure definition if it needs
61 * to be used in a structure shared between host and device. Consider such
62 * clients if any changes are made to this structure.
64 typedef struct _DLLIST_NODE_
66 struct _DLLIST_NODE_ *psPrevNode;
67 struct _DLLIST_NODE_ *psNextNode;
74 #define DECLARE_DLLIST(n) \
75 DLLIST_NODE n = {&n, &n}
78 /*************************************************************************/ /*!
81 @Description Initialize a new double linked list
83 @Input psListHead List head Node
86 /*****************************************************************************/
88 IMG_VOID dllist_init(PDLLIST_NODE psListHead)
90 psListHead->psPrevNode = psListHead;
91 psListHead->psNextNode = psListHead;
95 /*************************************************************************/ /*!
96 @Function dllist_is_empty
98 @Description Returns whether the list is empty
100 @Input psListHead List head Node
103 /*****************************************************************************/
105 IMG_BOOL dllist_is_empty(PDLLIST_NODE psListHead)
107 return ((psListHead->psPrevNode == psListHead)
108 && (psListHead->psNextNode == psListHead));
112 /*************************************************************************/ /*!
113 @Function dllist_add_to_head
115 @Description Add psNewNode to head of list psListHead
117 @Input psListHead Head Node
118 @Input psNewNode New Node
121 /*****************************************************************************/
123 IMG_VOID dllist_add_to_head(PDLLIST_NODE psListHead, PDLLIST_NODE psNewNode)
127 psTmp = psListHead->psNextNode;
129 psListHead->psNextNode = psNewNode;
130 psNewNode->psNextNode = psTmp;
132 psTmp->psPrevNode = psNewNode;
133 psNewNode->psPrevNode = psListHead;
137 /*************************************************************************/ /*!
138 @Function dllist_add_to_tail
140 @Description Add psNewNode to tail of list psListHead
142 @Input psListHead Head Node
143 @Input psNewNode New Node
146 /*****************************************************************************/
148 IMG_VOID dllist_add_to_tail(PDLLIST_NODE psListHead, PDLLIST_NODE psNewNode)
152 psTmp = psListHead->psPrevNode;
154 psListHead->psPrevNode = psNewNode;
155 psNewNode->psPrevNode = psTmp;
157 psTmp->psNextNode = psNewNode;
158 psNewNode->psNextNode = psListHead;
162 /*************************************************************************/ /*!
163 @Function dllist_node_is_in_list
165 @Description Returns IMG_TRUE if psNode is in a list
167 @Input psNode List node
170 /*****************************************************************************/
172 IMG_BOOL dllist_node_is_in_list(PDLLIST_NODE psNode)
174 return (psNode->psNextNode != 0);
178 /*************************************************************************/ /*!
179 @Function dllist_get_next_node
181 @Description Returns the list node after psListHead or IMG_NULL psListHead
182 is the only element in the list.
184 @Input psListHead List node to start the operation
187 /*****************************************************************************/
189 PDLLIST_NODE dllist_get_next_node(PDLLIST_NODE psListHead)
191 if (psListHead->psNextNode == psListHead)
197 return psListHead->psNextNode;
202 /*************************************************************************/ /*!
203 @Function dllist_remove_node
205 @Description Removes psListNode from the list where it currently belongs
207 @Input psListNode List node to be removed
210 /*****************************************************************************/
212 IMG_VOID dllist_remove_node(PDLLIST_NODE psListNode)
214 psListNode->psNextNode->psPrevNode = psListNode->psPrevNode;
215 psListNode->psPrevNode->psNextNode = psListNode->psNextNode;
217 /* Clear the node to show it's not on a list */
218 psListNode->psPrevNode = 0;
219 psListNode->psNextNode = 0;
224 Callback function called on each element of the list
226 typedef IMG_BOOL (*PFN_NODE_CALLBACK)(PDLLIST_NODE psNode, IMG_PVOID pvCallbackData);
229 /*************************************************************************/ /*!
230 @Function dllist_foreach_node
232 @Description Walk through all the nodes on the list until the
233 end or a callback returns FALSE
235 @Input psListHead List node to start the operation
236 @Input pfnCallBack PFN_NODE_CALLBACK function called on each element
237 @Input pvCallbackData Data passed to pfnCallBack alongside the current Node
240 /*****************************************************************************/
242 IMG_VOID dllist_foreach_node(PDLLIST_NODE psListHead,
243 PFN_NODE_CALLBACK pfnCallBack,
244 IMG_PVOID pvCallbackData);
247 #endif /* _DLLIST_ */