Changeset 9594


Ignore:
Timestamp:
Nov 27, 2009, 2:24:48 AM (13 years ago)
Author:
charles
Message:

(trunk libT) #2610 "avoid unnecessary calls to time(NULL)" -- fix new assertion error reported by John Clay and tstevens

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/session.c

    r9593 r9594  
    629629static void useAltSpeedTime( tr_session * session, tr_bool enabled, tr_bool byUser );
    630630
    631 static void
    632 onNowTimer( int foo UNUSED, short bar UNUSED, void * vsession )
    633 {
    634     struct timeval tv;
    635     tr_session * session = vsession;
    636 
    637     assert( tr_isSession( session ) );
    638     assert( session->nowTimer != NULL );
    639 
    640     /* schedule the next timer for right after the next second begins */
    641     gettimeofday( &tv, NULL );
    642     tr_timerAdd( session->nowTimer, 0, 1000000 - tv.tv_usec );
     631static void
     632onNowTimer( int foo UNUSED, short bar UNUSED, void * vsession )
     633{
     634    int usec;
     635    const int min = 100;
     636    const int max = 999999;
     637    struct timeval tv;
     638    tr_session * session = vsession;
     639
     640    assert( tr_isSession( session ) );
     641    assert( session->nowTimer != NULL );
     642
     643    /* schedule the next timer for right after the next second begins */
     644    gettimeofday( &tv, NULL );
     645    usec = 1000000 - tv.tv_usec;
     646    if( usec > max ) usec = max;
     647    if( usec < min ) usec = min;
     648    tr_timerAdd( session->nowTimer, 0, usec );
    643649    tr_timeUpdate( tv.tv_sec );
    644650    /* fprintf( stderr, "time %zu sec, %zu microsec\n", (size_t)tr_time(), (size_t)tv.tv_usec );  */
     
    663669    tr_bencMergeDicts( &settings, clientSettings );
    664670
    665     session->nowTimer = tr_new0( struct event, 1 ); 
    666     evtimer_set( session->nowTimer, onNowTimer, session ); 
     671    session->nowTimer = tr_new0( struct event, 1 );
     672    evtimer_set( session->nowTimer, onNowTimer, session );
    667673    onNowTimer( 0, 0, session );
    668674
Note: See TracChangeset for help on using the changeset viewer.