uint32_t phOsalNfc_Timer_Create(void)
{
    uint32_t i = 0;

    if (NULL == gpphOsalNfc_Context) {
        return PHNFCSTVAL(CID_NFC_OSAL, NFCSTATUS_INVALID_PARAMETER);
    }

    EnterCriticalSection(&gpphOsalNfc_Context->TimerLock);

    while (i < PH_MAX_OSAL_NUM_TIMERS) 
    {
        /* check whether the timer is free. If free then only it is created */
        if(gpphOsalNfc_Context->TimerList[i].pTimer == NULL)
        {
            gpphOsalNfc_Context->TimerList[i].pTimer = CreateThreadpoolTimer(phOsalNfc_TimerCallback, (void*)i, NULL);
            gpphOsalNfc_Context->TimerList[i].dwThreadId = GetCurrentThreadId();
            break;
        }

        i++;
    }

    LeaveCriticalSection(&gpphOsalNfc_Context->TimerLock);
    
    if ((i == PH_MAX_OSAL_NUM_TIMERS) || (gpphOsalNfc_Context->TimerList[i].pTimer == NULL))
    {
        return PH_OSALNFC_INVALID_TIMER_ID;
    }
    
    return (i + PH_OSAL_TIMER_BASE_ADDRESS);
}
Esempio n. 2
0
void MI_CALL Perf_Indication_EnableIndications(
    _In_opt_ Perf_Indication_Self* self,
    _In_ MI_Context* indicationsContext,
    _In_opt_z_ const MI_Char* nameSpace,
    _In_opt_z_ const MI_Char* className)
{
#ifdef _MSC_VER

    /* NOTE: Do not call MI_PostResult on this context */
    MI_UNREFERENCED_PARAMETER(nameSpace);
    MI_UNREFERENCED_PARAMETER(className);
    
    if (self)
    {
        FILETIME now;

        ZeroMemory(&now, sizeof(FILETIME));

        self->indicationContext = indicationsContext;
        self->indicationTimer = CreateThreadpoolTimer(TimerCallback, self, NULL);
        SetThreadpoolTimer(self->indicationTimer, &now, 0, 1);
    }

#endif
}
Esempio n. 3
0
{
    std::cerr << "Watchdog timer expired: Scilab killed" << std::endl;
    ExitProcess(1);
}
void timeout_process_after(int timeoutDelay)
{
    auto timerid = CreateThreadpoolTimer(kill_process_callback, nullptr, nullptr);

    FILETIME FileDueTime;
    ULARGE_INTEGER ulDueTime;

    // Set the timer to fire in the delay in seconds
    ulDueTime.QuadPart = (ULONGLONG) - (timeoutDelay * 10 * 1000 * 1000);
    FileDueTime.dwHighDateTime = ulDueTime.HighPart;
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);
}
Esempio n. 5
0
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);
    }
}
HRESULT CDriverSimBroadcast::Initialize(_In_ CSocketListener* pSocketListener)
{
    MethodEntry("...");

    _pSocketListener = pSocketListener;

    HRESULT hr = InitBroadcastMessage();
    
    if (SUCCEEDED(hr)) {
        _TpBroadcast = CreateThreadpoolTimer(&s_BroadcastTimerFired, (PVOID)this, nullptr);
        if (_TpBroadcast == nullptr) {
            hr = HRESULT_FROM_WIN32(GetLastError());
        }
    }

    if (SUCCEEDED(hr)) {
        // Convert milliseconds to relative filetime units (100ns)
        LONGLONG dueTime = Int32x32To64(BROADCAST_INTERVAL_MS, -10000);
        SetThreadpoolTimer(_TpBroadcast, (FILETIME*)&dueTime, BROADCAST_INTERVAL_MS, 3000);
    }

    MethodReturnHR(hr);
}