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.

244 lines
9.3 KiB

  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2001-2002 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: threadpoolapi.h
  6. *
  7. * Content: DirectPlay Thread Pool API implementation header file.
  8. *
  9. * History:
  10. * Date By Reason
  11. * ======== ======== =========
  12. * 11/02/01 VanceO Created.
  13. *
  14. ******************************************************************************/
  15. #ifndef __THREADPOOLAPI_H__
  16. #define __THREADPOOLAPI_H__
  17. //=============================================================================
  18. // Macros
  19. //=============================================================================
  20. #ifdef DPNBUILD_ONLYONEPROCESSOR
  21. #define NUM_CPUS(pDPTPObject) 1
  22. #define WORKQUEUE_FOR_CPU(pDPTPObject, dwCPUNum) (&(pDPTPObject)->WorkQueue)
  23. #else // ! DPNBUILD_ONLYONEPROCESSOR
  24. #define NUM_CPUS(pDPTPObject) (pDPTPObject)->dwNumCPUs
  25. #define WORKQUEUE_FOR_CPU(pDPTPObject, dwCPUNum) (pDPTPObject)->papCPUWorkQueues[dwCPUNum]
  26. #endif // ! DPNBUILD_ONLYONEPROCESSOR
  27. //=============================================================================
  28. // Thread pool interface object flags
  29. //=============================================================================
  30. #define DPTPOBJECTFLAG_USER_INITIALIZED 0x00000001 // the user interface has been initialized
  31. #define DPTPOBJECTFLAG_USER_DOINGWORK 0x00000002 // the user interface is currently calling the DoWork method
  32. #ifndef DPNBUILD_NOPARAMVAL
  33. #define DPTPOBJECTFLAG_USER_PARAMVALIDATION 0x00008000 // the user interface should perform parameter validation
  34. #endif // ! DPNBUILD_NOPARAMVAL
  35. #ifndef DPNBUILD_ONLYONETHREAD
  36. #define DPTPOBJECTFLAG_THREADCOUNTCHANGING 0x00010000 // threads are currently being added or removed
  37. #endif // ! DPNBUILD_ONLYONETHREAD
  38. //=============================================================================
  39. // Thread pool interface object
  40. //=============================================================================
  41. typedef struct _DPTHREADPOOLOBJECT
  42. {
  43. #ifdef DPNBUILD_LIBINTERFACE
  44. //
  45. // For lib interface builds, the interface Vtbl and refcount are embedded
  46. // in the object itself.
  47. //
  48. LPVOID lpVtbl; // must be first entry in structure
  49. #if ((! defined(DPNBUILD_ONLYONETHREAD)) || (defined(DPNBUILD_MULTIPLETHREADPOOLS)))
  50. LONG lRefCount; // reference count for object
  51. #endif // ! DPNBUILD_ONLYONETHREAD or DPNBUILD_MULTIPLETHREADPOOLS
  52. #endif // DPNBUILD_LIBINTERFACE
  53. BYTE Sig[4]; // debugging signature ('DPTP')
  54. DWORD dwFlags; // flags describing this thread pool object
  55. #ifdef DPNBUILD_ONLYONEPROCESSOR
  56. DPTPWORKQUEUE WorkQueue; // work queue structure for only CPU
  57. #else // ! DPNBUILD_ONLYONEPROCESSOR
  58. DWORD dwNumCPUs; // number of CPUs in this machine
  59. DPTPWORKQUEUE ** papCPUWorkQueues; // pointer to array of work queue structure pointers for each CPU
  60. DWORD dwCurrentCPUSelection; // current CPU selection for items that can be run on any processor
  61. #endif // ! DPNBUILD_ONLYONEPROCESSOR
  62. #ifdef DPNBUILD_ONLYONETHREAD
  63. DWORD dwWorkRecursionCount; // how many times DoWork, WaitWhileWorking, or SleepWhileWorking have been recursively called
  64. #else // ! DPNBUILD_ONLYONETHREAD
  65. DWORD dwTotalUserThreadCount; // the sum of what the user requested for thread counts for all processors, or -1 if unknown
  66. DWORD dwTotalDesiredWorkThreadCount; // the maximum number of threads requested via the work interface, or -1 if unknown
  67. DWORD dwWorkRecursionCountTlsIndex; // Thread Local Storage index for storing the Work recursion count for non-worker threads
  68. LONG lNumThreadCountChangeWaiters; // number of threads waiting for an existing thread to complete its thread count change
  69. DNHANDLE hThreadCountChangeComplete; // semaphore to be signalled when the existing thread completes the thread count change
  70. #endif // ! DPNBUILD_ONLYONETHREAD
  71. #if ((! defined(DPNBUILD_ONLYONETHREAD)) || (! defined(DPNBUILD_NOPARAMVAL)))
  72. DWORD dwCurrentDoWorkThreadID; // ID of the current thread inside DoWork
  73. #endif // ! DPNBUILD_ONLYONETHREAD or ! DPNBUILD_NOPARAMVAL
  74. #ifndef DPNBUILD_ONLYONETHREAD
  75. DNCRITICAL_SECTION csLock; // lock protecting this object
  76. #ifdef DPNBUILD_MANDATORYTHREADS
  77. DWORD dwMandatoryThreadCount; // number of mandatory threads currently active
  78. #ifdef DBG
  79. CBilink blMandatoryThreads; // list of mandatory threads that are currently active
  80. #endif // DBG
  81. #endif // DPNBUILD_MANDATORYTHREADS
  82. #endif // !DPNBUILD_ONLYONETHREAD
  83. } DPTHREADPOOLOBJECT, * PDPTHREADPOOLOBJECT;
  84. //=============================================================================
  85. // Interface functions
  86. //=============================================================================
  87. #if ((! defined(DPNBUILD_ONLYONETHREAD)) || (! defined(DPNBUILD_LIBINTERFACE)))
  88. //
  89. // IDirectPlay8ThreadPool
  90. //
  91. STDMETHODIMP DPTP_Initialize(IDirectPlay8ThreadPool * pInterface,
  92. PVOID const pvUserContext,
  93. const PFNDPNMESSAGEHANDLER pfn,
  94. const DWORD dwFlags);
  95. STDMETHODIMP DPTP_Close(IDirectPlay8ThreadPool * pInterface,
  96. const DWORD dwFlags);
  97. STDMETHODIMP DPTP_GetThreadCount(IDirectPlay8ThreadPool * pInterface,
  98. const DWORD dwProcessorNum,
  99. DWORD * const pdwNumThreads,
  100. const DWORD dwFlags);
  101. STDMETHODIMP DPTP_SetThreadCount(IDirectPlay8ThreadPool * pInterface,
  102. const DWORD dwProcessorNum,
  103. const DWORD dwNumThreads,
  104. const DWORD dwFlags);
  105. #endif // ! DPNBUILD_ONLYONETHREAD or ! DPNBUILD_LIBINTERFACE
  106. #ifdef DPNBUILD_LIBINTERFACE
  107. STDMETHODIMP DPTP_DoWork(const DWORD dwAllowedTimeSlice,
  108. const DWORD dwFlags);
  109. #else // ! DPNBUILD_LIBINTERFACE
  110. STDMETHODIMP DPTP_DoWork(IDirectPlay8ThreadPool * pInterface,
  111. const DWORD dwAllowedTimeSlice,
  112. const DWORD dwFlags);
  113. #endif // ! DPNBUILD_LIBINTERFACE
  114. //
  115. // IDirectPlay8ThreadPoolWork
  116. //
  117. STDMETHODIMP DPTPW_QueueWorkItem(IDirectPlay8ThreadPoolWork * pInterface,
  118. const DWORD dwCPU,
  119. const PFNDPTNWORKCALLBACK pfnWorkCallback,
  120. PVOID const pvCallbackContext,
  121. const DWORD dwFlags);
  122. STDMETHODIMP DPTPW_ScheduleTimer(IDirectPlay8ThreadPoolWork * pInterface,
  123. const DWORD dwCPU,
  124. const DWORD dwDelay,
  125. const PFNDPTNWORKCALLBACK pfnWorkCallback,
  126. PVOID const pvCallbackContext,
  127. void ** const ppvTimerData,
  128. UINT * const puiTimerUnique,
  129. const DWORD dwFlags);
  130. STDMETHODIMP DPTPW_StartTrackingFileIo(IDirectPlay8ThreadPoolWork * pInterface,
  131. const DWORD dwCPU,
  132. const HANDLE hFile,
  133. const DWORD dwFlags);
  134. STDMETHODIMP DPTPW_StopTrackingFileIo(IDirectPlay8ThreadPoolWork * pInterface,
  135. const DWORD dwCPU,
  136. const HANDLE hFile,
  137. const DWORD dwFlags);
  138. STDMETHODIMP DPTPW_CreateOverlapped(IDirectPlay8ThreadPoolWork * pInterface,
  139. const DWORD dwCPU,
  140. const PFNDPTNWORKCALLBACK pfnWorkCallback,
  141. PVOID const pvCallbackContext,
  142. OVERLAPPED ** const ppOverlapped,
  143. const DWORD dwFlags);
  144. STDMETHODIMP DPTPW_SubmitIoOperation(IDirectPlay8ThreadPoolWork * pInterface,
  145. OVERLAPPED * const pOverlapped,
  146. const DWORD dwFlags);
  147. STDMETHODIMP DPTPW_ReleaseOverlapped(IDirectPlay8ThreadPoolWork * pInterface,
  148. OVERLAPPED * const pOverlapped,
  149. const DWORD dwFlags);
  150. STDMETHODIMP DPTPW_CancelTimer(IDirectPlay8ThreadPoolWork * pInterface,
  151. void * const pvTimerData,
  152. const UINT uiTimerUnique,
  153. const DWORD dwFlags);
  154. STDMETHODIMP DPTPW_ResetCompletingTimer(IDirectPlay8ThreadPoolWork * pInterface,
  155. void * const pvTimerData,
  156. const DWORD dwNewDelay,
  157. const PFNDPTNWORKCALLBACK pfnNewWorkCallback,
  158. PVOID const pvNewCallbackContext,
  159. UINT * const puiNewTimerUnique,
  160. const DWORD dwFlags);
  161. STDMETHODIMP DPTPW_WaitWhileWorking(IDirectPlay8ThreadPoolWork * pInterface,
  162. const HANDLE hWaitObject,
  163. const DWORD dwFlags);
  164. STDMETHODIMP DPTPW_SleepWhileWorking(IDirectPlay8ThreadPoolWork * pInterface,
  165. const DWORD dwTimeout,
  166. const DWORD dwFlags);
  167. STDMETHODIMP DPTPW_RequestTotalThreadCount(IDirectPlay8ThreadPoolWork * pInterface,
  168. const DWORD dwNumThreads,
  169. const DWORD dwFlags);
  170. STDMETHODIMP DPTPW_GetThreadCount(IDirectPlay8ThreadPoolWork * pInterface,
  171. const DWORD dwCPU,
  172. DWORD * const pdwNumThreads,
  173. const DWORD dwFlags);
  174. STDMETHODIMP DPTPW_GetWorkRecursionDepth(IDirectPlay8ThreadPoolWork * pInterface,
  175. DWORD * const pdwDepth,
  176. const DWORD dwFlags);
  177. STDMETHODIMP DPTPW_Preallocate(IDirectPlay8ThreadPoolWork * pInterface,
  178. const DWORD dwNumWorkItems,
  179. const DWORD dwNumTimers,
  180. const DWORD dwNumIoOperations,
  181. const DWORD dwFlags);
  182. #ifdef DPNBUILD_MANDATORYTHREADS
  183. STDMETHODIMP DPTPW_CreateMandatoryThread(IDirectPlay8ThreadPoolWork * pInterface,
  184. LPSECURITY_ATTRIBUTES lpThreadAttributes,
  185. SIZE_T dwStackSize,
  186. LPTHREAD_START_ROUTINE lpStartAddress,
  187. LPVOID lpParameter,
  188. LPDWORD lpThreadId,
  189. HANDLE *const phThread,
  190. const DWORD dwFlags);
  191. #endif // DPNBUILD_MANDATORYTHREADS
  192. #endif // __THREADPOOLAPI_H__