1 /*++ 2 3 Copyright (c) Microsoft. All rights reserved. 4 5 Module Name: 6 7 FxInterruptThreadpoolUm.hpp 8 9 Abstract: 10 11 This file contains the class definition for the threadpool for interrupt object. 12 13 Author: 14 15 16 17 Environment: 18 19 User mode only 20 21 Revision History: 22 23 24 25 --*/ 26 #pragma once 27 28 #define MINIMUM_THREAD_COUNT_DEFAULT (1) 29 class FxInterrupt; 30 31 class FxInterruptThreadpool : FxGlobalsStump 32 { 33 34 private: 35 36 // 37 // Pointer to structure representing thread pool 38 // 39 PTP_POOL m_Pool; 40 41 // 42 // Structure representing callback environment for thread pool 43 // 44 TP_CALLBACK_ENVIRON m_CallbackEnvironment; 45 46 // 47 // Minimum thread pool thread count 48 // 49 ULONG m_MinimumThreadCount; 50 51 52 HRESULT 53 Initialize( 54 ); 55 56 public: 57 58 FxInterruptThreadpool( 59 PFX_DRIVER_GLOBALS FxDriverGlobals 60 ); 61 62 ~FxInterruptThreadpool(); 63 64 static 65 HRESULT 66 _CreateAndInit( 67 _In_ PFX_DRIVER_GLOBALS DriverGlobals, 68 _Out_ FxInterruptThreadpool** ppThreadpool 69 ); 70 71 PTP_CALLBACK_ENVIRON GetCallbackEnvironment(VOID)72 GetCallbackEnvironment( 73 VOID 74 ) 75 { 76 return &m_CallbackEnvironment; 77 } 78 79 PTP_WAIT CreateThreadpoolWait(__in PTP_WAIT_CALLBACK pfnwa,__inout_opt PVOID Context)80 CreateThreadpoolWait( 81 __in PTP_WAIT_CALLBACK pfnwa, 82 __inout_opt PVOID Context 83 ) 84 { 85 return ::CreateThreadpoolWait(pfnwa, Context, &m_CallbackEnvironment); 86 } 87 88 HRESULT 89 UpdateThreadPoolThreadLimits( 90 _In_ ULONG InterruptCount 91 ); 92 }; 93 94 class FxInterruptWaitblock : FxGlobalsStump 95 { 96 97 private: 98 99 // 100 // threadpool wait block 101 // 102 PTP_WAIT m_Wait; 103 104 // 105 // auto reset event 106 // 107 HANDLE m_Event; 108 109 110 HRESULT 111 Initialize( 112 __in FxInterruptThreadpool* Threadpool, 113 __in FxInterrupt* Interrupt, 114 __in PTP_WAIT_CALLBACK WaitCallback 115 ); 116 117 public: 118 119 static 120 HRESULT 121 _CreateAndInit( 122 _In_ FxInterruptThreadpool* Threadpool, 123 _In_ FxInterrupt* Interrupt, 124 _In_ PTP_WAIT_CALLBACK WaitCallback, 125 _Out_ FxInterruptWaitblock** Waitblock 126 ); 127 FxInterruptWaitblock(PFX_DRIVER_GLOBALS FxDriverGlobals)128 FxInterruptWaitblock( 129 PFX_DRIVER_GLOBALS FxDriverGlobals 130 ) : 131 FxGlobalsStump(FxDriverGlobals), 132 m_Wait(NULL), 133 m_Event(NULL) 134 { 135 } 136 137 ~FxInterruptWaitblock(); 138 139 VOID CloseThreadpoolWait(VOID)140 CloseThreadpoolWait( 141 VOID 142 ) 143 { 144 ::CloseThreadpoolWait(m_Wait); 145 } 146 147 VOID SetThreadpoolWait(VOID)148 SetThreadpoolWait( 149 VOID 150 ) 151 { 152 // 153 // associates event with wait block and queues it 154 // to thread pool queue. 155 // 156 ::SetThreadpoolWait(m_Wait, m_Event, NULL); 157 } 158 159 VOID ClearThreadpoolWait(VOID)160 ClearThreadpoolWait( 161 VOID 162 ) 163 { 164 // 165 // Passing a NULL handle clears the wait 166 // 167 ::SetThreadpoolWait(m_Wait, NULL, NULL); 168 } 169 170 VOID WaitForOutstandingCallbackToComplete(VOID)171 WaitForOutstandingCallbackToComplete( 172 VOID 173 ) 174 { 175 ::WaitForThreadpoolWaitCallbacks(m_Wait, FALSE); 176 } 177 178 HANDLE GetEventHandle(VOID)179 GetEventHandle( 180 VOID 181 ) 182 { 183 return m_Event; 184 } 185 186 VOID ResetEvent(VOID)187 ResetEvent( 188 VOID 189 ) 190 { 191 ::ResetEvent(m_Event); 192 } 193 194 }; 195 196