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.

202 lines
5.4 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name :
  4. acache.hxx
  5. Abstract:
  6. This module defines the USER-level allocation cache for IIS.
  7. Author:
  8. Murali R. Krishnan ( MuraliK ) 12-Sept-1996
  9. Environment:
  10. Win32 - User Mode
  11. Project:
  12. Internet Server DLL
  13. Revision History:
  14. --*/
  15. # ifndef _ACACHE_HXX_
  16. # define _ACACHE_HXX_
  17. /************************************************************
  18. * Include Headers
  19. ************************************************************/
  20. # include <nt.h>
  21. # include <ntrtl.h>
  22. # include <nturtl.h>
  23. # include <windef.h>
  24. # include <winbase.h>
  25. # include <irtlmisc.h>
  26. /************************************************************
  27. * Type Definitions
  28. ************************************************************/
  29. //
  30. // Lookaside cleanup interval and configuration key
  31. //
  32. #define ACACHE_REG_PARAMS_REG_KEY "System\\CurrentControlSet\\Services\\InetInfo\\Parameters"
  33. #define ACACHE_REG_LOOKASIDE_CLEANUP_INTERVAL "LookasideCleanupInterval"
  34. #define ACACHE_REG_DEFAULT_CLEANUP_INTERVAL ((15)*(60))
  35. typedef struct _ALLOC_CACHE_CONFIGURATION {
  36. DWORD nConcurrency; // specifies the amount of parallelism Desired.
  37. LONG nThreshold; // max number of items to cache.
  38. DWORD cbSize; // size of the object allocated.
  39. // Other params to be added in the future.
  40. } ALLOC_CACHE_CONFIGURATION;
  41. typedef ALLOC_CACHE_CONFIGURATION * PAC_CONFIG;
  42. typedef struct _ALLOC_CACHE_STATISTICS {
  43. ALLOC_CACHE_CONFIGURATION acConfig;
  44. LONG nTotal;
  45. LONG nAllocCalls;
  46. LONG nFreeCalls;
  47. LONG nFreeEntries;
  48. // Other params to be added in the future.
  49. } ALLOC_CACHE_STATISTICS;
  50. typedef ALLOC_CACHE_STATISTICS * PAC_STATS;
  51. class IRTL_DLLEXP ALLOC_CACHE_HANDLER {
  52. public:
  53. ALLOC_CACHE_HANDLER(IN LPCSTR pszName,
  54. IN const ALLOC_CACHE_CONFIGURATION * pacConfig,
  55. BOOL fEnabledCleanupAsserts = TRUE);
  56. ~ALLOC_CACHE_HANDLER(VOID);
  57. BOOL IsValid( VOID) const { return ( m_fValid); }
  58. LPVOID Alloc( VOID );
  59. // LPVOID Alloc( IN DWORD cbSize);
  60. BOOL Free( LPVOID pvBlob);
  61. VOID CleanupLookaside( IN BOOL fForceCleanup );
  62. // Debug Helper routines.
  63. VOID Print( VOID);
  64. BOOL IpPrint( OUT CHAR * pchBuffer, IN OUT LPDWORD pcchSize);
  65. VOID QueryStats( IN ALLOC_CACHE_STATISTICS * pacStats );
  66. private:
  67. BOOL m_fValid;
  68. BOOL m_fCleanupAssertsEnabled;
  69. LONG m_nLastAllocCount;
  70. ALLOC_CACHE_CONFIGURATION m_acConfig;
  71. // Simple alloc-cache - uses a single lock and list :(
  72. CRITICAL_SECTION m_csLock;
  73. BOOL m_fcsInitialized;
  74. SINGLE_LIST_ENTRY m_lHead;
  75. LONG m_nTotal;
  76. LONG m_nAllocCalls;
  77. LONG m_nFreeCalls;
  78. LONG m_nFreeEntries;
  79. LONG m_nFillPattern;
  80. LPCSTR m_pszName;
  81. HANDLE m_hHeap;
  82. VOID Lock(VOID);
  83. VOID Unlock( VOID );
  84. public:
  85. LIST_ENTRY m_lItemsEntry; // for list of alloc-cache-handler objects
  86. public:
  87. static BOOL Initialize(VOID);
  88. static BOOL Cleanup(VOID);
  89. static VOID InsertNewItem( IN ALLOC_CACHE_HANDLER * pach);
  90. static VOID RemoveItem( IN ALLOC_CACHE_HANDLER * pach);
  91. static BOOL DumpStatsToHtml( OUT CHAR * pchBuffer,
  92. IN OUT LPDWORD lpcchBuffer );
  93. static void CALLBACK CleanupAllLookasides( PVOID pvContext, BOOLEAN );
  94. static BOOL SetLookasideCleanupInterval( VOID );
  95. static BOOL ResetLookasideCleanupInterval( VOID );
  96. private:
  97. static CRITICAL_SECTION sm_csItems;
  98. static BOOL sm_fInitCsItems;
  99. // Head for all alloc-cache-handler objects
  100. static LIST_ENTRY sm_lItemsHead;
  101. static HANDLE sm_hTimer;
  102. static LONG sm_nFillPattern;
  103. }; // class ALLOC_CACHE_HANDLER
  104. typedef ALLOC_CACHE_HANDLER * PALLOC_CACHE_HANDLER;
  105. // You can use ALLOC_CACHE_HANDLER as a per-class allocator
  106. // in your C++ classes. Add the following to your class definition:
  107. //
  108. // protected:
  109. // static ALLOC_CACHE_HANDLER* sm_palloc;
  110. // public:
  111. // static void* operator new(size_t s)
  112. // {
  113. // IRTLASSERT(s == sizeof(C));
  114. // IRTLASSERT(sm_palloc != NULL);
  115. // return sm_palloc->Alloc();
  116. // }
  117. // static void operator delete(void* pv)
  118. // {
  119. // IRTLASSERT(pv != NULL);
  120. // if (sm_palloc != NULL)
  121. // sm_palloc->Free(pv);
  122. // }
  123. //
  124. // Obviously, you must initialize sm_palloc before you can allocate
  125. // any objects of this class.
  126. //
  127. // Note that if you derive a class from this base class, the derived class
  128. // must also provide its own operator new and operator delete. If not, the
  129. // base class's allocator will be called, but the size of the derived
  130. // object will almost certainly be larger than that of the base object.
  131. // Furthermore, the allocator will not be used for arrays of objects
  132. // (override operator new[] and operator delete[]), but this is a
  133. // harder problem since the allocator works with one fixed size.
  134. DWORD
  135. I_AtqReadRegDword(
  136. IN HKEY hkey,
  137. IN LPCSTR pszValueName,
  138. IN DWORD dwDefaultValue
  139. );
  140. # endif // _ACACHE_HXX_
  141. /************************ End of File ***********************/