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.

164 lines
3.0 KiB

  1. /*++
  2. Copyright(c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. bdgslist.h
  5. Abstract:
  6. Ethernet MAC level bridge
  7. Singly-linked list implementation
  8. Author:
  9. Mark Aiken
  10. (original bridge by Jameel Hyder)
  11. Environment:
  12. Kernel mode driver
  13. Revision History:
  14. Sept 1999 - Original version
  15. Feb 2000 - Overhaul
  16. --*/
  17. //
  18. // A singly-linked list with a length counter
  19. //
  20. typedef struct _BSINGLE_LIST_ENTRY
  21. {
  22. struct _BSINGLE_LIST_ENTRY *Next;
  23. } BSINGLE_LIST_ENTRY, *PBSINGLE_LIST_ENTRY;
  24. typedef struct _BSINGLE_LIST_HEAD
  25. {
  26. PBSINGLE_LIST_ENTRY Head;
  27. PBSINGLE_LIST_ENTRY Tail;
  28. ULONG Length;
  29. } BSINGLE_LIST_HEAD, *PBSINGLE_LIST_HEAD;
  30. //
  31. // Singly-linked list functions
  32. //
  33. __forceinline VOID
  34. BrdgInitializeSingleList(
  35. PBSINGLE_LIST_HEAD Head
  36. )
  37. {
  38. Head->Head = Head->Tail = NULL;
  39. Head->Length = 0L;
  40. }
  41. __forceinline ULONG
  42. BrdgQuerySingleListLength(
  43. PBSINGLE_LIST_HEAD Head
  44. )
  45. {
  46. return Head->Length;
  47. }
  48. __forceinline VOID
  49. BrdgInsertHeadSingleList(
  50. PBSINGLE_LIST_HEAD Head,
  51. PBSINGLE_LIST_ENTRY Entry
  52. )
  53. {
  54. Entry->Next = Head->Head;
  55. Head->Head = Entry;
  56. if( Head->Tail == NULL )
  57. {
  58. Head->Tail = Entry;
  59. }
  60. Head->Length++;
  61. }
  62. __forceinline VOID
  63. BrdgInterlockedInsertHeadSingleList(
  64. PBSINGLE_LIST_HEAD Head,
  65. PBSINGLE_LIST_ENTRY Entry,
  66. PNDIS_SPIN_LOCK Lock
  67. )
  68. {
  69. NdisAcquireSpinLock( Lock );
  70. BrdgInsertHeadSingleList( Head, Entry );
  71. NdisReleaseSpinLock( Lock );
  72. }
  73. __forceinline VOID
  74. BrdgInsertTailSingleList(
  75. PBSINGLE_LIST_HEAD Head,
  76. PBSINGLE_LIST_ENTRY Entry
  77. )
  78. {
  79. Entry->Next = NULL;
  80. if( Head->Tail != NULL )
  81. {
  82. Head->Tail->Next = Entry;
  83. }
  84. if( Head->Head == NULL )
  85. {
  86. Head->Head = Entry;
  87. }
  88. Head->Tail = Entry;
  89. Head->Length++;
  90. }
  91. __forceinline VOID
  92. BrdgInterlockedInsertTailSingleList(
  93. PBSINGLE_LIST_HEAD Head,
  94. PBSINGLE_LIST_ENTRY Entry,
  95. PNDIS_SPIN_LOCK Lock
  96. )
  97. {
  98. NdisAcquireSpinLock( Lock );
  99. BrdgInsertTailSingleList( Head, Entry );
  100. NdisReleaseSpinLock( Lock );
  101. }
  102. __forceinline PBSINGLE_LIST_ENTRY
  103. BrdgRemoveHeadSingleList(
  104. PBSINGLE_LIST_HEAD Head
  105. )
  106. {
  107. PBSINGLE_LIST_ENTRY Entry = Head->Head;
  108. if( Entry != NULL )
  109. {
  110. Head->Head = Entry->Next;
  111. if( Head->Tail == Entry )
  112. {
  113. Head->Tail = NULL;
  114. }
  115. Head->Length--;
  116. }
  117. return Entry;
  118. }
  119. __forceinline PBSINGLE_LIST_ENTRY
  120. BrdgInterlockedRemoveHeadSingleList(
  121. PBSINGLE_LIST_HEAD Head,
  122. PNDIS_SPIN_LOCK Lock
  123. )
  124. {
  125. PBSINGLE_LIST_ENTRY Entry;
  126. NdisAcquireSpinLock( Lock );
  127. Entry = BrdgRemoveHeadSingleList( Head );
  128. NdisReleaseSpinLock( Lock );
  129. return Entry;
  130. }