Example #1
0
void
CTimer::Update()
{
    char *p0;
    struct tm *tm;
    time_t mlSec;
    uint32_t muMSec;
    CTimeValue *tp;
    struct timeval tv;
    struct timezone tz;


    if ( !MINA_TRYLOCK(&this->muLock) )
    {
        return;
    }

    gettimeofday(&tv, &tz);

    mlSec = tv.tv_sec;
    muMSec = tv.tv_usec / TIME_MSEC;

    this->moTime.Set(mlSec * TIME_SEC + tv.tv_usec * TIME_USEC, TIME_NSEC);

    tp = &this->moCacheTimes[muSlot];

    if (tp->Sec() == mlSec)
    {
        tp->Msec(muMSec);
        MINA_UNLOCK(&this->muLock);
        return;
    }

    if (muSlot == TIME_SLOTS - 1)
    {
        muSlot = 0;
    }
    else
    {
        muSlot++;
    }

    tp = &this->moCacheTimes[muSlot];
    tp->Sec(mlSec);
    tp->Msec(muMSec);

    p0 = &maacFormatTimes[muSlot][0];

    tm = gmtime(&mlSec);
    strftime(p0, FORM_TIME_LEN, "%Y-%m-%d %H:%M:%S", tm);

    this->mpoCacheTime = tp;
    this->mpcFormatTime = p0;

    MINA_UNLOCK(&this->muLock);


}