]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/EfiCommonLib/LinkedList.c
Update the copyright notice format
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EfiCommonLib / LinkedList.c
CommitLineData
3eb9473e 1/*++\r
2\r
4ea9375a
HT
3Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>\r
4This program and the accompanying materials \r
3eb9473e 5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 LinkedList.c\r
15\r
16Abstract:\r
17\r
18 Linked List Library Functions\r
19\r
20--*/\r
21\r
22#include "Tiano.h"\r
23#include "EfiDriverLib.h"\r
24\r
25\r
26VOID\r
27InitializeListHead (\r
28 EFI_LIST_ENTRY *List\r
29 )\r
30/*++\r
31\r
32Routine Description:\r
33\r
34 Initialize the head of the List. The caller must allocate the memory \r
35 for the EFI_LIST. This function must be called before the other linked\r
36 list macros can be used.\r
37 \r
38Arguments:\r
39\r
40 List - Pointer to list head to initialize\r
41 \r
42Returns:\r
43\r
44 None.\r
45\r
46--*/\r
47\r
48{\r
49 List->ForwardLink = List;\r
50 List->BackLink = List;\r
51}\r
52\r
53\r
54BOOLEAN\r
55IsListEmpty (\r
56 EFI_LIST_ENTRY *List\r
57 )\r
58/*++\r
59\r
60Routine Description:\r
61\r
62 Return TRUE is the list contains zero nodes. Otherzise return FALSE.\r
63 The list must have been initialized with InitializeListHead () before using \r
64 this function.\r
65 \r
66Arguments:\r
67\r
68 List - Pointer to list head to test\r
69\r
70 \r
71Returns:\r
72\r
73 Return TRUE is the list contains zero nodes. Otherzise return FALSE.\r
74\r
75--*/\r
76{\r
77 return (BOOLEAN)(List->ForwardLink == List);\r
78}\r
79\r
80\r
81VOID\r
82RemoveEntryList (\r
83 EFI_LIST_ENTRY *Entry\r
84 )\r
85/*++\r
86\r
87Routine Description:\r
88\r
89 Remove Node from the doubly linked list. It is the caller's responsibility\r
90 to free any memory used by the entry if needed. The list must have been \r
91 initialized with InitializeListHead () before using this function.\r
92 \r
93Arguments:\r
94\r
95 Entry - Element to remove from the list.\r
96 \r
97Returns:\r
98 \r
99 None\r
100\r
101--*/\r
102{\r
103 EFI_LIST_ENTRY *_ForwardLink;\r
104 EFI_LIST_ENTRY *_BackLink;\r
105\r
106 _ForwardLink = Entry->ForwardLink;\r
107 _BackLink = Entry->BackLink; \r
108 _BackLink->ForwardLink = _ForwardLink;\r
109 _ForwardLink->BackLink = _BackLink; \r
110\r
111 DEBUG_CODE (\r
112 Entry->ForwardLink = (EFI_LIST_ENTRY *) EFI_BAD_POINTER;\r
113 Entry->BackLink = (EFI_LIST_ENTRY *) EFI_BAD_POINTER;\r
114 )\r
115}\r
116\r
117\r
118VOID\r
119InsertTailList (\r
120 EFI_LIST_ENTRY *ListHead,\r
121 EFI_LIST_ENTRY *Entry\r
122 )\r
123/*++\r
124\r
125Routine Description:\r
126\r
127 Insert a Node into the end of a doubly linked list. The list must have \r
128 been initialized with InitializeListHead () before using this function.\r
129 \r
130Arguments:\r
131\r
132 ListHead - Head of doubly linked list\r
133\r
134 Entry - Element to insert at the end of the list.\r
135 \r
136Returns:\r
137 \r
138 None\r
139\r
140--*/\r
141{\r
142 EFI_LIST_ENTRY *_ListHead;\r
143 EFI_LIST_ENTRY *_BackLink;\r
144\r
145 _ListHead = ListHead; \r
146 _BackLink = _ListHead->BackLink; \r
147 Entry->ForwardLink = _ListHead; \r
148 Entry->BackLink = _BackLink; \r
149 _BackLink->ForwardLink = Entry; \r
150 _ListHead->BackLink = Entry; \r
151}\r
152\r
153\r
154\r
155VOID\r
156InsertHeadList (\r
157 EFI_LIST_ENTRY *ListHead,\r
158 EFI_LIST_ENTRY *Entry\r
159 )\r
160/*++\r
161\r
162Routine Description:\r
163\r
164 Insert a Node into the start of a doubly linked list. The list must have \r
165 been initialized with InitializeListHead () before using this function.\r
166 \r
167Arguments:\r
168\r
169 ListHead - Head of doubly linked list\r
170\r
171 Entry - Element to insert to beginning of list\r
172 \r
173Returns:\r
174 \r
175 None\r
176\r
177--*/\r
178{\r
179 EFI_LIST_ENTRY *_ListHead;\r
180 EFI_LIST_ENTRY *_ForwardLink;\r
181\r
182 _ListHead = ListHead; \r
183 _ForwardLink = _ListHead->ForwardLink; \r
184 Entry->ForwardLink = _ForwardLink; \r
185 Entry->BackLink = _ListHead; \r
186 _ForwardLink->BackLink = Entry; \r
187 _ListHead->ForwardLink = Entry; \r
188}\r
189\r
190VOID\r
191SwapListEntries (\r
192 EFI_LIST_ENTRY *Entry1,\r
193 EFI_LIST_ENTRY *Entry2\r
194 )\r
195/*++\r
196\r
197Routine Description:\r
198\r
199 Swap the location of the two elements of a doubly linked list. Node2 \r
200 is placed in front of Node1. The list must have been initialized with \r
201 InitializeListHead () before using this function.\r
202 \r
203Arguments:\r
204\r
205 Entry1 - Element in the doubly linked list in front of Node2. \r
206\r
207 Entry2 - Element in the doubly linked list behind Node1.\r
208 \r
209Returns:\r
210 \r
211 None\r
212\r
213--*/\r
214{\r
215 EFI_LIST_ENTRY *Entry1ForwardLink;\r
216 EFI_LIST_ENTRY *Entry1BackLink;\r
217 EFI_LIST_ENTRY *Entry2ForwardLink;\r
218 EFI_LIST_ENTRY *Entry2BackLink;\r
219\r
220 Entry2ForwardLink = Entry2->ForwardLink; \r
221 Entry2BackLink = Entry2->BackLink; \r
222 Entry1ForwardLink = Entry1->ForwardLink; \r
223 Entry1BackLink = Entry1->BackLink; \r
224 Entry2BackLink->ForwardLink = Entry2ForwardLink; \r
225 Entry2ForwardLink->BackLink = Entry2BackLink; \r
226 Entry2->ForwardLink = Entry1; \r
227 Entry2->BackLink = Entry1BackLink; \r
228 Entry1BackLink->ForwardLink = Entry2; \r
229 Entry1->BackLink = Entry2; \r
230}\r
231\r
232\r
233EFI_LIST_ENTRY *\r
234GetFirstNode (\r
235 EFI_LIST_ENTRY *List \r
236 )\r
237/*++\r
238\r
239Routine Description:\r
240\r
241 Return the first node pointed to by the list head. The list must \r
242 have been initialized with InitializeListHead () before using this \r
243 function and must contain data.\r
244 \r
245Arguments:\r
246\r
247 List - The head of the doubly linked list.\r
248 \r
249Returns:\r
250 \r
251 Pointer to the first node, if the list contains nodes. The list will\r
252 return a null value--that is, the value of List--when the list is empty.\r
253 See the description of IsNull for more information.\r
254\r
255\r
256--*/\r
257{\r
258 return List->ForwardLink;\r
259}\r
260\r
261\r
262EFI_LIST_ENTRY *\r
263GetNextNode (\r
264 EFI_LIST_ENTRY *List,\r
265 EFI_LIST_ENTRY *Node\r
266 )\r
267/*++\r
268\r
269Routine Description:\r
270\r
271 Returns the node following Node in the list. The list must \r
272 have been initialized with InitializeListHead () before using this \r
273 function and must contain data.\r
274 \r
275Arguments:\r
276\r
277 List - The head of the list. MUST NOT be the literal value NULL.\r
278 Node - The node in the list. This value MUST NOT be the literal value NULL.\r
279 See the description of IsNull for more information.\r
280 \r
281Returns:\r
282 \r
283 Pointer to the next node, if one exists. Otherwise, returns a null value,\r
284 which is actually a pointer to List.\r
285 See the description of IsNull for more information.\r
286\r
287--*/\r
288{\r
289 if (Node == List) {\r
290 return List;\r
291 } \r
292 return Node->ForwardLink;\r
293}\r
294\r
295\r
296BOOLEAN \r
297IsNull ( \r
298 EFI_LIST_ENTRY *List,\r
299 EFI_LIST_ENTRY *Node \r
300 )\r
301/*++\r
302\r
303Routine Description:\r
304\r
305 Determines whether the given node is null. Note that Node is null\r
306 when its value is equal to the value of List. It is an error for\r
307 Node to be the literal value NULL [(VOID*)0x0].\r
308\r
309Arguments:\r
310\r
311 List - The head of the list. MUST NOT be the literal value NULL.\r
312 Node - The node to test. MUST NOT be the literal value NULL. See\r
313 the description above.\r
314 \r
315Returns:\r
316 \r
317 Returns true if the node is null.\r
318\r
319--*/\r
320{\r
321 return (BOOLEAN)(Node == List);\r
322}\r
323\r
324\r
325BOOLEAN \r
326IsNodeAtEnd ( \r
327 EFI_LIST_ENTRY *List, \r
328 EFI_LIST_ENTRY *Node \r
329 )\r
330/*++\r
331\r
332Routine Description:\r
333\r
334 Determines whether the given node is at the end of the list. Used\r
335 to walk the list. The list must have been initialized with \r
336 InitializeListHead () before using this function and must contain \r
337 data.\r
338\r
339Arguments:\r
340\r
341 List - The head of the list. MUST NOT be the literal value NULL.\r
342 Node - The node to test. MUST NOT be the literal value NULL.\r
343 See the description of IsNull for more information.\r
344 \r
345Returns:\r
346 \r
347 Returns true if the list is the tail.\r
348\r
349--*/\r
350{\r
351 if (IsNull (List, Node)) {\r
352 return FALSE;\r
353 }\r
354 return (BOOLEAN)(List->BackLink == Node);\r
355}\r
356\r