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.

202 lines
5.3 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. # if !defined( dllexp)
  26. # define dllexp __declspec( dllexport)
  27. # endif // !defined( dllexp)
  28. /************************************************************
  29. * Type Definitions
  30. ************************************************************/
  31. //
  32. // Lookaside cleanup interval and configuration key
  33. //
  34. #define ACACHE_REG_PARAMS_REG_KEY "System\\CurrentControlSet\\Services\\InetInfo\\Parameters"
  35. #define ACACHE_REG_LOOKASIDE_CLEANUP_INTERVAL "LookasideCleanupInterval"
  36. #define ACACHE_REG_DEFAULT_CLEANUP_INTERVAL ((15)*(60))
  37. typedef struct _ALLOC_CACHE_CONFIGURATION {
  38. DWORD nConcurrency; // specifies the amount of parallelism Desired.
  39. LONG nThreshold; // max number of items to cache.
  40. DWORD cbSize; // size of the object allocated.
  41. // Other params to be added in the future.
  42. } ALLOC_CACHE_CONFIGURATION;
  43. typedef ALLOC_CACHE_CONFIGURATION * PAC_CONFIG;
  44. typedef struct _ALLOC_CACHE_STATISTICS {
  45. ALLOC_CACHE_CONFIGURATION acConfig;
  46. LONG nTotal;
  47. LONG nAllocCalls;
  48. LONG nFreeCalls;
  49. LONG nFreeEntries;
  50. // Other params to be added in the future.
  51. } ALLOC_CACHE_STATISTICS;
  52. typedef ALLOC_CACHE_STATISTICS * PAC_STATS;
  53. class dllexp ALLOC_CACHE_HANDLER {
  54. public:
  55. ALLOC_CACHE_HANDLER(IN LPCSTR pszName,
  56. IN const ALLOC_CACHE_CONFIGURATION * pacConfig,
  57. BOOL fEnabledCleanupAsserts = TRUE);
  58. ~ALLOC_CACHE_HANDLER(VOID);
  59. BOOL IsValid( VOID) const { return ( m_fValid); }
  60. LPVOID Alloc( VOID );
  61. // LPVOID Alloc( IN DWORD cbSize);
  62. BOOL Free( LPVOID pvBlob);
  63. VOID CleanupLookaside( IN BOOL fForceCleanup );
  64. // Debug Helper routines.
  65. VOID Print( VOID);
  66. BOOL IpPrint( OUT CHAR * pchBuffer, IN OUT LPDWORD pcchSize);
  67. VOID QueryStats( IN ALLOC_CACHE_STATISTICS * pacStats );
  68. private:
  69. BOOL m_fValid;
  70. BOOL m_fCleanupAssertsEnabled;
  71. LONG m_nLastAllocCount;
  72. ALLOC_CACHE_CONFIGURATION m_acConfig;
  73. // Simple alloc-cache - uses a single lock and list :(
  74. CRITICAL_SECTION m_csLock;
  75. SINGLE_LIST_ENTRY m_lHead;
  76. LONG m_nTotal;
  77. LONG m_nAllocCalls;
  78. LONG m_nFreeCalls;
  79. LONG m_nFreeEntries;
  80. LONG m_nFillPattern;
  81. LPCSTR m_pszName;
  82. HANDLE m_hHeap;
  83. VOID Lock(VOID) { EnterCriticalSection( & m_csLock); }
  84. VOID Unlock(VOID) { LeaveCriticalSection( & m_csLock); }
  85. public:
  86. LIST_ENTRY m_lItemsEntry; // for list of alloc-cache-handler objects
  87. public:
  88. static BOOL Initialize(VOID);
  89. static BOOL Cleanup(VOID);
  90. static VOID InsertNewItem( IN ALLOC_CACHE_HANDLER * pach);
  91. static VOID RemoveItem( IN ALLOC_CACHE_HANDLER * pach);
  92. static BOOL DumpStatsToHtml( OUT CHAR * pchBuffer,
  93. IN OUT LPDWORD lpcchBuffer );
  94. static VOID WINAPI CleanupAllLookasides( PVOID pvContext );
  95. static BOOL SetLookasideCleanupInterval( VOID );
  96. static BOOL ResetLookasideCleanupInterval( VOID );
  97. private:
  98. static CRITICAL_SECTION sm_csItems;
  99. // Head for all alloc-cache-handler objects
  100. static LIST_ENTRY sm_lItemsHead;
  101. static DWORD sm_dwScheduleCookie;
  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 ***********************/