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.

269 lines
6.1 KiB

  1. /*++
  2. Copyright (c) 1998-2002 Microsoft Corporation
  3. Module Name:
  4. hashp.h
  5. Abstract:
  6. The private definition of response cache hash table.
  7. Author:
  8. Alex Chen (alexch) 28-Mar-2001
  9. Revision History:
  10. --*/
  11. #ifndef _HASHP_H_
  12. #define _HASHP_H_
  13. #include "hash.h"
  14. // Global Variables
  15. extern ULONG g_UlHashTableBits;
  16. extern ULONG g_UlHashTableSize;
  17. extern ULONG g_UlHashTableMask;
  18. extern ULONG g_UlHashIndexShift;
  19. extern ULONG g_UlNumOfHashUriKeys;
  20. // If we're using PagedPool for the hashtable, we must not access the
  21. // hashtable at dispatch level.
  22. #define HASH_PAGED_CODE(pHashTable) \
  23. do { \
  24. if ((pHashTable)->PoolType == PagedPool) { \
  25. PAGED_CODE(); \
  26. } \
  27. } while (0)
  28. // Set some parameters to small values to ensure the single list code
  29. // gets exercised
  30. #undef HASH_TEST
  31. // Turn HASH_FULL_ASSERTS on if you make any changes to hashtable internal
  32. // data structures to get rigorous-but-time-consuming assertions
  33. #undef HASH_FULL_ASSERTS
  34. //
  35. // Hash Table Bucket Stored UriKey definitions
  36. //
  37. #define INVALID_SLOT_INDEX ((LONG) (-1))
  38. typedef struct _HASH_URIKEY
  39. {
  40. PUL_URI_CACHE_ENTRY pUriCacheEntry;
  41. ULONG Hash; // Hash signature
  42. } HASHURIKEY, *PHASHURIKEY;
  43. //
  44. // Hash Table Bucket definitions
  45. //
  46. typedef struct _HASH_BUCKET
  47. {
  48. RWSPINLOCK RWSpinLock;
  49. PUL_URI_CACHE_ENTRY pUriCacheEntry;
  50. ULONG_PTR Entries; // force alignment
  51. // followed immediately by HASHURIKEY HashUriKey[g_UlNumOfHashUriKeys];
  52. } HASHBUCKET, *PHASHBUCKET;
  53. /***************************************************************************++
  54. Routine Description:
  55. Get the indexed bucket
  56. Return Value:
  57. --***************************************************************************/
  58. __inline
  59. PHASHBUCKET
  60. UlpHashTableIndexedBucket(
  61. IN PHASHTABLE pHashTable,
  62. IN ULONG Index
  63. )
  64. {
  65. PHASHBUCKET pBucket;
  66. ASSERT(Index < g_UlHashTableSize);
  67. ASSERT(NULL != pHashTable->pBuckets);
  68. pBucket = (PHASHBUCKET) (((PBYTE) pHashTable->pBuckets)
  69. + (Index << g_UlHashIndexShift));
  70. ASSERT((PBYTE) pBucket
  71. < (PBYTE) pHashTable->pBuckets + pHashTable->NumberOfBytes);
  72. return pBucket;
  73. } // UlpHashTableIndexedBucket
  74. /***************************************************************************++
  75. Routine Description:
  76. Retrieve the bucket associated with a URI_KEY hash
  77. Return Value:
  78. --***************************************************************************/
  79. __inline
  80. PHASHBUCKET
  81. UlpHashTableBucketFromUriKeyHash(
  82. IN PHASHTABLE pHashTable,
  83. IN ULONG UriKeyHash
  84. )
  85. {
  86. ASSERT(HASH_INVALID_SIGNATURE != UriKeyHash);
  87. return UlpHashTableIndexedBucket(
  88. pHashTable,
  89. UriKeyHash & g_UlHashTableMask
  90. );
  91. } // UlpHashTableBucketFromUriKeyHash
  92. /***************************************************************************++
  93. Routine Description:
  94. Get the address of the inline array of HASHURIKEYs at the end of
  95. the HASHBUCKET
  96. Return Value:
  97. --***************************************************************************/
  98. __inline
  99. PHASHURIKEY
  100. UlpHashTableUriKeyFromBucket(
  101. IN PHASHBUCKET pBucket
  102. )
  103. {
  104. return (PHASHURIKEY) ((PBYTE) pBucket + sizeof(HASHBUCKET));
  105. }
  106. /***************************************************************************++
  107. Routine Description:
  108. Compare two URI_KEYS that have identical hashes to see if the
  109. URIs also match (case-insensitively).
  110. (Hashes must have been computed with HashStringNoCaseW or
  111. HashCharNoCaseW.)
  112. Return Value:
  113. --***************************************************************************/
  114. __inline
  115. BOOLEAN
  116. UlpEqualUriKeys(
  117. IN PURI_KEY pUriKey1,
  118. IN PURI_KEY pUriKey2
  119. )
  120. {
  121. ASSERT(pUriKey1->Hash == pUriKey2->Hash);
  122. if (pUriKey1->Length == pUriKey2->Length
  123. && UlEqualUnicodeString(
  124. pUriKey1->pUri,
  125. pUriKey2->pUri,
  126. pUriKey1->Length,
  127. TRUE
  128. ))
  129. {
  130. return TRUE;
  131. }
  132. else
  133. {
  134. return FALSE;
  135. }
  136. }
  137. /***************************************************************************++
  138. Routine Description:
  139. Compare an EXTENDED_URI_KEY against a URI_KEY that have identical hashes
  140. to see if the URIs also match (case-insensitively).
  141. (Hashes must have been computed with HashStringNoCaseW or
  142. HashCharNoCaseW.)
  143. --***************************************************************************/
  144. __inline
  145. BOOLEAN
  146. UlpEqualUriKeysEx(
  147. IN PEX_URI_KEY pExtKey,
  148. IN PURI_KEY pUriKey
  149. )
  150. {
  151. ASSERT(pExtKey->Hash == pUriKey->Hash);
  152. if ((pExtKey->TokenLength + pExtKey->AbsPathLength)
  153. == pUriKey->Length
  154. && UlEqualUnicodeStringEx(
  155. pExtKey->pToken, // Routing token
  156. pExtKey->TokenLength, // Routing token length
  157. pExtKey->pAbsPath, // AbsPath
  158. pExtKey->AbsPathLength,// AbsPath length
  159. pUriKey->pUri, // Fully qualified url (in cache)
  160. TRUE // Case sensitive comparison
  161. ))
  162. {
  163. return TRUE;
  164. }
  165. else
  166. {
  167. return FALSE;
  168. }
  169. }
  170. VOID
  171. UlpGetHashTableSize(
  172. IN LONG HashTableBits
  173. );
  174. BOOLEAN
  175. UlpHashBucketIsCompact(
  176. IN const PHASHBUCKET pBucket);
  177. BOOLEAN
  178. UlpFilterFlushHashBucket(
  179. IN PHASHBUCKET pBucket,
  180. IN PUL_URI_FILTER pFilterRoutine,
  181. IN PVOID pContext,
  182. OUT PULONG pDeletedCount
  183. );
  184. VOID
  185. UlpClearHashBucket(
  186. IN PHASHBUCKET pBucket
  187. );
  188. #endif // _HASHP_H_