3 Copyright (c) 2004, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Linked List Library Functions
23 #include "EfiDriverLib.h"
34 Initialize the head of the List. The caller must allocate the memory
35 for the EFI_LIST. This function must be called before the other linked
36 list macros can be used.
40 List - Pointer to list head to initialize
49 List
->ForwardLink
= List
;
50 List
->BackLink
= List
;
62 Return TRUE is the list contains zero nodes. Otherzise return FALSE.
63 The list must have been initialized with InitializeListHead () before using
68 List - Pointer to list head to test
73 Return TRUE is the list contains zero nodes. Otherzise return FALSE.
77 return (BOOLEAN
)(List
->ForwardLink
== List
);
89 Remove Node from the doubly linked list. It is the caller's responsibility
90 to free any memory used by the entry if needed. The list must have been
91 initialized with InitializeListHead () before using this function.
95 Entry - Element to remove from the list.
103 EFI_LIST_ENTRY
*_ForwardLink
;
104 EFI_LIST_ENTRY
*_BackLink
;
106 _ForwardLink
= Entry
->ForwardLink
;
107 _BackLink
= Entry
->BackLink
;
108 _BackLink
->ForwardLink
= _ForwardLink
;
109 _ForwardLink
->BackLink
= _BackLink
;
112 Entry
->ForwardLink
= (EFI_LIST_ENTRY
*) EFI_BAD_POINTER
;
113 Entry
->BackLink
= (EFI_LIST_ENTRY
*) EFI_BAD_POINTER
;
120 EFI_LIST_ENTRY
*ListHead
,
121 EFI_LIST_ENTRY
*Entry
127 Insert a Node into the end of a doubly linked list. The list must have
128 been initialized with InitializeListHead () before using this function.
132 ListHead - Head of doubly linked list
134 Entry - Element to insert at the end of the list.
142 EFI_LIST_ENTRY
*_ListHead
;
143 EFI_LIST_ENTRY
*_BackLink
;
145 _ListHead
= ListHead
;
146 _BackLink
= _ListHead
->BackLink
;
147 Entry
->ForwardLink
= _ListHead
;
148 Entry
->BackLink
= _BackLink
;
149 _BackLink
->ForwardLink
= Entry
;
150 _ListHead
->BackLink
= Entry
;
157 EFI_LIST_ENTRY
*ListHead
,
158 EFI_LIST_ENTRY
*Entry
164 Insert a Node into the start of a doubly linked list. The list must have
165 been initialized with InitializeListHead () before using this function.
169 ListHead - Head of doubly linked list
171 Entry - Element to insert to beginning of list
179 EFI_LIST_ENTRY
*_ListHead
;
180 EFI_LIST_ENTRY
*_ForwardLink
;
182 _ListHead
= ListHead
;
183 _ForwardLink
= _ListHead
->ForwardLink
;
184 Entry
->ForwardLink
= _ForwardLink
;
185 Entry
->BackLink
= _ListHead
;
186 _ForwardLink
->BackLink
= Entry
;
187 _ListHead
->ForwardLink
= Entry
;
192 EFI_LIST_ENTRY
*Entry1
,
193 EFI_LIST_ENTRY
*Entry2
199 Swap the location of the two elements of a doubly linked list. Node2
200 is placed in front of Node1. The list must have been initialized with
201 InitializeListHead () before using this function.
205 Entry1 - Element in the doubly linked list in front of Node2.
207 Entry2 - Element in the doubly linked list behind Node1.
215 EFI_LIST_ENTRY
*Entry1ForwardLink
;
216 EFI_LIST_ENTRY
*Entry1BackLink
;
217 EFI_LIST_ENTRY
*Entry2ForwardLink
;
218 EFI_LIST_ENTRY
*Entry2BackLink
;
220 Entry2ForwardLink
= Entry2
->ForwardLink
;
221 Entry2BackLink
= Entry2
->BackLink
;
222 Entry1ForwardLink
= Entry1
->ForwardLink
;
223 Entry1BackLink
= Entry1
->BackLink
;
224 Entry2BackLink
->ForwardLink
= Entry2ForwardLink
;
225 Entry2ForwardLink
->BackLink
= Entry2BackLink
;
226 Entry2
->ForwardLink
= Entry1
;
227 Entry2
->BackLink
= Entry1BackLink
;
228 Entry1BackLink
->ForwardLink
= Entry2
;
229 Entry1
->BackLink
= Entry2
;
241 Return the first node pointed to by the list head. The list must
242 have been initialized with InitializeListHead () before using this
243 function and must contain data.
247 List - The head of the doubly linked list.
251 Pointer to the first node, if the list contains nodes. The list will
252 return a null value--that is, the value of List--when the list is empty.
253 See the description of IsNull for more information.
258 return List
->ForwardLink
;
264 EFI_LIST_ENTRY
*List
,
271 Returns the node following Node in the list. The list must
272 have been initialized with InitializeListHead () before using this
273 function and must contain data.
277 List - The head of the list. MUST NOT be the literal value NULL.
278 Node - The node in the list. This value MUST NOT be the literal value NULL.
279 See the description of IsNull for more information.
283 Pointer to the next node, if one exists. Otherwise, returns a null value,
284 which is actually a pointer to List.
285 See the description of IsNull for more information.
292 return Node
->ForwardLink
;
298 EFI_LIST_ENTRY
*List
,
305 Determines whether the given node is null. Note that Node is null
306 when its value is equal to the value of List. It is an error for
307 Node to be the literal value NULL [(VOID*)0x0].
311 List - The head of the list. MUST NOT be the literal value NULL.
312 Node - The node to test. MUST NOT be the literal value NULL. See
313 the description above.
317 Returns true if the node is null.
321 return (BOOLEAN
)(Node
== List
);
327 EFI_LIST_ENTRY
*List
,
334 Determines whether the given node is at the end of the list. Used
335 to walk the list. The list must have been initialized with
336 InitializeListHead () before using this function and must contain
341 List - The head of the list. MUST NOT be the literal value NULL.
342 Node - The node to test. MUST NOT be the literal value NULL.
343 See the description of IsNull for more information.
347 Returns true if the list is the tail.
351 if (IsNull (List
, Node
)) {
354 return (BOOLEAN
)(List
->BackLink
== Node
);