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.

124 lines
2.4 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 "newdpf.h"
  15. #include <dplaypr.h>
  16. #include "bilink.h"
  17. #include "mydebug.h"
  18. // Note: serialization of access to BILINK structures must
  19. // take place in the calling code. Operations are
  20. // not intrinsically atomic.
  21. #ifdef DEBUG
  22. int FindObject(
  23. BILINK *link,
  24. BILINK *list
  25. )
  26. {
  27. BILINK *p = list->next;
  28. while(p != link && p != list)
  29. p= p->next;
  30. return (p==link);
  31. }
  32. #endif
  33. void InsertAfter(
  34. BILINK *in,
  35. BILINK *after
  36. )
  37. /*=========================================================================
  38. * Description:
  39. * Insert an object after a specified object in the doubly linked list.
  40. * The after object could be the Head BILINK for adding to the head of a
  41. * queue.
  42. * Returns:
  43. *
  44. */
  45. {
  46. #ifdef DEBUG
  47. if(FindObject(in,after)) {
  48. DPF(0,"Attempt to re-insert object in BILINK queue\n");
  49. DEBUG_BREAK();
  50. }
  51. #endif
  52. in->next = after->next;
  53. in->prev = after;
  54. after->next->prev = in;
  55. after->next = in;
  56. }
  57. void InsertBefore(
  58. BILINK *in,
  59. BILINK *before
  60. )
  61. /*=========================================================================
  62. * Description:
  63. * Inserts an object before a specified object in the doubly linked list.
  64. * The before object could be the Head BILINK for adding to the end
  65. * of the queue
  66. * CALLED WITH INTERRUPTS_OFF
  67. *
  68. * Returns:
  69. *
  70. */
  71. {
  72. #ifdef DEBUG
  73. if(FindObject(in,before)) {
  74. DPF(0,"Attempt to re-insert object in BILINK queue\n");
  75. DEBUG_BREAK();
  76. }
  77. #endif
  78. in->next = before;
  79. in->prev = before->prev;
  80. before->prev->next = in;
  81. before->prev = in;
  82. }
  83. void Delete(
  84. BILINK *p
  85. )
  86. /*=========================================================================
  87. * Description:
  88. *
  89. * Delete a object from a doubly linked list. Make sure it IS on a list!
  90. * CALLED WITH INTERRUPTS OFF (must be atomic).
  91. *
  92. * Returns:
  93. *
  94. */
  95. {
  96. ASSERT(p && p->prev && p->next);
  97. if(!p && p->prev && p->next){
  98. DEBUG_BREAK();
  99. }
  100. ASSERT(p->prev->next == p && p->next->prev == p);
  101. if(!(p->prev->next == p && p->next->prev == p)){
  102. DEBUG_BREAK();
  103. }
  104. p->next->prev = p->prev;
  105. p->prev->next = p->next;
  106. // p->next = p->prev = 0;
  107. }