openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/rsyslog/8.1903.0-r0/rsyslog-8.1903.0/runtime/tcpsrv.c
static rsRetVal processWorkset(tcpsrv_t* pThis, nspoll_t* pPoll, int numEntries,
                               nsd_epworkset_t workset[])
{
    int i;
    int origEntries = numEntries;
    DEFiRet;

    DBGPRINTF("tcpsrv: ready to process %d event entries\n", numEntries);

    while (numEntries > 0)
    {
        if (glbl.GetGlobalInputTermState() == 1)
            ABORT_FINALIZE(RS_RET_FORCE_TERM);
        if (numEntries == 1)
        {
            /* process self, save context switch */
            iRet = processWorksetItem(pThis, pPoll, workset[numEntries - 1].id,
                                      workset[numEntries - 1].pUsr);
        }
        else
        {
            pthread_mutex_lock(&wrkrMut);
            /* check if there is a free worker */
            for (i = 0; (i < wrkrMax) && ((wrkrInfo[i].pSrv != NULL) ||
                                          (wrkrInfo[i].enabled == 0));
                 ++i)
                /*do search*/;
            if (i < wrkrMax)
            {
                /* worker free -> use it! */
                wrkrInfo[i].pSrv = pThis;
                wrkrInfo[i].pPoll = pPoll;
                wrkrInfo[i].idx = workset[numEntries - 1].id;
                wrkrInfo[i].pUsr = workset[numEntries - 1].pUsr;
                /* Note: we must increment wrkrRunning HERE and not inside the
                 * worker's code. This is because a worker may actually never
                 * start, and thus increment wrkrRunning, before we finish and
                 * check the running worker count. We can only avoid this by
                 * incrementing it here.
                 */
                ++wrkrRunning;
                pthread_cond_signal(&wrkrInfo[i].run);
                pthread_mutex_unlock(&wrkrMut);
            }
            else
            {
                pthread_mutex_unlock(&wrkrMut);
                /* no free worker, so we process this one ourselfs */
                iRet =
                    processWorksetItem(pThis, pPoll, workset[numEntries - 1].id,
                                       workset[numEntries - 1].pUsr);
            }
        }
        --numEntries;
    }

    if (origEntries > 1)
    {
        /* we now need to wait until all workers finish. This is because the
         * rest of this module can not handle the concurrency introduced
         * by workers running during the epoll call.
         */
        pthread_mutex_lock(&wrkrMut);
        while (wrkrRunning > 0)
        {
            pthread_cond_wait(&wrkrIdle, &wrkrMut);
        }
        pthread_mutex_unlock(&wrkrMut);
    }

finalize_it:
    RETiRet;
}
/* Process a workset, that is handle io. We become activated
 * from either select or epoll handler. We split the workload
 * out to a pool of threads, but try to avoid context switches
 * as much as possible.
 */
Process a workset, that is handle io. We become activated
from either select or epoll handler. We split the workload
out to a pool of threads, but try to avoid context switches
as much as possible.
Process a workset that is handle io . We become activated from either select or epoll handler . We split the workload out to a pool of threads but try to avoid context switches as much as possible .
static rsRetVal processWorkset(tcpsrv_t* pThis, nspoll_t* pPoll, int numEntries,
                               nsd_epworkset_t workset[])
{
    int i;
    int origEntries = numEntries;
    DEFiRet;
    DBGPRINTF("tcpsrv: ready to process %d event entries\n", numEntries);
    while (numEntries > 0)
    {
        if (glbl.GetGlobalInputTermState() == 1)
            ABORT_FINALIZE(RS_RET_FORCE_TERM);
        if (numEntries == 1)
        {
            iRet = processWorksetItem(pThis, pPoll, workset[numEntries - 1].id,
                                      workset[numEntries - 1].pUsr);
        }
        else
        {
            pthread_mutex_lock(&wrkrMut);
            for (i = 0; (i < wrkrMax) && ((wrkrInfo[i].pSrv != NULL) ||
                                          (wrkrInfo[i].enabled == 0));
                 ++i)
                ;
            if (i < wrkrMax)
            {
                wrkrInfo[i].pSrv = pThis;
                wrkrInfo[i].pPoll = pPoll;
                wrkrInfo[i].idx = workset[numEntries - 1].id;
                wrkrInfo[i].pUsr = workset[numEntries - 1].pUsr;
                ++wrkrRunning;
                pthread_cond_signal(&wrkrInfo[i].run);
                pthread_mutex_unlock(&wrkrMut);
            }
            else
            {
                pthread_mutex_unlock(&wrkrMut);
                iRet =
                    processWorksetItem(pThis, pPoll, workset[numEntries - 1].id,
                                       workset[numEntries - 1].pUsr);
            }
        }
        --numEntries;
    }
    if (origEntries > 1)
    {
        pthread_mutex_lock(&wrkrMut);
        while (wrkrRunning > 0)
        {
            pthread_cond_wait(&wrkrIdle, &wrkrMut);
        }
        pthread_mutex_unlock(&wrkrMut);
    }
finalize_it:
    RETiRet;
}
static rsRetVal processWorkset ( tcpsrv_t * pThis , nspoll_t * pPoll , int numEntries , nsd_epworkset_t workset [ ] ) { int i ; int origEntries = numEntries ; DEFiRet ; DBGPRINTF ( " \n " , numEntries ) ; while ( numEntries > 0 ) { if ( glbl . GetGlobalInputTermState ( ) == 1 ) ABORT_FINALIZE ( RS_RET_FORCE_TERM ) ; if ( numEntries == 1 ) { iRet = processWorksetItem ( pThis , pPoll , workset [ numEntries - 1 ] . id , workset [ numEntries - 1 ] . pUsr ) ; } else { pthread_mutex_lock ( & wrkrMut ) ; for ( i = 0 ; ( i < wrkrMax ) && ( ( wrkrInfo [ i ] . pSrv != NULL ) || ( wrkrInfo [ i ] . enabled == 0 ) ) ; ++ i ) ; if ( i < wrkrMax ) { wrkrInfo [ i ] . pSrv = pThis ; wrkrInfo [ i ] . pPoll = pPoll ; wrkrInfo [ i ] . idx = workset [ numEntries - 1 ] . id ; wrkrInfo [ i ] . pUsr = workset [ numEntries - 1 ] . pUsr ; ++ wrkrRunning ; pthread_cond_signal ( & wrkrInfo [ i ] . run ) ; pthread_mutex_unlock ( & wrkrMut ) ; } else { pthread_mutex_unlock ( & wrkrMut ) ; iRet = processWorksetItem ( pThis , pPoll , workset [ numEntries - 1 ] . id , workset [ numEntries - 1 ] . pUsr ) ; } } -- numEntries ; } if ( origEntries > 1 ) { pthread_mutex_lock ( & wrkrMut ) ; while ( wrkrRunning > 0 ) { pthread_cond_wait ( & wrkrIdle , & wrkrMut ) ; } pthread_mutex_unlock ( & wrkrMut ) ; } finalize_it : RETiRet ; }
Process a workset, that is handle io.
Process a workset that is handle io .
/* process self, save context switch */ /* check if there is a free worker */ /*do search*/ /* worker free -> use it! */ /* Note: we must increment wrkrRunning HERE and not inside the
                 * worker's code. This is because a worker may actually never
                 * start, and thus increment wrkrRunning, before we finish and
                 * check the running worker count. We can only avoid this by
                 * incrementing it here.
                 */ /* no free worker, so we process this one ourselfs */ /* we now need to wait until all workers finish. This is because the
         * rest of this module can not handle the concurrency introduced
         * by workers running during the epoll call.
         */