TianoCore EDK2 master
Loading...
Searching...
No Matches
LinkedList.c File Reference
#include "BaseLibInternals.h"

Go to the source code of this file.

Macros

#define ASSERT_VERIFY_NODE_IN_VALID_LIST(FirstEntry, SecondEntry, InList)
 

Functions

BOOLEAN EFIAPI InternalBaseLibIsListValid (IN CONST LIST_ENTRY *List)
 
BOOLEAN EFIAPI IsNodeInList (IN CONST LIST_ENTRY *FirstEntry, IN CONST LIST_ENTRY *SecondEntry)
 
LIST_ENTRY *EFIAPI InitializeListHead (IN OUT LIST_ENTRY *ListHead)
 
LIST_ENTRY *EFIAPI InsertHeadList (IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
 
LIST_ENTRY *EFIAPI InsertTailList (IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
 
LIST_ENTRY *EFIAPI GetFirstNode (IN CONST LIST_ENTRY *List)
 
LIST_ENTRY *EFIAPI GetNextNode (IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
 
LIST_ENTRY *EFIAPI GetPreviousNode (IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
 
BOOLEAN EFIAPI IsListEmpty (IN CONST LIST_ENTRY *ListHead)
 
BOOLEAN EFIAPI IsNull (IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
 
BOOLEAN EFIAPI IsNodeAtEnd (IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
 
LIST_ENTRY *EFIAPI SwapListEntries (IN OUT LIST_ENTRY *FirstEntry, IN OUT LIST_ENTRY *SecondEntry)
 
LIST_ENTRY *EFIAPI RemoveEntryList (IN CONST LIST_ENTRY *Entry)
 

Detailed Description

Linked List Library Functions.

Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file LinkedList.c.

Macro Definition Documentation

◆ ASSERT_VERIFY_NODE_IN_VALID_LIST

#define ASSERT_VERIFY_NODE_IN_VALID_LIST (   FirstEntry,
  SecondEntry,
  InList 
)
Value:
do { \
if (FeaturePcdGet (PcdVerifyNodeInList)) { \
ASSERT (InList == IsNodeInList ((FirstEntry), (SecondEntry))); \
} else { \
ASSERT (InternalBaseLibIsListValid (FirstEntry)); \
} \
} while (FALSE)
BOOLEAN EFIAPI InternalBaseLibIsListValid(IN CONST LIST_ENTRY *List)
Definition: LinkedList.c:64
BOOLEAN EFIAPI IsNodeInList(IN CONST LIST_ENTRY *FirstEntry, IN CONST LIST_ENTRY *SecondEntry)
Definition: LinkedList.c:121
#define FALSE
Definition: Base.h:307
#define FeaturePcdGet(TokenName)
Definition: PcdLib.h:50

If PcdVerifyNodeInList is TRUE, ASSERTs when SecondEntry is or is not part of the same doubly-linked list as FirstEntry depending on the value of InList. Independent of PcdVerifyNodeInList, ASSERTs when FirstEntry is not part of a valid list.

If FirstEntry is NULL, then ASSERT(). If FirstEntry->ForwardLink is NULL, then ASSERT(). If FirstEntry->BackLink is NULL, then ASSERT(). If PcdMaximumLinkedListLength is not zero, and List contains more than PcdMaximumLinkedListLength nodes, then ASSERT(). If PcdVerifyNodeInList is TRUE and SecondEntry is NULL, then ASSERT().

Parameters
FirstEntryA pointer to a node in a linked list.
SecondEntryA pointer to the node to locate.
InListDefines whether to check if SecondEntry is or is not part of the same doubly-linked list as FirstEntry.

Definition at line 31 of file LinkedList.c.

Function Documentation

◆ GetFirstNode()

LIST_ENTRY *EFIAPI GetFirstNode ( IN CONST LIST_ENTRY List)

Retrieves the first node of a doubly-linked list.

Returns the first node of a doubly-linked list. List must have been initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(). If List is empty, then List is returned.

If List is NULL, then ASSERT(). If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(), then ASSERT(). If PcdMaximumLinkedListLength is not zero, and the number of nodes in List, including the List node, is greater than or equal to PcdMaximumLinkedListLength, then ASSERT().

Parameters
ListA pointer to the head node of a doubly-linked list.
Returns
The first node of a doubly-linked list.
Return values
ListThe list is empty.

Definition at line 298 of file LinkedList.c.

◆ GetNextNode()

LIST_ENTRY *EFIAPI GetNextNode ( IN CONST LIST_ENTRY List,
IN CONST LIST_ENTRY Node 
)

Retrieves the next node of a doubly-linked list.

Returns the node of a doubly-linked list that follows Node. List must have been initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(). If List is empty, then List is returned.

If List is NULL, then ASSERT(). If Node is NULL, then ASSERT(). If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(), then ASSERT(). If PcdMaximumLinkedListLength is not zero, and List contains more than PcdMaximumLinkedListLength nodes, then ASSERT(). If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().

Parameters
ListA pointer to the head node of a doubly-linked list.
NodeA pointer to a node in the doubly-linked list.
Returns
A pointer to the next node if one exists. Otherwise List is returned.

Definition at line 333 of file LinkedList.c.

◆ GetPreviousNode()

LIST_ENTRY *EFIAPI GetPreviousNode ( IN CONST LIST_ENTRY List,
IN CONST LIST_ENTRY Node 
)

Retrieves the previous node of a doubly-linked list.

Returns the node of a doubly-linked list that precedes Node. List must have been initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(). If List is empty, then List is returned.

If List is NULL, then ASSERT(). If Node is NULL, then ASSERT(). If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(), then ASSERT(). If PcdMaximumLinkedListLength is not zero, and List contains more than PcdMaximumLinkedListLength nodes, then ASSERT(). If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().

Parameters
ListA pointer to the head node of a doubly-linked list.
NodeA pointer to a node in the doubly-linked list.
Returns
A pointer to the previous node if one exists. Otherwise List is returned.

Definition at line 369 of file LinkedList.c.

◆ InitializeListHead()

LIST_ENTRY *EFIAPI InitializeListHead ( IN OUT LIST_ENTRY ListHead)

Initializes the head node of a doubly-linked list, and returns the pointer to the head node of the doubly-linked list.

Initializes the forward and backward links of a new linked list. After initializing a linked list with this function, the other linked list functions may be used to add and remove nodes from the linked list. It is up to the caller of this function to allocate the memory for ListHead.

If ListHead is NULL, then ASSERT().

Parameters
ListHeadA pointer to the head node of a new doubly-linked list.
Returns
ListHead

Definition at line 182 of file LinkedList.c.

◆ InsertHeadList()

LIST_ENTRY *EFIAPI InsertHeadList ( IN OUT LIST_ENTRY ListHead,
IN OUT LIST_ENTRY Entry 
)

Adds a node to the beginning of a doubly-linked list, and returns the pointer to the head node of the doubly-linked list.

Adds the node Entry at the beginning of the doubly-linked list denoted by ListHead, and returns ListHead.

If ListHead is NULL, then ASSERT(). If Entry is NULL, then ASSERT(). If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(), then ASSERT(). If PcdMaximumLinkedListLength is not zero, and prior to insertion the number of nodes in ListHead, including the ListHead node, is greater than or equal to PcdMaximumLinkedListLength, then ASSERT().

Parameters
ListHeadA pointer to the head node of a doubly-linked list.
EntryA pointer to a node that is to be inserted at the beginning of a doubly-linked list.
Returns
ListHead

Definition at line 218 of file LinkedList.c.

◆ InsertTailList()

LIST_ENTRY *EFIAPI InsertTailList ( IN OUT LIST_ENTRY ListHead,
IN OUT LIST_ENTRY Entry 
)

Adds a node to the end of a doubly-linked list, and returns the pointer to the head node of the doubly-linked list.

Adds the node Entry to the end of the doubly-linked list denoted by ListHead, and returns ListHead.

If ListHead is NULL, then ASSERT(). If Entry is NULL, then ASSERT(). If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(), then ASSERT(). If PcdMaximumLinkedListLength is not zero, and prior to insertion the number of nodes in ListHead, including the ListHead node, is greater than or equal to PcdMaximumLinkedListLength, then ASSERT().

Parameters
ListHeadA pointer to the head node of a doubly-linked list.
EntryA pointer to a node that is to be added at the end of the doubly-linked list.
Returns
ListHead

Definition at line 259 of file LinkedList.c.

◆ InternalBaseLibIsListValid()

BOOLEAN EFIAPI InternalBaseLibIsListValid ( IN CONST LIST_ENTRY List)

Worker function that verifies the validity of this list.

If List is NULL, then ASSERT(). If List->ForwardLink is NULL, then ASSERT(). If List->BackLink is NULL, then ASSERT(). If PcdMaximumLinkedListLength is not zero, and List contains more than PcdMaximumLinkedListLength nodes, then ASSERT().

Parameters
ListA pointer to a node in a linked list.
Return values
TRUEif PcdVerifyNodeInList is FALSE
TRUEif DoMembershipCheck is FALSE
TRUEif PcdVerifyNodeInList is TRUE and DoMembershipCheck is TRUE and Node is a member of List.
FALSEif PcdVerifyNodeInList is TRUE and DoMembershipCheck is TRUE and Node is in not a member of List.

Definition at line 64 of file LinkedList.c.

◆ IsListEmpty()

BOOLEAN EFIAPI IsListEmpty ( IN CONST LIST_ENTRY ListHead)

Checks to see if a doubly-linked list is empty or not.

Checks to see if the doubly-linked list is empty. If the linked list contains zero nodes, this function returns TRUE. Otherwise, it returns FALSE.

If ListHead is NULL, then ASSERT(). If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(), then ASSERT(). If PcdMaximumLinkedListLength is not zero, and the number of nodes in List, including the List node, is greater than or equal to PcdMaximumLinkedListLength, then ASSERT().

Parameters
ListHeadA pointer to the head node of a doubly-linked list.
Return values
TRUEThe linked list is empty.
FALSEThe linked list is not empty.

Definition at line 403 of file LinkedList.c.

◆ IsNodeAtEnd()

BOOLEAN EFIAPI IsNodeAtEnd ( IN CONST LIST_ENTRY List,
IN CONST LIST_ENTRY Node 
)

Determines if a node the last node in a doubly-linked list.

Returns TRUE if Node is the last node in the doubly-linked list specified by List. Otherwise, FALSE is returned. List must have been initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().

If List is NULL, then ASSERT(). If Node is NULL, then ASSERT(). If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(), then ASSERT(). If PcdMaximumLinkedListLength is not zero, and the number of nodes in List, including the List node, is greater than or equal to PcdMaximumLinkedListLength, then ASSERT(). If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().

Parameters
ListA pointer to the head node of a doubly-linked list.
NodeA pointer to a node in the doubly-linked list.
Return values
TRUENode is the last node in the linked list.
FALSENode is not the last node in the linked list.

Definition at line 481 of file LinkedList.c.

◆ IsNodeInList()

BOOLEAN EFIAPI IsNodeInList ( IN CONST LIST_ENTRY FirstEntry,
IN CONST LIST_ENTRY SecondEntry 
)

Checks whether FirstEntry and SecondEntry are part of the same doubly-linked list.

If FirstEntry is NULL, then ASSERT(). If FirstEntry->ForwardLink is NULL, then ASSERT(). If FirstEntry->BackLink is NULL, then ASSERT(). If SecondEntry is NULL, then ASSERT(); If PcdMaximumLinkedListLength is not zero, and List contains more than PcdMaximumLinkedListLength nodes, then ASSERT().

Parameters
FirstEntryA pointer to a node in a linked list.
SecondEntryA pointer to the node to locate.
Return values
TRUESecondEntry is in the same doubly-linked list as FirstEntry.
FALSESecondEntry isn't in the same doubly-linked list as FirstEntry, or FirstEntry is invalid.

Definition at line 121 of file LinkedList.c.

◆ IsNull()

BOOLEAN EFIAPI IsNull ( IN CONST LIST_ENTRY List,
IN CONST LIST_ENTRY Node 
)

Determines if a node in a doubly-linked list is the head node of a the same doubly-linked list. This function is typically used to terminate a loop that traverses all the nodes in a doubly-linked list starting with the head node.

Returns TRUE if Node is equal to List. Returns FALSE if Node is one of the nodes in the doubly-linked list specified by List. List must have been initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().

If List is NULL, then ASSERT(). If Node is NULL, then ASSERT(). If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(), then ASSERT(). If PcdMaximumLinkedListLength is not zero, and the number of nodes in List, including the List node, is greater than or equal to PcdMaximumLinkedListLength, then ASSERT(). If PcdVerifyNodeInList is TRUE and Node is not a node in List and Node is not equal to List, then ASSERT().

Parameters
ListA pointer to the head node of a doubly-linked list.
NodeA pointer to a node in the doubly-linked list.
Return values
TRUENode is the head of the doubly-linked list pointed by List.
FALSENode is not the head of the doubly-linked list pointed by List.

Definition at line 443 of file LinkedList.c.

◆ RemoveEntryList()

LIST_ENTRY *EFIAPI RemoveEntryList ( IN CONST LIST_ENTRY Entry)

Removes a node from a doubly-linked list, and returns the node that follows the removed node.

Removes the node Entry from a doubly-linked list. It is up to the caller of this function to release the memory used by this node if that is required. On exit, the node following Entry in the doubly-linked list is returned. If Entry is the only node in the linked list, then the head node of the linked list is returned.

If Entry is NULL, then ASSERT(). If Entry is the head node of an empty list, then ASSERT(). If PcdMaximumLinkedListLength is not zero, and the number of nodes in the linked list containing Entry, including the Entry node, is greater than or equal to PcdMaximumLinkedListLength, then ASSERT().

Parameters
EntryA pointer to a node in a linked list.
Returns
Entry.

Definition at line 590 of file LinkedList.c.

◆ SwapListEntries()

LIST_ENTRY *EFIAPI SwapListEntries ( IN OUT LIST_ENTRY FirstEntry,
IN OUT LIST_ENTRY SecondEntry 
)

Swaps the location of two nodes in a doubly-linked list, and returns the first node after the swap.

If FirstEntry is identical to SecondEntry, then SecondEntry is returned. Otherwise, the location of the FirstEntry node is swapped with the location of the SecondEntry node in a doubly-linked list. SecondEntry must be in the same double linked list as FirstEntry and that double linked list must have been initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(). SecondEntry is returned after the nodes are swapped.

If FirstEntry is NULL, then ASSERT(). If SecondEntry is NULL, then ASSERT(). If PcdVerifyNodeInList is TRUE and SecondEntry and FirstEntry are not in the same linked list, then ASSERT(). If PcdMaximumLinkedListLength is not zero, and the number of nodes in the linked list containing the FirstEntry and SecondEntry nodes, including the FirstEntry and SecondEntry nodes, is greater than or equal to PcdMaximumLinkedListLength, then ASSERT().

Parameters
FirstEntryA pointer to a node in a linked list.
SecondEntryA pointer to another node in the same linked list.
Returns
SecondEntry.

Definition at line 522 of file LinkedList.c.