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.

177 lines
6.1 KiB

  1. /* (C) 1997-1998 Microsoft Corp.
  2. *
  3. * file: ch.h
  4. *
  5. * description: Main CH header.
  6. */
  7. #ifndef _H_CH
  8. #define _H_CH
  9. /*
  10. * Defines
  11. */
  12. #define CH_EVT_ENTRYREMOVED 0
  13. #define CH_EVT_QUERYREMOVEENTRY 1
  14. #define CH_KEY_UNCACHABLE ((unsigned)-1)
  15. // Used in debug build to determine display frequency of cache search stats.
  16. #define CH_STAT_DISPLAY_FREQ 64
  17. // Max number of caches that can be created at once.
  18. #define CH_MAX_NUM_CACHES 20
  19. /*
  20. * Typedefs
  21. */
  22. typedef void *CHCACHEHANDLE;
  23. typedef CHCACHEHANDLE *PCHCACHEHANDLE;
  24. typedef BOOLEAN (__fastcall *CHCACHECALLBACK)(
  25. CHCACHEHANDLE hCache,
  26. unsigned Event,
  27. unsigned iCacheEntry,
  28. void *UserDefined);
  29. // Node in a CH cache.
  30. typedef struct
  31. {
  32. LIST_ENTRY HashList;
  33. UINT32 Key1, Key2; // 64-bit hash value broken in two.
  34. LIST_ENTRY MRUList;
  35. void *UserDefined; // Associated data, used by SBC for fast-path.
  36. CHCACHEHANDLE hCache; // Used by SBC fast-path to get to the cache.
  37. } CHNODE, *PCHNODE;
  38. // Primary data structure containing the cache info and the hash bucket array.
  39. // CHNODEs are allocated at end of bucket array.
  40. typedef struct
  41. {
  42. unsigned bNotifyRemoveLRU : 1;
  43. unsigned bQueryRemoveLRU : 1;
  44. UINT32 HashKeyMask;
  45. CHCACHECALLBACK pfnCacheCallback;
  46. void *pContext;
  47. CHNODE *NodeArray;
  48. unsigned NumEntries;
  49. LIST_ENTRY MRUList;
  50. LIST_ENTRY FreeList;
  51. #ifdef DC_DEBUG
  52. // Statistics gathered in debug builds.
  53. unsigned MaxEntries;
  54. unsigned NumSearches;
  55. unsigned DeepestSearch;
  56. unsigned NumHits;
  57. unsigned TotalDepthOnHit;
  58. unsigned SearchHitDepthHistogram[8];
  59. unsigned TotalDepthOnMiss;
  60. unsigned SearchMissDepthHistogram[8];
  61. #endif
  62. LIST_ENTRY HashBuckets[1];
  63. } CHCACHEDATA, *PCHCACHEDATA;
  64. /*
  65. * Inlines.
  66. */
  67. /****************************************************************************/
  68. // Given a pointer to a CHNODE, returns the containing hCache.
  69. /****************************************************************************/
  70. //__inline CHCACHEHANDLE RDPCALL CH_GetCacheHandleFromNode(CHNODE *pNode)
  71. #define CH_GetCacheHandleFromNode(_pNode) ((_pNode)->hCache)
  72. /****************************************************************************/
  73. // Given a cache handle, returns the stored pContext information passed
  74. // into CH_CreateCache().
  75. /****************************************************************************/
  76. //__inline void * RDPCALL CH_GetCacheContextFromHandle(CHCACHEHANDLE hCache)
  77. #define CH_GetCacheContext(_hCache) \
  78. (((PCHCACHEDATA)(_hCache))->pContext)
  79. /****************************************************************************/
  80. // Given a cache handle, sets the stored pContext information passed into
  81. // CH_CreateCache().
  82. /****************************************************************************/
  83. //__inline void * RDPCALL CH_GetCacheContextFromHandle(CHCACHEHANDLE hCache)
  84. #define CH_SetCacheContext(_hCache, _pContext) \
  85. (((PCHCACHEDATA)(_hCache))->pContext) = (_pContext)
  86. /****************************************************************************/
  87. // Given a pointer to a CHNODE, returns the node's index.
  88. /****************************************************************************/
  89. //__inline unsigned RDPCALL CH_GetCacheIndexFromNode(CHNODE *pNode)
  90. #define CH_GetCacheIndexFromNode(_pNode) \
  91. ((unsigned)((_pNode) - ((PCHCACHEDATA)((_pNode)->hCache))->NodeArray))
  92. /****************************************************************************/
  93. // Given a cache handle and an index, returns a pointer to the node.
  94. /****************************************************************************/
  95. //__inline PCHNODE RDPCALL CH_GetNodeFromCacheIndex(
  96. // CHCACHEHANDLE hCache,
  97. // unsigned CacheIndex)
  98. #define CH_GetNodeFromCacheIndex(_hCache, _CacheIndex) \
  99. (&(((PCHCACHEDATA)(_hCache))->NodeArray[_CacheIndex]))
  100. /****************************************************************************/
  101. // Given a cache handle and an index, changes the node's UserDefined value.
  102. /****************************************************************************/
  103. //__inline void RDPCALL CH_SetUserDefined(
  104. // CHCACHEHANDLE hCache,
  105. // unsigned CacheIndex,
  106. // void *UserDefined)
  107. #define CH_SetUserDefined(_hCache, _CacheIndex, _UserDefined) \
  108. (((PCHCACHEDATA)(_hCache))->NodeArray[_CacheIndex].UserDefined = \
  109. _UserDefined)
  110. /****************************************************************************/
  111. // Given a cache handle and an index, returns the node's UserDefined value.
  112. /****************************************************************************/
  113. //__inline void * RDPCALL CH_GetUserDefined(
  114. // CHCACHEHANDLE hCache,
  115. // unsigned CacheIndex)
  116. #define CH_GetUserDefined(_hCache, _CacheIndex) \
  117. (((PCHCACHEDATA)(_hCache))->NodeArray[_CacheIndex].UserDefined)
  118. /****************************************************************************/
  119. // Given a node, changes its UserDefined value.
  120. /****************************************************************************/
  121. //__inline void RDPCALL CH_SetNodeUserDefined(CHNODE *pNode, void *UserDefined)
  122. #define CH_SetNodeUserDefined(_pNode, _UserDefined) \
  123. ((_pNode)->UserDefined = (_UserDefined))
  124. /****************************************************************************/
  125. // Given a node, returns its UserDefined value.
  126. /****************************************************************************/
  127. //__inline void * RDPCALL CH_GetNodeUserDefined(CHNODE *pNode)
  128. #define CH_GetNodeUserDefined(_pNode) ((_pNode)->UserDefined)
  129. /****************************************************************************/
  130. // Returns the number of cached entries in a cache.
  131. /****************************************************************************/
  132. //__inline unsigned RDPCALL CH_GetNumEntries(CHCACHEHANDLE hCache)
  133. #define CH_GetNumEntries(_hCache) (((PCHCACHEDATA)(_hCache))->NumEntries)
  134. #endif // !defined(_H_CH)