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.

186 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. thread_pool.h
  5. Abstract:
  6. Public routines for the iisplus worker process thread pool.
  7. This thread pool is based on the IIS5 atq implementation.
  8. Author:
  9. Taylor Weiss (TaylorW) 12-Jan-2000
  10. Revision History:
  11. --*/
  12. #ifndef _THREAD_POOL_H_
  13. #define _THREAD_POOL_H_
  14. //
  15. // For the static library version of w3tp, the consumer must set
  16. // this value to be the HINSTANCE of the DLL linking w3tp_static
  17. //
  18. extern HMODULE g_hmodW3TPDLL;
  19. //
  20. // ThreadPoolBindIoCompletionCallback:
  21. //
  22. // The real public API. Clients that wish to queue io completions
  23. // to the process Thread Pool should use this call as they would
  24. // the NT5 thread pool call.
  25. //
  26. BOOL
  27. ThreadPoolBindIoCompletionCallback(
  28. IN HANDLE FileHandle, // handle to file
  29. IN LPOVERLAPPED_COMPLETION_ROUTINE Function, // callback
  30. IN ULONG Flags // reserved
  31. );
  32. //
  33. // ThreadPoolPostCompletion:
  34. //
  35. // Use this function to get one of the process worker threads
  36. // to call your completion function.
  37. //
  38. BOOL ThreadPoolPostCompletion(
  39. IN DWORD dwBytesTransferred,
  40. IN LPOVERLAPPED_COMPLETION_ROUTINE Function,
  41. IN LPOVERLAPPED lpo
  42. );
  43. // forward declarations
  44. enum THREAD_POOL_INFO;
  45. class THREAD_POOL_DATA;
  46. struct THREAD_POOL_CONFIG;
  47. //
  48. // To use a thread pool other than the per process thread pool
  49. // Use the class THREAD_POOL instead of the global functions
  50. //
  51. class dllexp THREAD_POOL
  52. {
  53. public:
  54. static BOOL CreateThreadPool(OUT THREAD_POOL ** ppThreadPool,
  55. IN THREAD_POOL_CONFIG * pThreadPoolConfig);
  56. VOID TerminateThreadPool();
  57. BOOL BindIoCompletionCallback(IN HANDLE hFileHandle,
  58. IN LPOVERLAPPED_COMPLETION_ROUTINE function,
  59. IN ULONG flags);
  60. BOOL PostCompletion(IN DWORD dwBytesTransferred,
  61. IN LPOVERLAPPED_COMPLETION_ROUTINE function,
  62. IN LPOVERLAPPED lpo);
  63. ULONG_PTR SetInfo(IN THREAD_POOL_INFO InfoId,
  64. IN ULONG_PTR Data);
  65. private:
  66. // use create and terminate
  67. THREAD_POOL();
  68. ~THREAD_POOL();
  69. // not implemented
  70. THREAD_POOL(const THREAD_POOL&);
  71. THREAD_POOL& operator=(const THREAD_POOL&);
  72. // private data
  73. THREAD_POOL_DATA * m_pData;
  74. };
  75. struct THREAD_POOL_CONFIG
  76. {
  77. // the initial number of threads to have in the pool
  78. // valid values are 1->DWORD_MAX
  79. DWORD dwInitialThreadCount;
  80. // the absolute maximum number of threads to ever have in the thread pool
  81. DWORD dwAbsoluteMaximumThreadCount;
  82. // the number of threads to allow without calling SetInfo(ThreadPoolIncMaxPoolThreads)
  83. // before doing synchronous operations
  84. DWORD dwSoftLimitThreadCount;
  85. // How long a thread should stay alive if no I/O completions have occurred for it.
  86. DWORD dwThreadTimeout;
  87. // initial stack size for thread creation. Zero will create a default process stack size.
  88. DWORD dwInitialStackSize;
  89. // CPU usage backoff numebr
  90. DWORD dwMaxCPUUsage;
  91. // Maximum CPU concurrency. Zero will equal the # of processors
  92. DWORD dwConcurrency;
  93. // Per second per processor context switch rate maximum.
  94. // we double this number for # of processors > 1
  95. DWORD dwPerSecondContextSwitchMax;
  96. // Before we create a thread, we sample on two sides of a timer
  97. // this determines what the timer period is.
  98. DWORD dwTimerPeriod;
  99. // The exact number of threads to create
  100. // If this is set to something, no new threads will ever be created beyond the startup count here.
  101. DWORD dwExactThreadCount;
  102. // Just some padding to avoid changing a public structure size
  103. // when additional variables are added here
  104. DWORD dwPadding[10];
  105. };
  106. // to get some reasonable defaults for thread pool configuration
  107. HRESULT
  108. InitializeThreadPoolConfigWithDefaults(THREAD_POOL_CONFIG * pThreadPoolConfig);
  109. //
  110. // Override defaults with registry settings
  111. //
  112. HRESULT
  113. OverrideThreadPoolConfigWithRegistry(
  114. IN OUT THREAD_POOL_CONFIG * pThreadPoolConfig,
  115. IN WCHAR * pszRegistryPath );
  116. //
  117. // Configuration API calls. ONLY ULATQ should call these.
  118. //
  119. HRESULT
  120. ThreadPoolInitialize( DWORD cbInitialStackSize );
  121. HRESULT
  122. ThreadPoolTerminate( VOID );
  123. ULONG_PTR
  124. ThreadPoolSetInfo(
  125. IN THREAD_POOL_INFO InfoId,
  126. IN ULONG_PTR Data
  127. );
  128. //
  129. // IDs for getting and setting configuration options
  130. //
  131. enum THREAD_POOL_INFO
  132. {
  133. ThreadPoolIncMaxPoolThreads, // Up the max thread count - set only
  134. ThreadPoolDecMaxPoolThreads, // Decrease the max thread count - set only
  135. };
  136. #endif // !_THREAD_POOL_H_