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.

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