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/stream.c
static void* asyncWriterThread(void* pPtr)
{
    int iDeq;
    struct timespec t;
    sbool bTimedOut = 0;
    strm_t* pThis = (strm_t*)pPtr;
    int err;
    uchar thrdName[256] = "rs:";
    ISOBJ_TYPE_assert(pThis, strm);

    ustrncpy(thrdName + 3, pThis->pszFName, sizeof(thrdName) - 4);
    dbgOutputTID((char*)thrdName);
#if defined(HAVE_PRCTL) && defined(PR_SET_NAME)
    if (prctl(PR_SET_NAME, (char*)thrdName, 0, 0, 0) != 0)
    {
        DBGPRINTF("prctl failed, not setting thread name for '%s'\n",
                  "stream writer");
    }
#endif

    d_pthread_mutex_lock(&pThis->mut);
    while (1)
    { /* loop broken inside */
        while (pThis->iCnt == 0)
        {
            DBGOPRINT((obj_t*)pThis,
                      "file %d(%s) asyncWriterThread new iteration, "
                      "iCnt %d, bTimedOut %d, iFlushInterval %d\n",
                      pThis->fd, getFileDebugName(pThis), pThis->iCnt,
                      bTimedOut, pThis->iFlushInterval);
            if (pThis->bStopWriter)
            {
                pthread_cond_broadcast(&pThis->isEmpty);
                d_pthread_mutex_unlock(&pThis->mut);
                goto finalize_it; /* break main loop */
            }
            if (bTimedOut && pThis->iBufPtr > 0)
            {
                /* if we timed out, we need to flush pending data */
                strmFlushInternal(pThis, 1);
                bTimedOut = 0;
                continue;
            }
            bTimedOut = 0;
            if (pThis->bDoTimedWait)
            {
                timeoutComp(&t, pThis->iFlushInterval *
                                    1000); /* 1000 *millisconds* */
                if ((err = pthread_cond_timedwait(&pThis->notEmpty, &pThis->mut,
                                                  &t)) != 0)
                {
                    DBGOPRINT((obj_t*)pThis,
                              "file %d(%s) asyncWriterThread timed out\n",
                              pThis->fd, getFileDebugName(pThis));
                    bTimedOut = 1; /* simulate in any case */
                    if (err != ETIMEDOUT)
                    {
                        char errStr[1024];
                        rs_strerror_r(err, errStr, sizeof(errStr));
                        DBGPRINTF(
                            "stream async writer timeout with error (%d): %s - "
                            "ignoring\n",
                            err, errStr);
                    }
                }
            }
            else
            {
                d_pthread_cond_wait(&pThis->notEmpty, &pThis->mut);
            }
        }

        DBGOPRINT((obj_t*)pThis,
                  "file %d(%s) asyncWriterThread awoken, "
                  "iCnt %d, bTimedOut %d\n",
                  pThis->fd, getFileDebugName(pThis), pThis->iCnt, bTimedOut);
        bTimedOut = 0; /* we may have timed out, but there *is* work to do... */

        iDeq = pThis->iDeq++ % STREAM_ASYNC_NUMBUFS;
        const int bFlush = (pThis->bFlushNow || bTimedOut) ? 1 : 0;
        pThis->bFlushNow = 0;

        /* now we can do the actual write in parallel */
        d_pthread_mutex_unlock(&pThis->mut);
        doWriteInternal(pThis, pThis->asyncBuf[iDeq].pBuf,
                        pThis->asyncBuf[iDeq].lenBuf, bFlush);
        // TODO: error check????? 2009-07-06
        d_pthread_mutex_lock(&pThis->mut);

        --pThis->iCnt;
        if (pThis->iCnt < STREAM_ASYNC_NUMBUFS)
        {
            pthread_cond_signal(&pThis->notFull);
            if (pThis->iCnt == 0)
                pthread_cond_broadcast(&pThis->isEmpty);
        }
    }
    /* Not reached */

finalize_it:
    return NULL; /* to keep pthreads happy */
}
/* This is the writer thread for asynchronous mode.
 * -- rgerhards, 2009-07-06
 */
This is the writer thread for asynchronous mode.
This is the writer thread for asynchronous mode .
static void* asyncWriterThread(void* pPtr)
{
    int iDeq;
    struct timespec t;
    sbool bTimedOut = 0;
    strm_t* pThis = (strm_t*)pPtr;
    int err;
    uchar thrdName[256] = "rs:";
    ISOBJ_TYPE_assert(pThis, strm);
    ustrncpy(thrdName + 3, pThis->pszFName, sizeof(thrdName) - 4);
    dbgOutputTID((char*)thrdName);
#if defined(HAVE_PRCTL) && defined(PR_SET_NAME)
    if (prctl(PR_SET_NAME, (char*)thrdName, 0, 0, 0) != 0)
    {
        DBGPRINTF("prctl failed, not setting thread name for '%s'\n",
                  "stream writer");
    }
#endif
    d_pthread_mutex_lock(&pThis->mut);
    while (1)
    { 
        while (pThis->iCnt == 0)
        {
            DBGOPRINT((obj_t*)pThis,
                      "file %d(%s) asyncWriterThread new iteration, "
                      "iCnt %d, bTimedOut %d, iFlushInterval %d\n",
                      pThis->fd, getFileDebugName(pThis), pThis->iCnt,
                      bTimedOut, pThis->iFlushInterval);
            if (pThis->bStopWriter)
            {
                pthread_cond_broadcast(&pThis->isEmpty);
                d_pthread_mutex_unlock(&pThis->mut);
                goto finalize_it; 
            }
            if (bTimedOut && pThis->iBufPtr > 0)
            {
                strmFlushInternal(pThis, 1);
                bTimedOut = 0;
                continue;
            }
            bTimedOut = 0;
            if (pThis->bDoTimedWait)
            {
                timeoutComp(&t, pThis->iFlushInterval *
                                    1000); 
                if ((err = pthread_cond_timedwait(&pThis->notEmpty, &pThis->mut,
                                                  &t)) != 0)
                {
                    DBGOPRINT((obj_t*)pThis,
                              "file %d(%s) asyncWriterThread timed out\n",
                              pThis->fd, getFileDebugName(pThis));
                    bTimedOut = 1; 
                    if (err != ETIMEDOUT)
                    {
                        char errStr[1024];
                        rs_strerror_r(err, errStr, sizeof(errStr));
                        DBGPRINTF(
                            "stream async writer timeout with error (%d): %s - "
                            "ignoring\n",
                            err, errStr);
                    }
                }
            }
            else
            {
                d_pthread_cond_wait(&pThis->notEmpty, &pThis->mut);
            }
        }
        DBGOPRINT((obj_t*)pThis,
                  "file %d(%s) asyncWriterThread awoken, "
                  "iCnt %d, bTimedOut %d\n",
                  pThis->fd, getFileDebugName(pThis), pThis->iCnt, bTimedOut);
        bTimedOut = 0; 
        iDeq = pThis->iDeq++ % STREAM_ASYNC_NUMBUFS;
        const int bFlush = (pThis->bFlushNow || bTimedOut) ? 1 : 0;
        pThis->bFlushNow = 0;
        d_pthread_mutex_unlock(&pThis->mut);
        doWriteInternal(pThis, pThis->asyncBuf[iDeq].pBuf,
                        pThis->asyncBuf[iDeq].lenBuf, bFlush);
        d_pthread_mutex_lock(&pThis->mut);
        --pThis->iCnt;
        if (pThis->iCnt < STREAM_ASYNC_NUMBUFS)
        {
            pthread_cond_signal(&pThis->notFull);
            if (pThis->iCnt == 0)
                pthread_cond_broadcast(&pThis->isEmpty);
        }
    }
finalize_it:
    return NULL; 
}
static void * asyncWriterThread ( void * pPtr ) { int iDeq ; struct timespec t ; sbool bTimedOut = 0 ; strm_t * pThis = ( strm_t * ) pPtr ; int err ; uchar thrdName [ 256 ] = " " ; ISOBJ_TYPE_assert ( pThis , strm ) ; ustrncpy ( thrdName + 3 , pThis -> pszFName , sizeof ( thrdName ) - 4 ) ; dbgOutputTID ( ( char * ) thrdName ) ; #if defined ( HAVE_PRCTL ) && defined ( PR_SET_NAME ) if ( prctl ( PR_SET_NAME , ( char * ) thrdName , 0 , 0 , 0 ) != 0 ) { DBGPRINTF ( " \n " , " " ) ; } #endif d_pthread_mutex_lock ( & pThis -> mut ) ; while ( 1 ) { while ( pThis -> iCnt == 0 ) { DBGOPRINT ( ( obj_t * ) pThis , " " " \n " , pThis -> fd , getFileDebugName ( pThis ) , pThis -> iCnt , bTimedOut , pThis -> iFlushInterval ) ; if ( pThis -> bStopWriter ) { pthread_cond_broadcast ( & pThis -> isEmpty ) ; d_pthread_mutex_unlock ( & pThis -> mut ) ; goto finalize_it ; } if ( bTimedOut && pThis -> iBufPtr > 0 ) { strmFlushInternal ( pThis , 1 ) ; bTimedOut = 0 ; continue ; } bTimedOut = 0 ; if ( pThis -> bDoTimedWait ) { timeoutComp ( & t , pThis -> iFlushInterval * 1000 ) ; if ( ( err = pthread_cond_timedwait ( & pThis -> notEmpty , & pThis -> mut , & t ) ) != 0 ) { DBGOPRINT ( ( obj_t * ) pThis , " \n " , pThis -> fd , getFileDebugName ( pThis ) ) ; bTimedOut = 1 ; if ( err != ETIMEDOUT ) { char errStr [ 1024 ] ; rs_strerror_r ( err , errStr , sizeof ( errStr ) ) ; DBGPRINTF ( " " " \n " , err , errStr ) ; } } } else { d_pthread_cond_wait ( & pThis -> notEmpty , & pThis -> mut ) ; } } DBGOPRINT ( ( obj_t * ) pThis , " " " \n " , pThis -> fd , getFileDebugName ( pThis ) , pThis -> iCnt , bTimedOut ) ; bTimedOut = 0 ; iDeq = pThis -> iDeq ++ % STREAM_ASYNC_NUMBUFS ; const int bFlush = ( pThis -> bFlushNow || bTimedOut ) ? 1 : 0 ; pThis -> bFlushNow = 0 ; d_pthread_mutex_unlock ( & pThis -> mut ) ; doWriteInternal ( pThis , pThis -> asyncBuf [ iDeq ] . pBuf , pThis -> asyncBuf [ iDeq ] . lenBuf , bFlush ) ; d_pthread_mutex_lock ( & pThis -> mut ) ; -- pThis -> iCnt ; if ( pThis -> iCnt < STREAM_ASYNC_NUMBUFS ) { pthread_cond_signal ( & pThis -> notFull ) ; if ( pThis -> iCnt == 0 ) pthread_cond_broadcast ( & pThis -> isEmpty ) ; } } finalize_it : return NULL ; }
This is the writer thread for asynchronous mode.
This is the writer thread for asynchronous mode .
/* loop broken inside */ /* break main loop */ /* if we timed out, we need to flush pending data */ /* 1000 *millisconds* */ /* simulate in any case */ /* we may have timed out, but there *is* work to do... */ /* now we can do the actual write in parallel */ // TODO: error check????? 2009-07-06 /* Not reached */ /* to keep pthreads happy */