void MI_CALL Perf_Indication_DisableIndications( _In_opt_ Perf_Indication_Self* self, _In_ MI_Context* indicationsContext, _In_opt_z_ const MI_Char* nameSpace, _In_opt_z_ const MI_Char* className) { MI_UNREFERENCED_PARAMETER(nameSpace); MI_UNREFERENCED_PARAMETER(className); #ifdef _MSC_VER if (self) { self->indicationContext = 0; self->shutdownCalled = MI_TRUE; SetThreadpoolTimer(self->indicationTimer, NULL, 0, 0); WaitForThreadpoolTimerCallbacks(self->indicationTimer, TRUE); CloseThreadpoolTimer(self->indicationTimer); self->shutdownCalled = MI_FALSE; } #endif MI_PostResult(indicationsContext, MI_RESULT_OK); }
void phOsalNfc_Timer_Delete(uint32_t TimerId) { uint32_t uIndex; // // In various places in the code, timers are initialized only // after they are first needed. Despite this fact, they are // deleted unconditionally when their context is being deleted // Intead of adding an if statement in all places where // timers are being deleted, this check is added to prevent // a NULL deref. // if (NULL == gpphOsalNfc_Context || PH_OSALNFC_TIMER_ID_INVALID == TimerId) { return; } uIndex = TimerId - PH_OSAL_TIMER_BASE_ADDRESS; EnterCriticalSection(&gpphOsalNfc_Context->TimerLock); if(gpphOsalNfc_Context->TimerList[uIndex].pTimer != NULL) { SetThreadpoolTimer(gpphOsalNfc_Context->TimerList[uIndex].pTimer, NULL, 0, 0); LeaveCriticalSection(&gpphOsalNfc_Context->TimerLock); WaitForThreadpoolTimerCallbacks(gpphOsalNfc_Context->TimerList[uIndex].pTimer, TRUE); EnterCriticalSection(&gpphOsalNfc_Context->TimerLock); CloseThreadpoolTimer(gpphOsalNfc_Context->TimerList[uIndex].pTimer); gpphOsalNfc_Context->TimerList[uIndex].pTimer = NULL; gpphOsalNfc_Context->TimerList[uIndex].pCallback = NULL; gpphOsalNfc_Context->TimerList[uIndex].pContext = NULL; gpphOsalNfc_Context->TimerList[uIndex].bFired = FALSE; uIndex = 0; while (uIndex < PH_MAX_OSAL_NUM_TIMERS) { if (gpphOsalNfc_Context->TimerList[uIndex].pTimer != NULL) { break; } uIndex++; } } LeaveCriticalSection(&gpphOsalNfc_Context->TimerLock); }
int WINAPI _tWinMain(HINSTANCE, HINSTANCE, PTSTR, int) { //TcpClient(); _tcscpy_s(g_szCaption, _countof(g_szCaption), TEXT("Timed Message Box")); // How many seconds we'll give the user to respond g_nSecLeft = 10; // Create the threadpool timer object PTP_TIMER lpTimer = CreateThreadpoolTimer(MsgBoxTimeoutCallback, NULL, NULL); if (lpTimer == NULL) { TCHAR szMsg[MAX_PATH]; StringCchPrintf(szMsg, _countof(szMsg), TEXT("Impossible to create the timer: %u"), GetLastError()); MessageBox(NULL, szMsg, TEXT("Error"), MB_OK | MB_ICONERROR); return(-1); } // Start the timer in one second to trigger every 1 second ULARGE_INTEGER ulRelativeStartTime; ulRelativeStartTime.QuadPart = (LONGLONG) -(10000000); // start in 1 second FILETIME ftRelativeStartTime; ftRelativeStartTime.dwHighDateTime = ulRelativeStartTime.HighPart; ftRelativeStartTime.dwLowDateTime = ulRelativeStartTime.LowPart; SetThreadpoolTimer( lpTimer, &ftRelativeStartTime, 1000, // Triggers every 1000 milliseconds 0 ); // Display the message box MessageBox(NULL, TEXT("You have 10 seconds to respond"), g_szCaption, MB_OK); // Clean up the timer CloseThreadpoolTimer(lpTimer); // Let us know if the user responded or if we timed out MessageBox( NULL, (g_nSecLeft == 1) ? TEXT("Timeout") : TEXT("User responded"), TEXT("Result"), MB_OK); return(0); }
HRESULT CDriverSimBroadcast::Uninitialize() { MethodEntry("..."); HRESULT hr = S_OK; if (_TpBroadcast != nullptr) { SetThreadpoolTimer(_TpBroadcast, nullptr, 0, 0); WaitForThreadpoolTimerCallbacks(_TpBroadcast, TRUE); CloseThreadpoolTimer(_TpBroadcast); _TpBroadcast = nullptr; } _pSocketListener = nullptr; MethodReturnHR(hr); }
static void CALLBACK TimerCallback( __inout PTP_CALLBACK_INSTANCE instance, __inout_opt PVOID context, __inout PTP_TIMER timer ) { MI_Result result = MI_RESULT_FAILED; Perf_Indication_Self* self; Perf_Indication indicationInstance = {{0}}; if(!context) { return; } self = (Perf_Indication_Self*)context; result = Perf_Indication_Construct(&indicationInstance, self->indicationContext); if(result != MI_RESULT_OK) return; result = FillInstance(self->indicationContext, &indicationInstance.__instance, self->keyCounter++); if(result != MI_RESULT_OK) return; Perf_Indication_Post(&indicationInstance, self->indicationContext, 0, 0); Perf_Indication_Destruct(&indicationInstance); if(self->shutdownCalled != MI_TRUE) { // Clean up the previous timer. Do not do a WaitForThreadpoolTimerCallbacks as this will hang. // Instead directly call CloseThreadPoolTimer. This asynchronously closes the timer when outstanding calls are done. // As the timer settings are for 1 event only, there will be no outstanding calls, but only the current call. SetThreadpoolTimer(self->indicationTimer, NULL, 0, 0); CloseThreadpoolTimer(self->indicationTimer); FILETIME now; ZeroMemory(&now, sizeof(FILETIME)); self->indicationTimer = CreateThreadpoolTimer(TimerCallback, self, NULL); SetThreadpoolTimer(self->indicationTimer, &now, 0, 1); } }