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.

238 lines
4.9 KiB

  1. /*++ BUILD Version: 0000 Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. ntslist.h
  5. Abstract:
  6. This file exposes the internal s-list functionality for projects that need
  7. to run on down-level platforms.
  8. Revision History:
  9. --*/
  10. #ifndef _NTSLIST_
  11. #define _NTSLIST_
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #if !defined(NTSLIST_ASSERT)
  16. #define NTSLIST_ASSERT(x) ASSERT(x)
  17. #endif // !defined(NTSLIST_ASSERT)
  18. #ifdef _NTSLIST_DIRECT_
  19. #define INLINE_SLIST __inline
  20. #define RtlInitializeSListHead _RtlInitializeSListHead
  21. #define _RtlFirstEntrySList FirstEntrySList
  22. PSLIST_ENTRY
  23. FirstEntrySList (
  24. const SLIST_HEADER *ListHead
  25. );
  26. #define RtlInterlockedPopEntrySList _RtlInterlockedPopEntrySList
  27. #define RtlInterlockedPushEntrySList _RtlInterlockedPushEntrySList
  28. #define RtlInterlockedFlushSList _RtlInterlockedFlushSList
  29. #define _RtlQueryDepthSList RtlpQueryDepthSList
  30. #else
  31. #define INLINE_SLIST
  32. #endif // _NTSLIST_DIRECT_
  33. //
  34. // Define forward referenced function prototypes.
  35. //
  36. VOID
  37. RtlpInitializeSListHead (
  38. IN PSLIST_HEADER ListHead
  39. );
  40. PSLIST_ENTRY
  41. FASTCALL
  42. RtlpInterlockedPopEntrySList (
  43. IN PSLIST_HEADER ListHead
  44. );
  45. PSLIST_ENTRY
  46. FASTCALL
  47. RtlpInterlockedPushEntrySList (
  48. IN PSLIST_HEADER ListHead,
  49. IN PSLIST_ENTRY ListEntry
  50. );
  51. PSLIST_ENTRY
  52. FASTCALL
  53. RtlpInterlockedFlushSList (
  54. IN PSLIST_HEADER ListHead
  55. );
  56. WORD
  57. RtlpQueryDepthSList (
  58. IN PSLIST_HEADER SListHead
  59. );
  60. INLINE_SLIST
  61. VOID
  62. RtlInitializeSListHead (
  63. IN PSLIST_HEADER SListHead
  64. )
  65. /*++
  66. Routine Description:
  67. This function initializes a sequenced singly linked listhead.
  68. Arguments:
  69. SListHead - Supplies a pointer to a sequenced singly linked listhead.
  70. Return Value:
  71. None.
  72. --*/
  73. {
  74. RtlpInitializeSListHead(SListHead);
  75. return;
  76. }
  77. INLINE_SLIST
  78. PSLIST_ENTRY
  79. RtlInterlockedPopEntrySList (
  80. IN PSLIST_HEADER ListHead
  81. )
  82. /*++
  83. Routine Description:
  84. This function removes an entry from the front of a sequenced singly
  85. linked list so that access to the list is synchronized in a MP system.
  86. If there are no entries in the list, then a value of NULL is returned.
  87. Otherwise, the address of the entry that is removed is returned as the
  88. function value.
  89. Arguments:
  90. ListHead - Supplies a pointer to the sequenced listhead from which
  91. an entry is to be removed.
  92. Return Value:
  93. The address of the entry removed from the list, or NULL if the list is
  94. empty.
  95. --*/
  96. {
  97. DWORD Count;
  98. //
  99. // It is posible during the pop of the sequenced list that an access
  100. // violation can occur if a stale pointer is dereferenced. This is an
  101. // acceptable result and the operation can be retried.
  102. //
  103. // N.B. The count is used to distinguish the case where the list head
  104. // itself causes the access violation and therefore no progress
  105. // can be made by repeating the operation.
  106. //
  107. Count = 0;
  108. do {
  109. __try {
  110. return RtlpInterlockedPopEntrySList(ListHead);
  111. } __except (Count++ < 20 ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) {
  112. continue;
  113. }
  114. } while (TRUE);
  115. }
  116. INLINE_SLIST
  117. PSLIST_ENTRY
  118. RtlInterlockedPushEntrySList (
  119. IN PSLIST_HEADER ListHead,
  120. IN PSLIST_ENTRY ListEntry
  121. )
  122. /*++
  123. Routine Description:
  124. This function inserts an entry at the head of a sequenced singly linked
  125. list so that access to the list is synchronized in an MP system.
  126. Arguments:
  127. ListHead - Supplies a pointer to the sequenced listhead into which
  128. an entry is to be inserted.
  129. ListEntry - Supplies a pointer to the entry to be inserted at the
  130. head of the list.
  131. Return Value:
  132. The address of the previous firt entry in the list. NULL implies list
  133. went from empty to not empty.
  134. --*/
  135. {
  136. NTSLIST_ASSERT(((ULONG_PTR)ListEntry & 0x7) == 0);
  137. return RtlpInterlockedPushEntrySList(ListHead, ListEntry);
  138. }
  139. INLINE_SLIST
  140. PSLIST_ENTRY
  141. RtlInterlockedFlushSList (
  142. IN PSLIST_HEADER ListHead
  143. )
  144. /*++
  145. Routine Description:
  146. This function flushes the entire list of entries on a sequenced singly
  147. linked list so that access to the list is synchronized in a MP system.
  148. If there are no entries in the list, then a value of NULL is returned.
  149. Otherwise, the address of the firt entry on the list is returned as the
  150. function value.
  151. Arguments:
  152. ListHead - Supplies a pointer to the sequenced listhead from which
  153. an entry is to be removed.
  154. Return Value:
  155. The address of the entry removed from the list, or NULL if the list is
  156. empty.
  157. --*/
  158. {
  159. return RtlpInterlockedFlushSList(ListHead);
  160. }
  161. #ifdef __cplusplus
  162. }
  163. #endif
  164. #endif /* _NTSLIST_ */