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.

221 lines
5.3 KiB

  1. /*++
  2. Copyright (c) 1999-2001 Microsoft Corporation
  3. Module Name:
  4. thread_pool_private.h
  5. Abstract:
  6. Internal declarations and types for the IIS+ worker process
  7. thread pool.
  8. This thread pool is based on the IIS5 atq implementation.
  9. Author:
  10. Taylor Weiss (TaylorW) 12-Jan-2000
  11. Revision History:
  12. --*/
  13. #ifndef _THREAD_POOL_PRIVATE_H_
  14. #define _THREAD_POOL_PRIVATE_H_
  15. #include <tracelog.h>
  16. /**********************************************************************
  17. Configuration
  18. **********************************************************************/
  19. //
  20. // Registry parameters
  21. // HKLM\System\CurrentControlSet\Services\InetInfo\Parameters
  22. //
  23. #define THREAD_POOL_REG_PER_PROCESSOR_THREADS TEXT("MaxPoolThreads")
  24. #define THREAD_POOL_REG_POOL_THREAD_LIMIT TEXT("PoolThreadLimit")
  25. #define THREAD_POOL_REG_PER_PROCESSOR_CONCURRENCY TEXT("MaxConcurrency")
  26. #define THREAD_POOL_REG_THREAD_TIMEOUT TEXT("ThreadTimeout")
  27. #define THREAD_POOL_REG_POOL_THREAD_START TEXT("ThreadPoolStartupThreadCount")
  28. #define THREAD_POOL_REG_START_DELAY TEXT("ThreadPoolStartDelay")
  29. #define THREAD_POOL_REG_MAX_CONTEXT_SWITCH TEXT("ThreadPoolMaxContextSwitch")
  30. #define THREAD_POOL_REG_REF_TRACE_COUNTER TEXT("ThreadPoolRefTraceCounter")
  31. #define THREAD_POOL_REG_MAX_CPU TEXT("ThreadPoolMaxCPU")
  32. #define THREAD_POOL_REG_EXACT_THREAD_COUNT TEXT("ThreadPoolExactThreadCount")
  33. //
  34. // Default values
  35. //
  36. // special value of 0 means that system will determine this dynamically.
  37. const DWORD THREAD_POOL_REG_DEF_PER_PROCESSOR_CONCURRENCY = 0;
  38. // how many threads do we start with
  39. const LONG THREAD_POOL_REG_DEF_PER_PROCESSOR_THREADS = 4;
  40. // thirty minutes
  41. const DWORD THREAD_POOL_REG_DEF_THREAD_TIMEOUT = (30 * 60);
  42. // thread limits
  43. const LONG THREAD_POOL_REG_MIN_POOL_THREAD_LIMIT = 64;
  44. const LONG THREAD_POOL_REG_DEF_POOL_THREAD_LIMIT = 128;
  45. const LONG THREAD_POOL_REG_MAX_POOL_THREAD_LIMIT = 256;
  46. // thread_manager constants
  47. const DWORD THREAD_POOL_TIMER_CALLBACK = 1000;
  48. const DWORD THREAD_POOL_CONTEXT_SWITCH_RATE = 10000;
  49. const DWORD THREAD_POOL_MAX_CPU_USAGE_DEFAULT = -1;
  50. const DWORD THREAD_POOL_EXACT_NUMBER_OF_THREADS_DEFAULT = 0;
  51. //
  52. // Enumeration used for Ref Trace logging registry key
  53. //
  54. enum REF_TRACE_COUNTER_ENUM
  55. {
  56. TRACE_NONE = 0,
  57. TRACE_WHEN_NULL,
  58. TRACE_ALWAYS
  59. };
  60. extern DWORD g_dwcCPU;
  61. /**********************************************************************
  62. **********************************************************************/
  63. // Arbitrary signal for the thread to shutdown
  64. const ULONG_PTR THREAD_POOL_THREAD_EXIT_KEY = -1;
  65. /**********************************************************************
  66. Function declarations
  67. **********************************************************************/
  68. DWORD
  69. I_ThreadPoolReadRegDword(
  70. IN HKEY hkey,
  71. IN LPCTSTR pszValueName,
  72. IN DWORD dwDefaultValue
  73. );
  74. class THREAD_POOL;
  75. class THREAD_MANAGER;
  76. #define SIGNATURE_THREAD_POOL_DATA ((DWORD) 'ADPT')
  77. #define SIGNATURE_THREAD_POOL_DATA_FREE ((DWORD) 'xDPT')
  78. /*++
  79. Storage for data members of THREAD_POOL
  80. --*/
  81. class THREAD_POOL_DATA
  82. {
  83. private:
  84. DWORD m_dwSignature;
  85. public:
  86. THREAD_POOL_DATA(THREAD_POOL * pPool)
  87. {
  88. m_dwSignature = SIGNATURE_THREAD_POOL_DATA;
  89. m_hCompPort = NULL;
  90. m_cThreads = 0;
  91. m_cAvailableThreads = 0;
  92. m_fShutdown = FALSE;
  93. m_pThreadManager = NULL;
  94. DBG_ASSERT(NULL != pPool);
  95. m_pPool = pPool;
  96. #if DBG
  97. m_pTraceLog = NULL;
  98. m_dwTraceRegSetting = 0;
  99. #endif
  100. }
  101. ~THREAD_POOL_DATA()
  102. {
  103. DBG_ASSERT(SIGNATURE_THREAD_POOL_DATA == m_dwSignature);
  104. m_dwSignature = SIGNATURE_THREAD_POOL_DATA_FREE;
  105. m_pPool = NULL;
  106. DBG_ASSERT(NULL == m_pThreadManager);
  107. DBG_ASSERT(NULL == m_hCompPort);
  108. DBG_ASSERT(0 == m_cAvailableThreads);
  109. DBG_ASSERT(0 == m_cThreads);
  110. #if DBG
  111. DBG_ASSERT(NULL == m_pTraceLog);
  112. DBG_ASSERT(0 == m_dwTraceRegSetting);
  113. #endif
  114. }
  115. BOOL InitializeThreadPool(THREAD_POOL_CONFIG * pThreadPoolConfig);
  116. DWORD ThreadPoolThread();
  117. static DWORD ThreadPoolThread(LPVOID pvThis);
  118. static void WINAPI ThreadPoolStop(LPVOID pvThis);
  119. BOOL ThreadPoolCheckThreadStatus();
  120. BOOL WINAPI OkToCreateAnotherThread();
  121. // -------------------------
  122. // Current state information
  123. // -------------------------
  124. //
  125. // Handle for completion port
  126. //
  127. HANDLE m_hCompPort;
  128. //
  129. // number of thread in the pool
  130. //
  131. LONG m_cThreads;
  132. //
  133. // # of threads waiting on the port.
  134. //
  135. LONG m_cAvailableThreads;
  136. //
  137. // Are we shutting down
  138. //
  139. BOOL m_fShutdown;
  140. //
  141. // Pointer to THREAD_MANAGER
  142. //
  143. THREAD_MANAGER *m_pThreadManager;
  144. //
  145. // Back pointer to owner THREAD_POOL
  146. //
  147. THREAD_POOL * m_pPool;
  148. //
  149. // the configuration information
  150. //
  151. THREAD_POOL_CONFIG m_poolConfig;
  152. #if DBG
  153. //
  154. // Poniter to reference logging var
  155. //
  156. PTRACE_LOG m_pTraceLog;
  157. //
  158. // Reg setting for Ref tracing
  159. //
  160. DWORD m_dwTraceRegSetting;
  161. #endif
  162. };
  163. #endif // !_THREAD_POOL_PRIVATE_H_