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.

282 lines
6.9 KiB

  1. /*++
  2. Copyright (c) Microsoft 1998, All Rights Reserved
  3. Module Name:
  4. list.h
  5. Abstract:
  6. This module contains the code for manipulating list structures.
  7. Environment:
  8. User mode
  9. Revision History:
  10. Nov-97 : Created
  11. --*/
  12. #ifndef __LIST_H__
  13. #define __LIST_H__
  14. #include <windows.h>
  15. typedef LIST_ENTRY LIST_NODE_HDR, *PLIST_NODE_HDR;
  16. typedef LIST_NODE_HDR LIST, *PLIST;
  17. typedef VOID PLIST_CALLBACK(PLIST_NODE_HDR);
  18. VOID
  19. InitializeList(
  20. IN PLIST NewList
  21. );
  22. VOID
  23. InsertHead(
  24. IN PLIST List,
  25. IN PLIST_NODE_HDR ListNode
  26. );
  27. VOID
  28. InsertTail(
  29. IN PLIST List,
  30. IN PLIST_NODE_HDR ListNode
  31. );
  32. VOID
  33. RemoveNode(
  34. IN PLIST_NODE_HDR ListNode
  35. );
  36. PLIST_NODE_HDR
  37. RemoveHead(
  38. IN PLIST List
  39. );
  40. PLIST_NODE_HDR
  41. RemoveTail(
  42. IN PLIST List
  43. );
  44. BOOL
  45. IsListEmpty(
  46. IN PLIST List
  47. );
  48. PLIST_NODE_HDR
  49. GetListHead(
  50. IN PLIST List
  51. );
  52. PLIST_NODE_HDR
  53. GetListTail(
  54. IN PLIST List
  55. );
  56. PLIST_NODE_HDR
  57. GetNextEntry(
  58. IN PLIST_NODE_HDR ListNode
  59. );
  60. PLIST_NODE_HDR
  61. GetPrevEntry(
  62. IN PLIST_NODE_HDR ListNode
  63. );
  64. VOID
  65. DestroyListNoCallback(
  66. IN PLIST List
  67. );
  68. VOID
  69. DestroyListWithCallback(
  70. IN PLIST List,
  71. IN PLIST_CALLBACK Callback
  72. );
  73. /*****************************************************************************
  74. /* Macro definitions of list functions
  75. /*****************************************************************************/
  76. /*
  77. // VOID
  78. // InitializeList(
  79. // IN PLIST NewList
  80. // );
  81. */
  82. #define InitializeList(nl) \
  83. { ((PLIST)(nl)) -> Flink = ((PLIST)(nl)) -> Blink = nl; }
  84. /*
  85. // VOID
  86. // InsertHead(
  87. / IN PLIST List,
  88. // IN PLIST_NODE_HDR ListNode
  89. // );
  90. */
  91. #define InsertHead(List, Node) { \
  92. PLIST_NODE_HDR _EX_Flink; \
  93. PLIST_NODE_HDR _EX_List; \
  94. \
  95. _EX_List = ((PLIST_NODE_HDR) (List)); \
  96. _EX_Flink = _EX_List -> Flink; \
  97. ((PLIST_NODE_HDR) (Node))->Blink = _EX_List; \
  98. ((PLIST_NODE_HDR) (Node))->Flink = _EX_Flink; \
  99. _EX_Flink->Blink = (((PLIST_NODE_HDR) (Node))); \
  100. _EX_List->Flink = ((PLIST_NODE_HDR) (Node)); \
  101. }
  102. /*
  103. // VOID
  104. // InsertTail(
  105. // IN PLIST List,
  106. // IN PLIST_NODE_HDR ListNode
  107. // );
  108. */
  109. #define InsertTail(List, Node) { \
  110. PLIST_NODE_HDR _EX_Blink; \
  111. PLIST_NODE_HDR _EX_List; \
  112. \
  113. _EX_List = ((PLIST_NODE_HDR) (List)); \
  114. _EX_Blink = _EX_List->Blink; \
  115. ((PLIST_NODE_HDR) (Node))->Flink = _EX_List; \
  116. ((PLIST_NODE_HDR) (Node))->Blink = _EX_Blink; \
  117. _EX_Blink->Flink = (((PLIST_NODE_HDR) (Node))); \
  118. _EX_List->Blink = ((PLIST_NODE_HDR) (Node)); \
  119. }
  120. /*
  121. // VOID
  122. // RemoveNode(
  123. // IN PLIST_NODE_HDR ListNode
  124. // );
  125. */
  126. #define RemoveNode(node) { \
  127. PLIST_NODE_HDR _EX_Blink; \
  128. PLIST_NODE_HDR _EX_Flink; \
  129. \
  130. _EX_Flink = ((PLIST_NODE_HDR) (node))->Flink; \
  131. _EX_Blink = ((PLIST_NODE_HDR) (node))->Blink; \
  132. _EX_Blink->Flink = _EX_Flink; \
  133. _EX_Flink->Blink = _EX_Blink; \
  134. }
  135. /*
  136. // PLIST_NODE_HDR
  137. // RemoveHead(
  138. // IN PLIST List
  139. // );
  140. */
  141. #define RemoveHead(List) \
  142. GetListHead((List)); \
  143. RemoveNode(((PLIST_NODE_HDR) (List))->Flink)
  144. /*
  145. // PLIST_NODE_HDR
  146. // RemoveTail(
  147. // IN PLIST List
  148. // );
  149. */
  150. #define RemoveTail(List) \
  151. GetListTail((List)); \
  152. RemoveNode(((PLIST_NODE_HDR) (List))->Blink)
  153. /*
  154. // BOOL
  155. // IsListEmpty(
  156. // IN PLIST List
  157. // );
  158. */
  159. #define IsListEmpty(List) \
  160. (((PLIST_NODE_HDR) (List))->Flink == ((PLIST_NODE_HDR) (List)))
  161. /*
  162. // PLIST_NODE_HDR
  163. // GetListHead(
  164. // IN PLIST List
  165. // );
  166. */
  167. #define GetListHead(List) \
  168. (((PLIST_NODE_HDR) (List))->Flink)
  169. /*
  170. // PLIST_NODE_HDR
  171. // GetListTail(
  172. // IN PLIST List
  173. // );
  174. */
  175. #define GetListTail(List) \
  176. (((PLIST_NODE_HDR) (List))->Blink)
  177. /*
  178. // PLIST_NODE_HDR
  179. // GetNextEntry(
  180. // IN PLIST_NODE_HDR ListNode
  181. // );
  182. */
  183. #define GetNextEntry(ListNode) \
  184. (((PLIST_NODE_HDR) (ListNode)) -> Flink);
  185. /*
  186. // PLIST_NODE_HDR
  187. // GetPrevEntry(
  188. // IN PLIST_NODE_HDR ListNode
  189. // );
  190. */
  191. #define GetPrevEntry(ListNode) \
  192. (((PLIST_NODE_HDR) (ListNode)) -> Blink);
  193. /*
  194. // VOID
  195. // DestroyListNoCallback(
  196. // IN PLIST List,
  197. // IN PLIST_CALLBACK Callback
  198. // );
  199. */
  200. #define DestroyListNoCallback(list) \
  201. PLIST_NODE_HDR currNode; \
  202. \
  203. while (!IsListEmpty((list))) { \
  204. currNode = RemoveHead((list)); \
  205. } \
  206. }
  207. /*
  208. // VOID
  209. // DestroyListWithCallback(
  210. // IN PLIST List,
  211. // IN PLIST_CALLBACK Callback
  212. // );
  213. */
  214. #define DestroyListWithCallback(list, cb) { \
  215. PLIST_NODE_HDR currNode; \
  216. \
  217. while (!IsListEmpty((list))) { \
  218. currNode = RemoveHead((list)); \
  219. (cb)(currNode); \
  220. } \
  221. }
  222. #endif