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.

257 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. serialst.h
  5. Abstract:
  6. Header file for serialst.c
  7. Author:
  8. Richard L Firth (rfirth) 16-Feb-1995
  9. Revision History:
  10. 16-Feb-1995 rfirth
  11. Created
  12. --*/
  13. #if defined(__cplusplus)
  14. extern "C" {
  15. #endif
  16. //
  17. // types
  18. //
  19. typedef struct {
  20. #if INET_DEBUG
  21. //
  22. // Signature - must have this to ensure its really a serialized list. Also
  23. // makes finding start of this structure relatively easy when debugging
  24. //
  25. DWORD Signature;
  26. //
  27. // ResourceInfo - basically who owns this 'object', combined with yet more
  28. // debugging information
  29. //
  30. RESOURCE_INFO ResourceInfo;
  31. //
  32. // LockCount - number of re-entrant locks held
  33. //
  34. LONG LockCount;
  35. #endif // INET_DEBUG
  36. LIST_ENTRY List;
  37. //
  38. // ElementCount - number of items on list. Useful for consistency checking
  39. //
  40. LONG ElementCount;
  41. //
  42. // Lock - we must acquire this to update the list. Put this structure at
  43. // the end to make life easier when debugging
  44. //
  45. CRITICAL_SECTION Lock;
  46. } SERIALIZED_LIST, *LPSERIALIZED_LIST;
  47. //
  48. // SERIALIZED_LIST_ENTRY - we can use this in place of LIST_ENTRY so that in
  49. // the debug version we can check for cycles, etc.
  50. //
  51. typedef struct {
  52. LIST_ENTRY List;
  53. #if INET_DEBUG
  54. DWORD Signature;
  55. DWORD Flags;
  56. #endif
  57. } SERIALIZED_LIST_ENTRY, *LPSERIALIZED_LIST_ENTRY;
  58. //
  59. // prototypes
  60. //
  61. #if INET_DEBUG
  62. VOID
  63. InitializeSerializedList(
  64. IN LPSERIALIZED_LIST SerializedList
  65. );
  66. VOID
  67. TerminateSerializedList(
  68. IN LPSERIALIZED_LIST SerializedList
  69. );
  70. VOID
  71. LockSerializedList(
  72. IN LPSERIALIZED_LIST SerializedList
  73. );
  74. VOID
  75. UnlockSerializedList(
  76. IN LPSERIALIZED_LIST SerializedList
  77. );
  78. VOID
  79. InsertAtHeadOfSerializedList(
  80. IN LPSERIALIZED_LIST SerializedList,
  81. IN PLIST_ENTRY Entry
  82. );
  83. VOID
  84. InsertAtTailOfSerializedList(
  85. IN LPSERIALIZED_LIST SerializedList,
  86. IN PLIST_ENTRY Entry
  87. );
  88. VOID
  89. RemoveFromSerializedList(
  90. IN LPSERIALIZED_LIST SerializedList,
  91. IN PLIST_ENTRY Entry
  92. );
  93. BOOL
  94. IsSerializedListEmpty(
  95. IN LPSERIALIZED_LIST SerializedList
  96. );
  97. PLIST_ENTRY
  98. HeadOfSerializedList(
  99. IN LPSERIALIZED_LIST SerializedList
  100. );
  101. PLIST_ENTRY
  102. TailOfSerializedList(
  103. IN LPSERIALIZED_LIST SerializedList
  104. );
  105. BOOL
  106. CheckEntryOnSerializedList(
  107. IN LPSERIALIZED_LIST SerializedList,
  108. IN PLIST_ENTRY Entry,
  109. IN BOOL ExpectedResult
  110. );
  111. #define IsLockHeld(list) \
  112. (((list)->ResourceInfo.Tid == GetCurrentThreadId()) \
  113. ? ((list)->LockCount != 0) \
  114. : FALSE)
  115. #else // INET_DEBUG
  116. #define InitializeSerializedList(list) \
  117. { \
  118. InitializeListHead(&(list)->List); \
  119. InitializeCriticalSection(&(list)->Lock); \
  120. (list)->ElementCount = 0; \
  121. }
  122. #define TerminateSerializedList(list) \
  123. DeleteCriticalSection(&(list)->Lock)
  124. #define LockSerializedList(list) \
  125. EnterCriticalSection(&(list)->Lock)
  126. #define UnlockSerializedList(list) \
  127. LeaveCriticalSection(&(list)->Lock)
  128. #define InsertAtHeadOfSerializedList(list, entry) \
  129. { \
  130. LockSerializedList(list); \
  131. InsertHeadList(&(list)->List, entry); \
  132. ++(list)->ElementCount; \
  133. UnlockSerializedList(list); \
  134. }
  135. #define InsertAtTailOfSerializedList(list, entry) \
  136. { \
  137. LockSerializedList(list); \
  138. InsertTailList(&(list)->List, entry); \
  139. ++(list)->ElementCount; \
  140. UnlockSerializedList(list); \
  141. }
  142. #define RemoveFromSerializedList(list, entry) \
  143. { \
  144. LockSerializedList(list); \
  145. RemoveEntryList(entry); \
  146. --(list)->ElementCount; \
  147. UnlockSerializedList(list); \
  148. }
  149. #define IsSerializedListEmpty(list) \
  150. IsListEmpty(&(list)->List)
  151. #define HeadOfSerializedList(list) \
  152. (list)->List.Flink
  153. #define TailOfSerializedList(list) \
  154. (list)->List.Blink
  155. #define IsLockHeld(list) \
  156. /* NOTHING */
  157. #endif // INET_DEBUG
  158. //
  159. // functions that are always functions
  160. //
  161. LPVOID
  162. SlDequeueHead(
  163. IN LPSERIALIZED_LIST SerializedList
  164. );
  165. LPVOID
  166. SlDequeueTail(
  167. IN LPSERIALIZED_LIST SerializedList
  168. );
  169. BOOL
  170. IsOnSerializedList(
  171. IN LPSERIALIZED_LIST SerializedList,
  172. IN PLIST_ENTRY Entry
  173. );
  174. //
  175. // functions that are always macros
  176. //
  177. #define NextInSerializedList(list, entry)\
  178. (( ((entry)->List).Flink == &((list)->List))? NULL : ((entry)->List).Flink)
  179. #define ElementsOnSerializedList(list) \
  180. (list)->ElementCount
  181. #define SlSelf(SerializedList) \
  182. &(SerializedList)->List.Flink
  183. #if defined(__cplusplus)
  184. }
  185. #endif