Changeset 11783


Ignore:
Timestamp:
Jan 29, 2011, 6:59:23 PM (11 years ago)
Author:
jordan
Message:

(trunk libT) #3950 "use libevent's cached gettimeofday() value when appropriate" -- fixed.

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-io.c

    r11718 r11783  
    8787};
    8888
     89
    8990/***
    9091****
     
    100101        const unsigned int payload = MIN( next->length, bytes_transferred );
    101102        const unsigned int overhead = guessPacketOverhead( payload );
    102         const uint64_t now = tr_time_msec( );
     103        const uint64_t now = tr_sessionGetTimeMsec( io->session );
    103104
    104105        tr_bandwidthUsed( &io->bandwidth, TR_UP, payload, next->isPieceData, now );
     
    140141    if( io->canRead )
    141142    {
     143        const uint64_t now = tr_sessionGetTimeMsec( io->session );
     144
    142145        tr_sessionLock( session );
    143146
     
    149152            const size_t used = oldLen - evbuffer_get_length( io->inbuf );
    150153            const unsigned int overhead = guessPacketOverhead( used );
    151             const uint64_t now = tr_time_msec( );
    152154
    153155            assert( tr_isPeerIo( io ) );
  • trunk/libtransmission/peer-mgr.c

    r11709 r11783  
    27512751rechokePulse( int foo UNUSED, short bar UNUSED, void * vmgr )
    27522752{
    2753     uint64_t now;
    27542753    tr_torrent * tor = NULL;
    27552754    tr_peerMgr * mgr = vmgr;
     2755    const uint64_t now = tr_sessionGetTimeMsec( mgr->session );
     2756
    27562757    managerLock( mgr );
    27572758
    2758     now = tr_time_msec( );
    27592759    while(( tor = tr_torrentNext( mgr->session, tor ))) {
    27602760        if( tor->isRunning ) {
     
    31143114    tr_peerMgr * mgr = vmgr;
    31153115    const time_t now_sec = tr_time( );
    3116     const uint64_t now_msec = tr_time_msec( );
     3116    const uint64_t now_msec = tr_sessionGetTimeMsec( mgr->session );
    31173117
    31183118    /**
  • trunk/libtransmission/session.c

    r11781 r11783  
    25592559    session->curl_easy_config_func = func;
    25602560}
     2561
     2562/***
     2563****
     2564***/
     2565
     2566uint64_t
     2567tr_sessionGetTimeMsec( tr_session * session )
     2568{
     2569    struct timeval tv;
     2570
     2571    if( event_base_gettimeofday_cached( session->event_base, &tv ) )
     2572    {
     2573        return tr_time_msec( );
     2574    }
     2575    else
     2576    {
     2577        /* event_base_gettimeofday_cached() might be implemented using
     2578           clock_gettime(CLOCK_MONOTONIC), so calculate the offset to
     2579           real time... */
     2580        static uint64_t offset;
     2581        static tr_bool offset_calculated = FALSE;
     2582
     2583        const uint64_t val = (uint64_t) tv.tv_sec * 1000 + ( tv.tv_usec / 1000 );
     2584
     2585        if( !offset_calculated )
     2586        {
     2587            offset = tr_time_msec() - val;
     2588            offset_calculated = TRUE;
     2589        }
     2590
     2591        return val + offset;
     2592    }
     2593}
  • trunk/libtransmission/session.h

    r11709 r11783  
    306306
    307307
     308/**
     309 * Tries to use libevent's cached timeval so we can avoid excessive calls
     310 * to gettimeofday().
     311 *
     312 * This isn't for all uses, but should be reasonably accurate when called
     313 * near the beginning of a libevent callback.
     314 */
     315uint64_t tr_sessionGetTimeMsec( tr_session * session );
     316
     317
    308318#endif
Note: See TracChangeset for help on using the changeset viewer.