summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MdePkg/Include/Library/BaseLib.h32
-rw-r--r--MdePkg/Library/BaseLib/LinkedList.c39
2 files changed, 67 insertions, 4 deletions
diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h
index 05014a3b6d..e63831e059 100644
--- a/MdePkg/Include/Library/BaseLib.h
+++ b/MdePkg/Include/Library/BaseLib.h
@@ -1383,8 +1383,7 @@ GetFirstNode (
@param List A pointer to the head node of a doubly linked list.
@param Node A pointer to a node in the doubly linked list.
- @return Pointer to the next node if one exists. Otherwise a null value which
- is actually List is returned.
+ @return Pointer to the next node if one exists. Otherwise List is returned.
**/
LIST_ENTRY *
@@ -1394,7 +1393,36 @@ GetNextNode (
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 PcdMaximumLinkedListLenth is not zero, and List contains more than
+ PcdMaximumLinkedListLenth nodes, then ASSERT().
+ If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().
+
+ @param List A pointer to the head node of a doubly linked list.
+ @param Node A pointer to a node in the doubly linked list.
+
+ @return Pointer to the previous node if one exists. Otherwise List is returned.
+
+**/
+LIST_ENTRY *
+EFIAPI
+GetPreviousNode (
+ IN CONST LIST_ENTRY *List,
+ IN CONST LIST_ENTRY *Node
+ );
+
/**
Checks to see if a doubly linked list is empty or not.
diff --git a/MdePkg/Library/BaseLib/LinkedList.c b/MdePkg/Library/BaseLib/LinkedList.c
index 3ff582a978..0c811b0bff 100644
--- a/MdePkg/Library/BaseLib/LinkedList.c
+++ b/MdePkg/Library/BaseLib/LinkedList.c
@@ -276,8 +276,7 @@ GetFirstNode (
@param List A pointer to the head node of a doubly linked list.
@param Node A pointer to a node in the doubly linked list.
- @return Pointer to the next node if one exists. Otherwise a null value which
- is actually List is returned.
+ @return Pointer to the next node if one exists. Otherwise List is returned.
**/
LIST_ENTRY *
@@ -296,6 +295,42 @@ GetNextNode (
}
/**
+ 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 PcdMaximumLinkedListLenth is not zero, and List contains more than
+ PcdMaximumLinkedListLenth nodes, then ASSERT().
+ If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().
+
+ @param List A pointer to the head node of a doubly linked list.
+ @param Node A pointer to a node in the doubly linked list.
+
+ @return Pointer to the previous node if one exists. Otherwise List is returned.
+
+**/
+LIST_ENTRY *
+EFIAPI
+GetPreviousNode (
+ IN CONST LIST_ENTRY *List,
+ IN CONST LIST_ENTRY *Node
+ )
+{
+ //
+ // ASSERT List not too long and Node is one of the nodes of List
+ //
+ ASSERT (InternalBaseLibIsNodeInList (List, Node, TRUE));
+
+ return Node->BackLink;
+}
+
+/**
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