]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/LinkedList.c
Rename BaseLib internal functions by adding InternalBaseLib.
[mirror_edk2.git] / MdePkg / Library / BaseLib / LinkedList.c
index 3cbc0447a0f43e33b29b2770740443b632d6ccaf..62b6c364783afc137f21098c7808f8c978a49839 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Linked List Library Functions.\r
 \r
-  Copyright (c) 2006, Intel Corporation<BR>\r
+  Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
   All rights reserved. This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-  Module Name:  LinkedList.c\r
-\r
 **/\r
 \r
-//\r
-// Include common header file for this module.\r
-//\r
-#include "CommonHeader.h"\r
-\r
 #include "BaseLibInternals.h"\r
 \r
 /**\r
-  Worker function that locates the Node in the List\r
+  Worker function that locates the Node in the List.\r
 \r
   By searching the List, finds the location of the Node in List. At the same time,\r
   verifies the validity of this list.\r
@@ -43,7 +36,8 @@
 \r
 **/\r
 BOOLEAN\r
-IsNodeInList (\r
+EFIAPI\r
+InternalBaseLibIsNodeInList (\r
   IN      CONST LIST_ENTRY      *List,\r
   IN      CONST LIST_ENTRY      *Node\r
   )\r
@@ -99,15 +93,15 @@ IsNodeInList (
 LIST_ENTRY *\r
 EFIAPI\r
 InitializeListHead (\r
-  IN OUT  LIST_ENTRY            *List\r
+  IN OUT  LIST_ENTRY                *ListHead\r
   )\r
 \r
 {\r
-  ASSERT (List != NULL);\r
+  ASSERT (ListHead != NULL);\r
 \r
-  List->ForwardLink = List;\r
-  List->BackLink = List;\r
-  return List;\r
+  ListHead->ForwardLink = ListHead;\r
+  ListHead->BackLink = ListHead;\r
+  return ListHead;\r
 }\r
 \r
 /**\r
@@ -119,7 +113,8 @@ InitializeListHead (
 \r
   If ListHead is NULL, then ASSERT().\r
   If Entry is NULL, then ASSERT().\r
-  If ListHead was not initialized with InitializeListHead(), then ASSERT().\r
+  If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or\r
+  InitializeListHead(), then ASSERT().\r
   If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number\r
   of nodes in ListHead, including the ListHead node, is greater than or\r
   equal to PcdMaximumLinkedListLength, then ASSERT().\r
@@ -134,20 +129,20 @@ InitializeListHead (
 LIST_ENTRY *\r
 EFIAPI\r
 InsertHeadList (\r
-  IN OUT  LIST_ENTRY            *List,\r
-  IN OUT  LIST_ENTRY            *Entry\r
+  IN OUT  LIST_ENTRY                *ListHead,\r
+  IN OUT  LIST_ENTRY                *Entry\r
   )\r
 {\r
   //\r
   // ASSERT List not too long and Entry is not one of the nodes of List\r
   //\r
-  ASSERT (!IsNodeInList (List, Entry));\r
+  ASSERT (!InternalBaseLibIsNodeInList (ListHead, Entry));\r
 \r
-  Entry->ForwardLink = List->ForwardLink;\r
-  Entry->BackLink = List;\r
+  Entry->ForwardLink = ListHead->ForwardLink;\r
+  Entry->BackLink = ListHead;\r
   Entry->ForwardLink->BackLink = Entry;\r
-  List->ForwardLink = Entry;\r
-  return List;\r
+  ListHead->ForwardLink = Entry;\r
+  return ListHead;\r
 }\r
 \r
 /**\r
@@ -159,7 +154,8 @@ InsertHeadList (
 \r
   If ListHead is NULL, then ASSERT().\r
   If Entry is NULL, then ASSERT().\r
-  If ListHead was not initialized with InitializeListHead(), then ASSERT().\r
+  If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or \r
+  InitializeListHead(), then ASSERT().\r
   If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number\r
   of nodes in ListHead, including the ListHead node, is greater than or\r
   equal to PcdMaximumLinkedListLength, then ASSERT().\r
@@ -174,31 +170,32 @@ InsertHeadList (
 LIST_ENTRY *\r
 EFIAPI\r
 InsertTailList (\r
-  IN OUT  LIST_ENTRY            *List,\r
-  IN OUT  LIST_ENTRY            *Entry\r
+  IN OUT  LIST_ENTRY                *ListHead,\r
+  IN OUT  LIST_ENTRY                *Entry\r
   )\r
 {\r
   //\r
   // ASSERT List not too long and Entry is not one of the nodes of List\r
   //\r
-  ASSERT (!IsNodeInList (List, Entry));\r
+  ASSERT (!InternalBaseLibIsNodeInList (ListHead, Entry));\r
 \r
-  Entry->ForwardLink = List;\r
-  Entry->BackLink = List->BackLink;\r
+  Entry->ForwardLink = ListHead;\r
+  Entry->BackLink = ListHead->BackLink;\r
   Entry->BackLink->ForwardLink = Entry;\r
-  List->BackLink = Entry;\r
-  return List;\r
+  ListHead->BackLink = Entry;\r
+  return ListHead;\r
 }\r
 \r
 /**\r
   Retrieves the first node of a doubly linked list.\r
 \r
-  Returns the first node of a doubly linked list. List must have been\r
-  initialized with InitializeListHead(). If List is empty, then NULL is\r
-  returned.\r
+  Returns the first node of a doubly linked list.  List must have been \r
+  initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().\r
+  If List is empty, then List is returned.\r
 \r
   If List is NULL, then ASSERT().\r
-  If List was not initialized with InitializeListHead(), then ASSERT().\r
+  If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or \r
+  InitializeListHead(), then ASSERT().\r
   If PcdMaximumLinkedListLenth is not zero, and the number of nodes\r
   in List, including the List node, is greater than or equal to\r
   PcdMaximumLinkedListLength, then ASSERT().\r
@@ -212,13 +209,13 @@ InsertTailList (
 LIST_ENTRY *\r
 EFIAPI\r
 GetFirstNode (\r
-  IN CONST LIST_ENTRY  *List\r
+  IN      CONST LIST_ENTRY          *List\r
   )\r
 {\r
   //\r
   // ASSERT List not too long\r
   //\r
-  ASSERT (IsNodeInList (List, List));\r
+  ASSERT (InternalBaseLibIsNodeInList (List, List));\r
 \r
   return List->ForwardLink;\r
 }\r
@@ -226,13 +223,14 @@ GetFirstNode (
 /**\r
   Retrieves the next node of a doubly linked list.\r
 \r
-  Returns the node of a doubly linked list that follows Node. List must have\r
-  been initialized with InitializeListHead(). If List is empty, then List is\r
-  returned.\r
+  Returns the node of a doubly linked list that follows Node.  \r
+  List must have been initialized with INTIALIZE_LIST_HEAD_VARIABLE()\r
+  or InitializeListHead().  If List is empty, then List is returned.\r
 \r
   If List is NULL, then ASSERT().\r
   If Node is NULL, then ASSERT().\r
-  If List was not initialized with InitializeListHead(), then ASSERT().\r
+  If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or \r
+  InitializeListHead(), then ASSERT().\r
   If PcdMaximumLinkedListLenth is not zero, and List contains more than\r
   PcdMaximumLinkedListLenth nodes, then ASSERT().\r
   If Node is not a node in List, then ASSERT().\r
@@ -247,14 +245,14 @@ GetFirstNode (
 LIST_ENTRY *\r
 EFIAPI\r
 GetNextNode (\r
-  IN CONST LIST_ENTRY  *List,\r
-  IN CONST LIST_ENTRY  *Node\r
+  IN      CONST LIST_ENTRY          *List,\r
+  IN      CONST LIST_ENTRY          *Node\r
   )\r
 {\r
   //\r
   // ASSERT List not too long and Node is one of the nodes of List\r
   //\r
-  ASSERT (IsNodeInList (List, Node));\r
+  ASSERT (InternalBaseLibIsNodeInList (List, Node));\r
 \r
   return Node->ForwardLink;\r
 }\r
@@ -266,7 +264,8 @@ GetNextNode (
   zero nodes, this function returns TRUE. Otherwise, it returns FALSE.\r
 \r
   If ListHead is NULL, then ASSERT().\r
-  If ListHead was not initialized with InitializeListHead(), then ASSERT().\r
+  If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or \r
+  InitializeListHead(), then ASSERT().\r
   If PcdMaximumLinkedListLenth is not zero, and the number of nodes\r
   in List, including the List node, is greater than or equal to\r
   PcdMaximumLinkedListLength, then ASSERT().\r
@@ -280,27 +279,30 @@ GetNextNode (
 BOOLEAN\r
 EFIAPI\r
 IsListEmpty (\r
-  IN      CONST LIST_ENTRY      *List\r
+  IN      CONST LIST_ENTRY          *ListHead\r
   )\r
 {\r
   //\r
   // ASSERT List not too long\r
   //\r
-  ASSERT (IsNodeInList (List, List));\r
+  ASSERT (InternalBaseLibIsNodeInList (ListHead, ListHead));\r
 \r
-  return (BOOLEAN)(List->ForwardLink == List);\r
+  return (BOOLEAN)(ListHead->ForwardLink == ListHead);\r
 }\r
 \r
 /**\r
-  Determines if a node in a doubly linked list is null.\r
+  Determines if a node in a doubly linked list is the head node of a the same\r
+  doubly linked list.  This function is typically used to terminate a loop that\r
+  traverses all the nodes in a doubly linked list starting with the head node.\r
 \r
-  Returns FALSE if Node is one of the nodes in the doubly linked list specified\r
-  by List. Otherwise, TRUE is returned. List must have been initialized with\r
-  InitializeListHead().\r
+  Returns TRUE if Node is equal to List.  Returns FALSE if Node is one of the\r
+  nodes in the doubly linked list specified by List.  List must have been\r
+  initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().\r
 \r
   If List is NULL, then ASSERT().\r
   If Node is NULL, then ASSERT().\r
-  If List was not initialized with InitializeListHead(), then ASSERT().\r
+  If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(), \r
+  then ASSERT().\r
   If PcdMaximumLinkedListLenth is not zero, and the number of nodes\r
   in List, including the List node, is greater than or equal to\r
   PcdMaximumLinkedListLength, then ASSERT().\r
@@ -316,14 +318,14 @@ IsListEmpty (
 BOOLEAN\r
 EFIAPI\r
 IsNull (\r
-  IN      CONST LIST_ENTRY      *List,\r
-  IN      CONST LIST_ENTRY      *Node\r
+  IN      CONST LIST_ENTRY          *List,\r
+  IN      CONST LIST_ENTRY          *Node\r
   )\r
 {\r
   //\r
   // ASSERT List not too long and Node is one of the nodes of List\r
   //\r
-  ASSERT (IsNodeInList (List, Node));\r
+  ASSERT (InternalBaseLibIsNodeInList (List, Node));\r
 \r
   return (BOOLEAN)(Node == List);\r
 }\r
@@ -333,11 +335,12 @@ IsNull (
 \r
   Returns TRUE if Node is the last node in the doubly linked list specified by\r
   List. Otherwise, FALSE is returned. List must have been initialized with\r
-  InitializeListHead().\r
+  INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().\r
 \r
   If List is NULL, then ASSERT().\r
   If Node is NULL, then ASSERT().\r
-  If List was not initialized with InitializeListHead(), then ASSERT().\r
+  If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or\r
+  InitializeListHead(), then ASSERT().\r
   If PcdMaximumLinkedListLenth is not zero, and the number of nodes\r
   in List, including the List node, is greater than or equal to\r
   PcdMaximumLinkedListLength, then ASSERT().\r
@@ -353,14 +356,14 @@ IsNull (
 BOOLEAN\r
 EFIAPI\r
 IsNodeAtEnd (\r
-  IN      CONST LIST_ENTRY      *List,\r
-  IN      CONST LIST_ENTRY      *Node\r
+  IN      CONST LIST_ENTRY          *List,\r
+  IN      CONST LIST_ENTRY          *Node\r
   )\r
 {\r
   //\r
   // ASSERT List not too long and Node is one of the nodes of List\r
   //\r
-  ASSERT (IsNodeInList (List, Node));\r
+  ASSERT (InternalBaseLibIsNodeInList (List, Node));\r
 \r
   return (BOOLEAN)(!IsNull (List, Node) && List->BackLink == Node);\r
 }\r
@@ -373,8 +376,8 @@ IsNodeAtEnd (
   Otherwise, the location of the FirstEntry node is swapped with the location\r
   of the SecondEntry node in a doubly linked list. SecondEntry must be in the\r
   same double linked list as FirstEntry and that double linked list must have\r
-  been initialized with InitializeListHead(). SecondEntry is returned after the\r
-  nodes are swapped.\r
+  been initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(). \r
+  SecondEntry is returned after the nodes are swapped.\r
 \r
   If FirstEntry is NULL, then ASSERT().\r
   If SecondEntry is NULL, then ASSERT().\r
@@ -386,13 +389,15 @@ IsNodeAtEnd (
 \r
   @param  FirstEntry  A pointer to a node in a linked list.\r
   @param  SecondEntry A pointer to another node in the same linked list.\r
+  \r
+  @return SecondEntry.\r
 \r
 **/\r
 LIST_ENTRY *\r
 EFIAPI\r
 SwapListEntries (\r
-  IN OUT  LIST_ENTRY            *FirstEntry,\r
-  IN OUT  LIST_ENTRY            *SecondEntry\r
+  IN OUT  LIST_ENTRY                *FirstEntry,\r
+  IN OUT  LIST_ENTRY                *SecondEntry\r
   )\r
 {\r
   LIST_ENTRY                    *Ptr;\r
@@ -404,7 +409,7 @@ SwapListEntries (
   //\r
   // ASSERT Entry1 and Entry2 are in the same linked list\r
   //\r
-  ASSERT (IsNodeInList (FirstEntry, SecondEntry));\r
+  ASSERT (InternalBaseLibIsNodeInList (FirstEntry, SecondEntry));\r
 \r
   //\r
   // Ptr is the node pointed to by FirstEntry->ForwardLink\r
@@ -412,7 +417,7 @@ SwapListEntries (
   Ptr = RemoveEntryList (FirstEntry);\r
 \r
   //\r
-  // If FirstEntry immediately follows SecondEntry, FirstEntry willl be placed\r
+  // If FirstEntry immediately follows SecondEntry, FirstEntry will be placed\r
   // immediately in front of SecondEntry\r
   //\r
   if (Ptr->BackLink == SecondEntry) {\r
@@ -451,15 +456,15 @@ SwapListEntries (
   linked list containing Entry, including the Entry node, is greater than\r
   or equal to PcdMaximumLinkedListLength, then ASSERT().\r
 \r
-  @param  Entry A pointer to a node in a linked list\r
+  @param  Entry A pointer to a node in a linked list.\r
 \r
-  @return Entry\r
+  @return Entry.\r
 \r
 **/\r
 LIST_ENTRY *\r
 EFIAPI\r
 RemoveEntryList (\r
-  IN      CONST LIST_ENTRY      *Entry\r
+  IN      CONST LIST_ENTRY          *Entry\r
   )\r
 {\r
   ASSERT (!IsListEmpty (Entry));\r