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.

116 lines
2.9 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1995 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: bilink.c
  6. * Content: Management for doubly linked (BILINK) lists
  7. *@@BEGIN_MSINTERNAL
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 1993 George Joy
  12. * 10/15/99 mjn Changed Delete to initialize bilink element after adjusting pointers
  13. *@@END_MSINTERNAL
  14. *
  15. ***************************************************************************/
  16. #include "dncmni.h"
  17. #include "bilink.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. #undef DPF_MODNAME
  23. #define DPF_MODNAME "FindObject"
  24. int FindObject(BILINK *link,BILINK *list)
  25. {
  26. BILINK *p = list->next;
  27. while(p != link && p != list)
  28. p= p->next;
  29. return (p==link);
  30. }
  31. #endif
  32. /*=========================================================================
  33. * Description:
  34. * Insert an object after a specified object in the doubly linked list.
  35. * The after object could be the Head BILINK for adding to the head of a
  36. * queue.
  37. * Returns:
  38. *
  39. */
  40. #undef DPF_MODNAME
  41. #define DPF_MODNAME "InsertAfter"
  42. void InsertAfter(BILINK *in,BILINK *after)
  43. {
  44. #ifdef DEBUG
  45. if(FindObject(in,after)) {
  46. DPFX(DPFPREP, 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. /*=========================================================================
  56. * Description:
  57. * Inserts an object before a specified object in the doubly linked list.
  58. * The before object could be the Head BILINK for adding to the end
  59. * of the queue
  60. * CALLED WITH INTERRUPTS_OFF
  61. *
  62. * Returns:
  63. *
  64. */
  65. #undef DPF_MODNAME
  66. #define DPF_MODNAME "InsertBefore"
  67. void InsertBefore(BILINK *in,BILINK *before)
  68. {
  69. #ifdef DEBUG
  70. if(FindObject(in,before)) {
  71. DPFX(DPFPREP, 0,"Attempt to re-insert object in BILINK queue\n");
  72. DEBUG_BREAK();
  73. }
  74. #endif
  75. in->next = before;
  76. in->prev = before->prev;
  77. before->prev->next = in;
  78. before->prev = in;
  79. }
  80. /*=========================================================================
  81. * Description:
  82. *
  83. * Delete a object from a doubly linked list. Make sure it IS on a list!
  84. * CALLED WITH INTERRUPTS OFF (must be atomic).
  85. *
  86. * Returns:
  87. *
  88. */
  89. #undef DPF_MODNAME
  90. #define DPF_MODNAME "Delete"
  91. void Delete(BILINK *p)
  92. {
  93. DNASSERT(p && p->prev && p->next);
  94. DNASSERT(p->prev->next == p && p->next->prev == p);
  95. #ifdef DEBUG
  96. if(!p && p->prev && p->next){
  97. DEBUG_BREAK();
  98. }
  99. if(!(p->prev->next == p && p->next->prev == p)){
  100. DEBUG_BREAK();
  101. }
  102. #endif
  103. p->next->prev = p->prev;
  104. p->prev->next = p->next;
  105. InitBilink(p, p->pvObject);
  106. }