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.

163 lines
3.9 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. /***LP ListRemoveEntry - Remove an entry from the list
  11. *
  12. * ENTRY
  13. * plist -> list object to be removed
  14. * pplistHead -> list head pointer
  15. *
  16. * EXIT
  17. * None
  18. */
  19. VOID EXPORT ListRemoveEntry(PLIST plist, PPLIST pplistHead)
  20. {
  21. ASSERT(pplistHead);
  22. ENTER((4, "ListRemoveEntry(plist=%p,plistHead=%p)\n", plist, *pplistHead));
  23. ASSERT(plist != NULL);
  24. if (plist->plistNext == plist)
  25. {
  26. //
  27. // This is the only object in the list, it must be the head too.
  28. //
  29. ASSERT(plist == *pplistHead);
  30. *pplistHead = NULL;
  31. }
  32. else
  33. {
  34. if (plist == *pplistHead)
  35. {
  36. //
  37. // The entry is at the head, so the next one becomes the new
  38. // head.
  39. //
  40. *pplistHead = (*pplistHead)->plistNext;
  41. }
  42. plist->plistNext->plistPrev = plist->plistPrev;
  43. plist->plistPrev->plistNext = plist->plistNext;
  44. }
  45. EXIT((4, "ListRemoveEntry! (plistHead=%p)\n", *pplistHead));
  46. } //ListRemoveEntry
  47. /***LP ListRemoveHead - Remove the head entry of the list
  48. *
  49. * ENTRY
  50. * pplistHead -> list head pointer
  51. *
  52. * EXIT
  53. * returns the removed entry
  54. */
  55. PLIST EXPORT ListRemoveHead(PPLIST pplistHead)
  56. {
  57. PLIST plist;
  58. ASSERT(pplistHead);
  59. ENTER((4, "ListRemoveHead(plistHead=%p)\n", *pplistHead));
  60. if ((plist = *pplistHead) != NULL)
  61. ListRemoveEntry(plist, pplistHead);
  62. EXIT((4, "ListRemoveHead=%p (plistHead=%p)\n", plist, *pplistHead));
  63. return plist;
  64. } //ListRemoveHead
  65. /***LP ListRemoveTail - Remove the tail entry of the list
  66. *
  67. * ENTRY
  68. * pplistHead -> list head pointer
  69. *
  70. * EXIT
  71. * returns the removed entry
  72. */
  73. PLIST EXPORT ListRemoveTail(PPLIST pplistHead)
  74. {
  75. PLIST plist;
  76. ASSERT(pplistHead);
  77. ENTER((4, "ListRemoveTail(plistHead=%p)\n", *pplistHead));
  78. if (*pplistHead == NULL)
  79. plist = NULL;
  80. else
  81. {
  82. //
  83. // List is not empty, so find the tail.
  84. //
  85. plist = (*pplistHead)->plistPrev;
  86. ListRemoveEntry(plist, pplistHead);
  87. }
  88. EXIT((4, "ListRemoveTail=%p (plistHead=%p)\n", plist, *pplistHead));
  89. return plist;
  90. } //ListRemoveTail
  91. /***LP ListInsertHead - Insert an entry at the head of the list
  92. *
  93. * ENTRY
  94. * plist -> list object to be inserted
  95. * pplistHead -> list head pointer
  96. *
  97. * EXIT
  98. * None
  99. */
  100. VOID EXPORT ListInsertHead(PLIST plist, PPLIST pplistHead)
  101. {
  102. ASSERT(pplistHead != NULL);
  103. ENTER((4, "ListInsertHead(plist=%p,plistHead=%p)\n", plist, *pplistHead));
  104. ASSERT(plist != NULL);
  105. ListInsertTail(plist, pplistHead);
  106. *pplistHead = plist;
  107. EXIT((4, "ListInsertHead! (plistHead=%p)\n", *pplistHead));
  108. } //ListInsertHead
  109. /***LP ListInsertTail - Insert an entry at the tail of the list
  110. *
  111. * ENTRY
  112. * plist -> list object to be inserted
  113. * pplistHead -> list head pointer
  114. *
  115. * EXIT
  116. * None
  117. */
  118. VOID EXPORT ListInsertTail(PLIST plist, PPLIST pplistHead)
  119. {
  120. ASSERT(pplistHead != NULL);
  121. ENTER((4, "ListInsertTail(plist=%p,plistHead=%p)\n", plist, *pplistHead));
  122. ASSERT(plist != NULL);
  123. if (*pplistHead == NULL)
  124. {
  125. //
  126. // List is empty, so this becomes the head.
  127. //
  128. *pplistHead = plist;
  129. plist->plistPrev = plist->plistNext = plist;
  130. }
  131. else
  132. {
  133. plist->plistNext = *pplistHead;
  134. plist->plistPrev = (*pplistHead)->plistPrev;
  135. (*pplistHead)->plistPrev->plistNext = plist;
  136. (*pplistHead)->plistPrev = plist;
  137. }
  138. EXIT((4, "ListInsertTail! (plistHead=%p)\n", *pplistHead));
  139. } //ListInsertTail