Source code of Windows XP (NT5)
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.

117 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. BILINK.C
  5. Abstract:
  6. Management for doubly linked lists
  7. Author:
  8. George Joy
  9. Environment:
  10. 32-bit 'C'
  11. Revision History:
  12. --*/
  13. #include <windows.h>
  14. #include "dpsp.h"
  15. #include <dpf.h>
  16. #include "bilink.h"
  17. // Note: serialization of access to BILINK structures must
  18. // take place in the calling code. Operations are
  19. // not intrinsically atomic.
  20. #ifdef DEBUG
  21. int FindObject(
  22. BILINK *link,
  23. BILINK *list
  24. )
  25. {
  26. BILINK *p = list->next;
  27. while(p != link && p != list)
  28. p= p->next;
  29. return (p==link);
  30. }
  31. #endif
  32. void InsertAfter(
  33. BILINK *in,
  34. BILINK *after
  35. )
  36. /*=========================================================================
  37. * Description:
  38. * Insert an object after a specified object in the doubly linked list.
  39. * The after object could be the Head BILINK for adding to the head of a
  40. * queue.
  41. * Returns:
  42. *
  43. */
  44. {
  45. #ifdef DEBUG
  46. if(FindObject(in,after)) {
  47. DPF(0,"Attempt to re-insert object in BILINK queue\n");
  48. DEBUG_BREAK();
  49. }
  50. #endif
  51. in->next = after->next;
  52. in->prev = after;
  53. after->next->prev = in;
  54. after->next = in;
  55. }
  56. void InsertBefore(
  57. BILINK *in,
  58. BILINK *before
  59. )
  60. /*=========================================================================
  61. * Description:
  62. * Inserts an object before a specified object in the doubly linked list.
  63. * The before object could be the Head BILINK for adding to the end
  64. * of the queue
  65. * CALLED WITH INTERRUPTS_OFF
  66. *
  67. * Returns:
  68. *
  69. */
  70. {
  71. #ifdef DEBUG
  72. if(FindObject(in,before)) {
  73. DPF(0,"Attempt to re-insert object in BILINK queue\n");
  74. DEBUG_BREAK();
  75. }
  76. #endif
  77. in->next = before;
  78. in->prev = before->prev;
  79. before->prev->next = in;
  80. before->prev = in;
  81. }
  82. void Delete(
  83. BILINK *p
  84. )
  85. /*=========================================================================
  86. * Description:
  87. *
  88. * Delete a object from a doubly linked list. Make sure it IS on a list!
  89. * CALLED WITH INTERRUPTS OFF (must be atomic).
  90. *
  91. * Returns:
  92. *
  93. */
  94. {
  95. ASSERT(p && p->prev && p->next);
  96. ASSERT(p->prev->next == p && p->next->prev == p);
  97. p->next->prev = p->prev;
  98. p->prev->next = p->next;
  99. // p->next = p->prev = 0;
  100. }