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.

335 lines
6.2 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. 05-Jul-1999 adriaanc
  13. nabbed for fusion
  14. --*/
  15. #if defined(__cplusplus)
  16. extern "C" {
  17. #endif
  18. // defines copied from wininet\common
  19. #define InitializeListHead(ListHead) (\
  20. (ListHead)->Flink = (ListHead)->Blink = (ListHead))
  21. #define IsListEmpty(ListHead) \
  22. ((ListHead)->Flink == (ListHead))
  23. #define RemoveHeadList(ListHead) \
  24. (ListHead)->Flink;\
  25. {RemoveEntryList((ListHead)->Flink)}
  26. #define RemoveTailList(ListHead) \
  27. (ListHead)->Blink;\
  28. {RemoveEntryList((ListHead)->Blink)}
  29. #define RemoveEntryList(Entry) {\
  30. PLIST_ENTRY _EX_Blink;\
  31. PLIST_ENTRY _EX_Flink;\
  32. _EX_Flink = (Entry)->Flink;\
  33. _EX_Blink = (Entry)->Blink;\
  34. _EX_Blink->Flink = _EX_Flink;\
  35. _EX_Flink->Blink = _EX_Blink;\
  36. }
  37. #define InsertTailList(ListHead,Entry) {\
  38. PLIST_ENTRY _EX_Blink;\
  39. PLIST_ENTRY _EX_ListHead;\
  40. _EX_ListHead = (ListHead);\
  41. _EX_Blink = _EX_ListHead->Blink;\
  42. (Entry)->Flink = _EX_ListHead;\
  43. (Entry)->Blink = _EX_Blink;\
  44. _EX_Blink->Flink = (Entry);\
  45. _EX_ListHead->Blink = (Entry);\
  46. }
  47. #define InsertHeadList(ListHead,Entry) {\
  48. PLIST_ENTRY _EX_Flink;\
  49. PLIST_ENTRY _EX_ListHead;\
  50. _EX_ListHead = (ListHead);\
  51. _EX_Flink = _EX_ListHead->Flink;\
  52. (Entry)->Flink = _EX_Flink;\
  53. (Entry)->Blink = _EX_ListHead;\
  54. _EX_Flink->Blink = (Entry);\
  55. _EX_ListHead->Flink = (Entry);\
  56. }
  57. #define PopEntryList(ListHead) \
  58. (ListHead)->Next;\
  59. {\
  60. PSINGLE_LIST_ENTRY FirstEntry;\
  61. FirstEntry = (ListHead)->Next;\
  62. if (FirstEntry != NULL) { \
  63. (ListHead)->Next = FirstEntry->Next;\
  64. } \
  65. }
  66. #define PushEntryList(ListHead,Entry) \
  67. (Entry)->Next = (ListHead)->Next; \
  68. (ListHead)->Next = (Entry)
  69. //
  70. // types
  71. //
  72. #if DBG
  73. typedef struct _RESOURCE_INFO
  74. {
  75. DWORD Tid;
  76. } RESOURCE_INFO, *LPRESOURCE_INFO;
  77. #endif // DBG
  78. typedef struct {
  79. #if DBG
  80. //
  81. // Signature - must have this to ensure its really a serialized list. Also
  82. // makes finding start of this structure relatively easy when debugging
  83. //
  84. DWORD Signature;
  85. //
  86. // ResourceInfo - basically who owns this 'object', combined with yet more
  87. // debugging information
  88. //
  89. RESOURCE_INFO ResourceInfo;
  90. //
  91. // LockCount - number of re-entrant locks held
  92. //
  93. LONG LockCount;
  94. #endif // DBG
  95. LIST_ENTRY List;
  96. //
  97. // ElementCount - number of items on list. Useful for consistency checking
  98. //
  99. LONG ElementCount;
  100. //
  101. // Lock - we must acquire this to update the list. Put this structure at
  102. // the end to make life easier when debugging
  103. //
  104. CRITICAL_SECTION Lock;
  105. } SERIALIZED_LIST, *LPSERIALIZED_LIST;
  106. //
  107. // SERIALIZED_LIST_ENTRY - we can use this in place of LIST_ENTRY so that in
  108. // the debug version we can check for cycles, etc.
  109. //
  110. typedef struct {
  111. LIST_ENTRY List;
  112. #if DBG
  113. DWORD Signature;
  114. DWORD Flags;
  115. #endif
  116. } SERIALIZED_LIST_ENTRY, *LPSERIALIZED_LIST_ENTRY;
  117. //
  118. // prototypes
  119. //
  120. #if DBG
  121. VOID
  122. InitializeSerializedList(
  123. IN LPSERIALIZED_LIST SerializedList
  124. );
  125. VOID
  126. TerminateSerializedList(
  127. IN LPSERIALIZED_LIST SerializedList
  128. );
  129. VOID
  130. LockSerializedList(
  131. IN LPSERIALIZED_LIST SerializedList
  132. );
  133. VOID
  134. UnlockSerializedList(
  135. IN LPSERIALIZED_LIST SerializedList
  136. );
  137. VOID
  138. InsertAtHeadOfSerializedList(
  139. IN LPSERIALIZED_LIST SerializedList,
  140. IN PLIST_ENTRY Entry
  141. );
  142. VOID
  143. InsertAtTailOfSerializedList(
  144. IN LPSERIALIZED_LIST SerializedList,
  145. IN PLIST_ENTRY Entry
  146. );
  147. VOID
  148. RemoveFromSerializedList(
  149. IN LPSERIALIZED_LIST SerializedList,
  150. IN PLIST_ENTRY Entry
  151. );
  152. BOOL
  153. IsSerializedListEmpty(
  154. IN LPSERIALIZED_LIST SerializedList
  155. );
  156. PLIST_ENTRY
  157. HeadOfSerializedList(
  158. IN LPSERIALIZED_LIST SerializedList
  159. );
  160. PLIST_ENTRY
  161. TailOfSerializedList(
  162. IN LPSERIALIZED_LIST SerializedList
  163. );
  164. BOOL
  165. CheckEntryOnSerializedList(
  166. IN LPSERIALIZED_LIST SerializedList,
  167. IN PLIST_ENTRY Entry,
  168. IN BOOL ExpectedResult
  169. );
  170. #define IsLockHeld(list) \
  171. (((list)->ResourceInfo.Tid == GetCurrentThreadId()) \
  172. ? ((list)->LockCount != 0) \
  173. : FALSE)
  174. #else // DBG
  175. #define InitializeSerializedList(list) \
  176. { \
  177. InitializeListHead(&(list)->List); \
  178. InitializeCriticalSection(&(list)->Lock); \
  179. (list)->ElementCount = 0; \
  180. }
  181. #define TerminateSerializedList(list) \
  182. DeleteCriticalSection(&(list)->Lock)
  183. #define LockSerializedList(list) \
  184. EnterCriticalSection(&(list)->Lock)
  185. #define UnlockSerializedList(list) \
  186. LeaveCriticalSection(&(list)->Lock)
  187. #define InsertAtHeadOfSerializedList(list, entry) \
  188. { \
  189. LockSerializedList(list); \
  190. InsertHeadList(&(list)->List, entry); \
  191. ++(list)->ElementCount; \
  192. UnlockSerializedList(list); \
  193. }
  194. #define InsertAtTailOfSerializedList(list, entry) \
  195. { \
  196. LockSerializedList(list); \
  197. InsertTailList(&(list)->List, entry); \
  198. ++(list)->ElementCount; \
  199. UnlockSerializedList(list); \
  200. }
  201. #define RemoveFromSerializedList(list, entry) \
  202. { \
  203. LockSerializedList(list); \
  204. RemoveEntryList(entry); \
  205. --(list)->ElementCount; \
  206. UnlockSerializedList(list); \
  207. }
  208. #define IsSerializedListEmpty(list) \
  209. IsListEmpty(&(list)->List)
  210. #define HeadOfSerializedList(list) \
  211. (list)->List.Flink
  212. #define TailOfSerializedList(list) \
  213. (list)->List.Blink
  214. #define IsLockHeld(list) \
  215. /* NOTHING */
  216. #endif // DBG
  217. //
  218. // functions that are always functions
  219. //
  220. LPVOID
  221. SlDequeueHead(
  222. IN LPSERIALIZED_LIST SerializedList
  223. );
  224. LPVOID
  225. SlDequeueTail(
  226. IN LPSERIALIZED_LIST SerializedList
  227. );
  228. BOOL
  229. IsOnSerializedList(
  230. IN LPSERIALIZED_LIST SerializedList,
  231. IN PLIST_ENTRY Entry
  232. );
  233. //
  234. // functions that are always macros
  235. //
  236. #define NextInSerializedList(list, entry)\
  237. (( ((entry)->List).Flink == &((list)->List))? NULL : ((entry)->List).Flink)
  238. #define ElementsOnSerializedList(list) \
  239. (list)->ElementCount
  240. #define SlSelf(SerializedList) \
  241. &(SerializedList)->List.Flink
  242. #if defined(__cplusplus)
  243. }
  244. #endif