summaryrefslogtreecommitdiffstats
path: root/MdePkg/Library/BaseLib/LinkedList.c
diff options
context:
space:
mode:
authorMarvin.Haeuser@outlook.com <Marvin.Haeuser@outlook.com>2017-08-04 03:52:08 +0800
committerLiming Gao <liming.gao@intel.com>2017-08-16 16:55:30 +0800
commitd0aef615acb0b1cb3c1662a7d2562ea7bef471ec (patch)
treeddc1f574dd4157472349c39c93cd59af605c7992 /MdePkg/Library/BaseLib/LinkedList.c
parent8a765da2a3da23607cd46c18c7d05937cd09d799 (diff)
downloadedk2-d0aef615acb0b1cb3c1662a7d2562ea7bef471ec.tar.gz
edk2-d0aef615acb0b1cb3c1662a7d2562ea7bef471ec.tar.bz2
edk2-d0aef615acb0b1cb3c1662a7d2562ea7bef471ec.zip
MdePkg/BaseLib: Add IsNodeInList() function.
This patch adds IsNodeInList() to BaseLib, which verifies the given Node is part of the doubly-linked List provided. V2: - Rename "List" to "FirstEntry" and "Node" to "SecondEntry" to clarify that "FirstEntry" does not need to be the doubly-linked list's head node. V3: - Remove ASSERTs from IsNodeInList() which are present in InternalBaseLibIsListValid(). Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marvin Haeuser <Marvin.Haeuser@outlook.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
Diffstat (limited to 'MdePkg/Library/BaseLib/LinkedList.c')
-rw-r--r--MdePkg/Library/BaseLib/LinkedList.c66
1 files changed, 65 insertions, 1 deletions
diff --git a/MdePkg/Library/BaseLib/LinkedList.c b/MdePkg/Library/BaseLib/LinkedList.c
index ba373f4b7b..af27b0dd9a 100644
--- a/MdePkg/Library/BaseLib/LinkedList.c
+++ b/MdePkg/Library/BaseLib/LinkedList.c
@@ -1,7 +1,7 @@
/** @file
Linked List Library Functions.
- Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -113,6 +113,70 @@ InternalBaseLibIsNodeInList (
}
/**
+ 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().
+
+ @param FirstEntry A pointer to a node in a linked list.
+ @param SecondEntry A pointer to the node to locate.
+
+ @retval TRUE SecondEntry is in the same doubly-linked list as FirstEntry.
+ @retval FALSE SecondEntry isn't in the same doubly-linked list as FirstEntry,
+ or FirstEntry is invalid.
+
+**/
+BOOLEAN
+EFIAPI
+IsNodeInList (
+ IN CONST LIST_ENTRY *FirstEntry,
+ IN CONST LIST_ENTRY *SecondEntry
+ )
+{
+ UINTN Count;
+ CONST LIST_ENTRY *Ptr;
+
+ //
+ // ASSERT List not too long
+ //
+ ASSERT (InternalBaseLibIsListValid (FirstEntry));
+
+ ASSERT (SecondEntry != NULL);
+
+ Count = 0;
+ Ptr = FirstEntry;
+
+ //
+ // Check to see if SecondEntry is a member of FirstEntry.
+ // Exit early if the number of nodes in List >= PcdMaximumLinkedListLength
+ //
+ do {
+ Ptr = Ptr->ForwardLink;
+ if (PcdGet32 (PcdMaximumLinkedListLength) > 0) {
+ Count++;
+
+ //
+ // Return if the linked list is too long
+ //
+ if (Count == PcdGet32 (PcdMaximumLinkedListLength)) {
+ return (BOOLEAN)(Ptr == SecondEntry);
+ }
+ }
+
+ if (Ptr == SecondEntry) {
+ return TRUE;
+ }
+ } while (Ptr != FirstEntry);
+
+ return FALSE;
+}
+
+/**
Initializes the head node of a doubly-linked list, and returns the pointer to
the head node of the doubly-linked list.