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.

112 lines
2.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: queue.cxx
  7. //
  8. // Contents: CQueue class implementation.
  9. //
  10. // Classes: CQueue
  11. //
  12. // Functions: None.
  13. //
  14. // History: 25-Oct-95 MarkBl Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "..\pch\headers.hxx"
  18. #pragma hdrstop
  19. #include "debug.hxx"
  20. #include "queue.hxx"
  21. //+---------------------------------------------------------------------------
  22. //
  23. // Member: CQueue::AddElement
  24. //
  25. // Synopsis: Add an element to the linked list.
  26. //
  27. // Arguments: [pdl] -- Doubly-linked list element.
  28. //
  29. // Notes: None.
  30. //
  31. //----------------------------------------------------------------------------
  32. void
  33. CQueue::AddElement(CDLink * pdl)
  34. {
  35. schAssert(pdl != NULL);
  36. //
  37. // NB: maintain a circular list to insure FIFO ordering.
  38. //
  39. if (_pdlFirst == NULL)
  40. {
  41. _pdlFirst = pdl;
  42. }
  43. else
  44. {
  45. pdl->LinkAfter(_pdlFirst->Prev());
  46. }
  47. _pdlFirst->SetPrev(pdl);
  48. ++_cElems;
  49. }
  50. //+---------------------------------------------------------------------------
  51. //
  52. // Member: CQueue::RemoveElement
  53. //
  54. // Synopsis: Remove an element to the linked list.
  55. //
  56. // Arguments: [pdl] -- Doubly-linked list element.
  57. //
  58. // Notes: None.
  59. //
  60. //----------------------------------------------------------------------------
  61. CDLink *
  62. CQueue::RemoveElement(CDLink * pdl)
  63. {
  64. if (pdl != NULL)
  65. {
  66. if (pdl == _pdlFirst)
  67. {
  68. //
  69. // Special case list head.
  70. //
  71. if (pdl->Next() != NULL)
  72. {
  73. pdl->Next()->SetPrev(pdl->Prev());
  74. }
  75. _pdlFirst = pdl->Next();
  76. pdl->SetNext(NULL);
  77. pdl->SetPrev(NULL);
  78. }
  79. else
  80. {
  81. //
  82. // If deleting last entry in list, must make list head
  83. // point to new last entry.
  84. //
  85. if (pdl == _pdlFirst->Prev())
  86. {
  87. _pdlFirst->SetPrev(pdl->Prev());
  88. }
  89. //
  90. // Standard node deletion.
  91. //
  92. pdl->UnLink();
  93. }
  94. --_cElems;
  95. }
  96. return(pdl);
  97. }