예제 #1
0
//------------------------------------------------------------------------------
static void* eventProcessThread(void* pArg_p)
{
    struct timespec curTime;
    struct timespec timeout;

    UNUSED_PARAMETER(pArg_p);

    while (!instance_l.fStopProcessThread)
    {
        clock_gettime(CLOCK_REALTIME, &curTime);
        timeout.tv_sec = 0;
        timeout.tv_nsec = 50000 * 1000;
        TIMESPECADD(&timeout, &curTime);

        if (sem_timedwait(instance_l.semUserData, &timeout) == 0)
        {
            if (eventucal_getEventCountCircbuf(kEventQueueUInt) > 0)
                eventucal_processEventCircbuf(kEventQueueUInt);
        }
    }

    instance_l.fStopProcessThread = FALSE;

    return NULL;
}
//------------------------------------------------------------------------------
void eventucal_process(void)
{
    if (eventucal_getEventCountCircbuf(kEventQueueK2U) > 0)
    {
        eventucal_processEventCircbuf(kEventQueueK2U);
    }
}
//------------------------------------------------------------------------------
static DWORD WINAPI eventThread(LPVOID arg)
{
    tEventuCalInstance*     pInstance = (tEventuCalInstance*)arg;
    DWORD                   waitResult;

    TRACE("User event thread %d waiting for events...\n", GetCurrentThreadId());

    while (!pInstance->fStopThread)
    {
        waitResult = WaitForSingleObject(pInstance->semUserData, 5000);
        switch (waitResult)
        {
            case WAIT_OBJECT_0:
                //TRACE("Received user event!\n");
                /* first handle all kernel to user events --> higher priority! */
                if (eventucal_getEventCountCircbuf(kEventQueueK2U) > 0)
                {
                    eventucal_processEventCircbuf(kEventQueueK2U);
                }
                else
                {
                    if (eventucal_getEventCountCircbuf(kEventQueueUInt) > 0)
                    {
                        eventucal_processEventCircbuf(kEventQueueUInt);
                    }
                }
                break;

            case WAIT_TIMEOUT:
                break;

            default:
                TRACE("%s() Semaphore wait unknown error! Error:%ld\n", __func__, GetLastError());
                break;
        }
    }
    TRACE("User Event Thread is exiting!\n");
    return 0;
}