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.

144 lines
2.7 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. linklist.h
  5. Abstract:
  6. This file contains the generic doubly-linked list manipulation package
  7. stolen from NT & made digestible by Win95
  8. Author:
  9. Vlad Sadovsky (VladS) 11-Feb-1997
  10. Revision History:
  11. VladS 02-11-97 Extracted from NT SDK headers to use on Win9x
  12. --*/
  13. #ifndef _LINKLIST_H_
  14. #define _LINKLIST_H_
  15. //
  16. // Calculate the address of the base of the structure given its type, and an
  17. // address of a field within the structure.
  18. //
  19. #ifndef CONTAINING_RECORD
  20. #define CONTAINING_RECORD(address, type, field) ((type *)( \
  21. (PCHAR)(address) - \
  22. (PCHAR)(&((type *)0)->field)))
  23. #endif // CONTAINING_RECORD
  24. //
  25. // Doubly-linked list manipulation routines. Implemented as macros
  26. // but logically these are procedures.
  27. //
  28. //
  29. // VOID
  30. // InitializeListHead(
  31. // PLIST_ENTRY ListHead
  32. // );
  33. //
  34. #define InitializeListHead(ListHead) (\
  35. (ListHead)->Flink = (ListHead)->Blink = (ListHead))
  36. //
  37. // BOOLEAN
  38. // IsListEmpty(
  39. // PLIST_ENTRY ListHead
  40. // );
  41. //
  42. #define IsListEmpty(ListHead) \
  43. ((ListHead)->Flink == (ListHead))
  44. //
  45. // PLIST_ENTRY
  46. // RemoveHeadList(
  47. // PLIST_ENTRY ListHead
  48. // );
  49. //
  50. #define RemoveHeadList(ListHead) \
  51. (ListHead)->Flink;\
  52. {RemoveEntryList((ListHead)->Flink)}
  53. //
  54. // PLIST_ENTRY
  55. // RemoveTailList(
  56. // PLIST_ENTRY ListHead
  57. // );
  58. //
  59. #define RemoveTailList(ListHead) \
  60. (ListHead)->Blink;\
  61. {RemoveEntryList((ListHead)->Blink)}
  62. //
  63. // VOID
  64. // RemoveEntryList(
  65. // PLIST_ENTRY Entry
  66. // );
  67. //
  68. #define RemoveEntryList(Entry) {\
  69. PLIST_ENTRY _EX_Blink;\
  70. PLIST_ENTRY _EX_Flink;\
  71. _EX_Flink = (Entry)->Flink;\
  72. _EX_Blink = (Entry)->Blink;\
  73. _EX_Blink->Flink = _EX_Flink;\
  74. _EX_Flink->Blink = _EX_Blink;\
  75. }
  76. //
  77. // VOID
  78. // InsertTailList(
  79. // PLIST_ENTRY ListHead,
  80. // PLIST_ENTRY Entry
  81. // );
  82. //
  83. #define InsertTailList(ListHead,Entry) {\
  84. PLIST_ENTRY _EX_Blink;\
  85. PLIST_ENTRY _EX_ListHead;\
  86. _EX_ListHead = (ListHead);\
  87. _EX_Blink = _EX_ListHead->Blink;\
  88. (Entry)->Flink = _EX_ListHead;\
  89. (Entry)->Blink = _EX_Blink;\
  90. _EX_Blink->Flink = (Entry);\
  91. _EX_ListHead->Blink = (Entry);\
  92. }
  93. //
  94. // VOID
  95. // InsertHeadList(
  96. // PLIST_ENTRY ListHead,
  97. // PLIST_ENTRY Entry
  98. // );
  99. //
  100. #define InsertHeadList(ListHead,Entry) {\
  101. PLIST_ENTRY _EX_Flink;\
  102. PLIST_ENTRY _EX_ListHead;\
  103. _EX_ListHead = (ListHead);\
  104. _EX_Flink = _EX_ListHead->Flink;\
  105. (Entry)->Flink = _EX_Flink;\
  106. (Entry)->Blink = _EX_ListHead;\
  107. _EX_Flink->Blink = (Entry);\
  108. _EX_ListHead->Flink = (Entry);\
  109. }
  110. #endif // _LINKLIST_H_