Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
4.7 KiB

  1. /*** list.c - Miscellaneous functions
  2. *
  3. * Copyright (c) 1996,1997 Microsoft Corporation
  4. * Author: Michael Tsang (MikeTs)
  5. * Created 09/13/96
  6. *
  7. * MODIFICATION HISTORY
  8. */
  9. #include "pch.h"
  10. #ifdef LOCKABLE_PRAGMA
  11. #pragma ACPI_LOCKABLE_DATA
  12. #pragma ACPI_LOCKABLE_CODE
  13. #endif
  14. /***LP ListRemoveEntry - Remove an entry from the list
  15. *
  16. * ENTRY
  17. * plist -> list object to be removed
  18. * pplistHead -> list head pointer
  19. *
  20. * EXIT
  21. * None
  22. */
  23. VOID EXPORT ListRemoveEntry(PLIST plist, PPLIST pplistHead)
  24. {
  25. TRACENAME("LISTREMOVEENTRY")
  26. ASSERT(pplistHead);
  27. ENTER(4, ("ListRemoveEntry(plist=%x,plistHead=%x)\n", plist, *pplistHead));
  28. ASSERT(plist != NULL);
  29. if (plist->plistNext == plist)
  30. {
  31. //
  32. // This is the only object in the list, it must be the head too.
  33. //
  34. ASSERT(plist == *pplistHead);
  35. *pplistHead = NULL;
  36. }
  37. else
  38. {
  39. if (plist == *pplistHead)
  40. {
  41. //
  42. // The entry is at the head, so the next one becomes the new
  43. // head.
  44. //
  45. *pplistHead = (*pplistHead)->plistNext;
  46. }
  47. plist->plistNext->plistPrev = plist->plistPrev;
  48. plist->plistPrev->plistNext = plist->plistNext;
  49. }
  50. EXIT(4, ("ListRemoveEntry! (plistHead=%x)\n", *pplistHead));
  51. } //ListRemoveEntry
  52. /***LP ListRemoveHead - Remove the head entry of the list
  53. *
  54. * ENTRY
  55. * pplistHead -> list head pointer
  56. *
  57. * EXIT
  58. * returns the removed entry
  59. */
  60. PLIST EXPORT ListRemoveHead(PPLIST pplistHead)
  61. {
  62. TRACENAME("LISTREMOVEHEAD")
  63. PLIST plist;
  64. ASSERT(pplistHead);
  65. ENTER(4, ("ListRemoveHead(plistHead=%x)\n", *pplistHead));
  66. if ((plist = *pplistHead) != NULL)
  67. ListRemoveEntry(plist, pplistHead);
  68. EXIT(4, ("ListRemoveHead=%x (plistHead=%x)\n", plist, *pplistHead));
  69. return plist;
  70. } //ListRemoveHead
  71. /***LP ListRemoveTail - Remove the tail entry of the list
  72. *
  73. * ENTRY
  74. * pplistHead -> list head pointer
  75. *
  76. * EXIT
  77. * returns the removed entry
  78. */
  79. PLIST EXPORT ListRemoveTail(PPLIST pplistHead)
  80. {
  81. TRACENAME("LISTREMOVETAIL")
  82. PLIST plist;
  83. ASSERT(pplistHead);
  84. ENTER(4, ("ListRemoveTail(plistHead=%x)\n", *pplistHead));
  85. if (*pplistHead == NULL)
  86. plist = NULL;
  87. else
  88. {
  89. //
  90. // List is not empty, so find the tail.
  91. //
  92. plist = (*pplistHead)->plistPrev;
  93. ListRemoveEntry(plist, pplistHead);
  94. }
  95. EXIT(4, ("ListRemoveTail=%x (plistHead=%x)\n", plist, *pplistHead));
  96. return plist;
  97. } //ListRemoveTail
  98. /***LP ListRemoveAll - Remove all elements in the list
  99. *
  100. * ENTRY
  101. * pplistHead -> list head pointer
  102. *
  103. * EXIT
  104. * None
  105. */
  106. VOID EXPORT ListRemoveAll(PPLIST pplistHead)
  107. {
  108. TRACENAME("LISTREMOVEALL")
  109. ASSERT(pplistHead);
  110. ENTER(4, ("ListRemoveAll(plistHead=%x)\n", *pplistHead));
  111. while (*pplistHead != NULL)
  112. {
  113. ListRemoveTail(pplistHead);
  114. }
  115. EXIT(4, ("ListRemoveAll! (plistHead=%x)\n", *pplistHead));
  116. } //ListRemoveAll
  117. /***LP ListInsertHead - Insert an entry at the head of the list
  118. *
  119. * ENTRY
  120. * plist -> list object to be inserted
  121. * pplistHead -> list head pointer
  122. *
  123. * EXIT
  124. * None
  125. */
  126. VOID EXPORT ListInsertHead(PLIST plist, PPLIST pplistHead)
  127. {
  128. TRACENAME("LISTINSERTHEAD")
  129. ASSERT(pplistHead != NULL);
  130. ENTER(4, ("ListInsertHead(plist=%x,plistHead=%x)\n", plist, *pplistHead));
  131. ASSERT(plist != NULL);
  132. ListInsertTail(plist, pplistHead);
  133. *pplistHead = plist;
  134. EXIT(4, ("ListInsertHead! (plistHead=%x)\n", *pplistHead));
  135. } //ListInsertHead
  136. /***LP ListInsertTail - Insert an entry at the tail of the list
  137. *
  138. * ENTRY
  139. * plist -> list object to be inserted
  140. * pplistHead -> list head pointer
  141. *
  142. * EXIT
  143. * None
  144. */
  145. VOID EXPORT ListInsertTail(PLIST plist, PPLIST pplistHead)
  146. {
  147. TRACENAME("LISTINSERTTAIL")
  148. ASSERT(pplistHead != NULL);
  149. ENTER(4, ("ListInsertTail(plist=%x,plistHead=%x)\n", plist, *pplistHead));
  150. ASSERT(plist != NULL);
  151. if (*pplistHead == NULL)
  152. {
  153. //
  154. // List is empty, so this becomes the head.
  155. //
  156. *pplistHead = plist;
  157. plist->plistPrev = plist->plistNext = plist;
  158. }
  159. else
  160. {
  161. plist->plistNext = *pplistHead;
  162. plist->plistPrev = (*pplistHead)->plistPrev;
  163. (*pplistHead)->plistPrev->plistNext = plist;
  164. (*pplistHead)->plistPrev = plist;
  165. }
  166. EXIT(4, ("ListInsertTail! (plistHead=%x)\n", *pplistHead));
  167. } //ListInsertTail