int ShbIpcThreadSignalNewData (void *pvThreadParam_p)
{
tShbInstance    pShbInstance;
tShbMemInst*    pShbMemInst;
tShbMemHeader*  pShbMemHeader;
int             fCallAgain;

    pShbInstance = (tShbMemInst*)pvThreadParam_p;
    pShbMemInst  = ShbIpcGetShbMemInst (pShbInstance);
    pShbMemHeader = ShbIpcGetShbMemHeader (pShbMemInst);

    DEBUG_LVL_26_TRACE1("ShbIpcThreadSignalNewData(%p)\n",pvThreadParam_p);

    set_user_nice(current, pShbMemInst->m_lThreadNewDataNice);

#ifdef CONFIG_PREEMPT_RT
    if (pShbMemInst->m_lThreadNewDataNice == -20) // highest priority
    {
    struct sched_param  rt_prio;
        rt_prio.sched_priority = 79;
        sched_setscheduler(current, SCHED_FIFO, &rt_prio);
    }
#endif

//            DEBUG_LVL_29_TRACE1("ShbIpcThreadSignalNewData wait for New Data Sem %p\n",pShbMemInst->m_pSemNewData);
    while (!kthread_should_stop())
    {
        wait_event_interruptible(pShbMemHeader->m_WaitQueueNewData,
            kthread_should_stop()
            || (pShbMemHeader->m_fNewData != FALSE));

        if (pShbMemHeader->m_fNewData != FALSE)
        {
            pShbMemHeader->m_fNewData = FALSE;
            do
            {
                fCallAgain = pShbMemInst->m_pfnSigHndlrNewData(pShbInstance);
                // call scheduler, which will execute any task with higher priority
                schedule();
            } while (fCallAgain != FALSE);
        }
    }

    DEBUG_LVL_29_TRACE0("ShbIpcThreadSignalNewData terminated \n");

    return 0;
}
tShbError  ShbIpcReleaseBuffer (tShbInstance pShbInstance_p)
{
tShbMemInst*    pShbMemInst;
tShbMemHeader*  pShbMemHeader;
tShbError       ShbError;
tShbError       ShbError2;

    DEBUG_LVL_26_TRACE1("ShbIpcReleaseBuffer(%p)\n", pShbInstance_p);
    if (pShbInstance_p == NULL)
    {
        return (kShbOk);
    }
    pShbMemInst   = ShbIpcGetShbMemInst   (pShbInstance_p);
    pShbMemHeader = ShbIpcGetShbMemHeader (pShbMemInst);

    // stop threads in any case, because they are bound to that specific instance
    ShbError2 = ShbIpcStopSignalingNewData (pShbInstance_p);

    down(&pShbMemInst->m_SemaphoreStopThreadJobReady);
    if (pShbMemInst->m_tThreadJobReadyId != INVALID_ID)
    {
        kthread_stop(pShbMemInst->m_tThreadJobReadyId);
    }
    up(&pShbMemInst->m_SemaphoreStopThreadJobReady);


    if ( !--pShbMemHeader->m_ulRefCount )
    {
        ShbError = kShbOk;
        // delete mem table element
        ShbIpcDeleteListElement(pShbMemHeader->m_iBufferId);
        // delete shared mem
        kfree(pShbMemInst->m_pShbMemHeader);
    }
    else
    {
        ShbError = kShbMemUsedByOtherProcs;
    }
    //delete privat mem
    kfree(pShbMemInst);
    return (ShbError);
}
Example #3
0
tShbError  ShbIpcReleaseBuffer (tShbInstance pShbInstance_p)
{
tShbMemInst*    pShbMemInst;
tShbMemInst**   ppShbMemInst;
tShbMemHeader*  pShbMemHeader;
tShbError       ShbError;

    DEBUG_LVL_26_TRACE1("ShbIpcReleaseBuffer(%p)\n", pShbInstance_p);
    if (ShbTgtIsInterruptContext())
    {
        return (kShbInterruptContextNotAllowed);
    }

    if (pShbInstance_p == NULL)
    {
        return (kShbOk);
    }
    pShbMemInst   = ShbIpcGetShbMemInst   (pShbInstance_p);
    pShbMemHeader = ShbIpcGetShbMemHeader (pShbMemInst);

    ShbIpcStopSignalingNewData (pShbInstance_p);

    // remove ShbMemInst from JobReady process list if signaling
    ppShbMemInst = &pShbIpcProcessListJobReadyFirst_g;
    while (*ppShbMemInst != NULL)
    {
        if (*ppShbMemInst == pShbMemInst)
        {
            if (pShbMemInst->m_pProcessListJobReadyNext == NULL)
            {
                ShbIpcEnterAtomicSection(NULL);
                *ppShbMemInst = pShbMemInst->m_pProcessListJobReadyNext;
                ShbIpcLeaveAtomicSection(NULL);
            }
            else
            {
                *ppShbMemInst = pShbMemInst->m_pProcessListJobReadyNext;
            }
            if (ppShbIpcProcessListJobReadyCurrent_g == &pShbMemInst->m_pProcessListJobReadyNext)
            {
                ppShbIpcProcessListJobReadyCurrent_g = ppShbMemInst;
            }
            break;
        }
        ppShbMemInst = &(*ppShbMemInst)->m_pProcessListJobReadyNext;
    }

    if ( !--pShbMemHeader->m_ulRefCount )
    {
        ShbError = kShbOk;
        // delete mem table element
        ShbIpcDeleteListElement(pShbMemHeader->m_iBufferId);
        // delete shared mem
        free(pShbMemInst->m_pShbMemHeader);
    }
    else
    {
        ShbError = kShbMemUsedByOtherProcs;
    }
    //delete privat mem
    free(pShbMemInst);

    return (ShbError);
}