1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-02-03 13:03:50 +00:00

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

This commit is contained in:
Charles Kerr 2009-11-27 02:24:48 +00:00
parent e1c6b792aa
commit d7d5bb6db7

View file

@ -628,18 +628,24 @@ tr_sessionInit( const char * tag,
static void useAltSpeed( tr_session * session, tr_bool enabled, tr_bool byUser );
static void useAltSpeedTime( tr_session * session, tr_bool enabled, tr_bool byUser );
static void
onNowTimer( int foo UNUSED, short bar UNUSED, void * vsession )
{
struct timeval tv;
tr_session * session = vsession;
static void
onNowTimer( int foo UNUSED, short bar UNUSED, void * vsession )
{
int usec;
const int min = 100;
const int max = 999999;
struct timeval tv;
tr_session * session = vsession;
assert( tr_isSession( session ) );
assert( session->nowTimer != NULL );
assert( tr_isSession( session ) );
assert( session->nowTimer != NULL );
/* schedule the next timer for right after the next second begins */
gettimeofday( &tv, NULL );
tr_timerAdd( session->nowTimer, 0, 1000000 - tv.tv_usec );
/* schedule the next timer for right after the next second begins */
gettimeofday( &tv, NULL );
usec = 1000000 - tv.tv_usec;
if( usec > max ) usec = max;
if( usec < min ) usec = min;
tr_timerAdd( session->nowTimer, 0, usec );
tr_timeUpdate( tv.tv_sec );
/* fprintf( stderr, "time %zu sec, %zu microsec\n", (size_t)tr_time(), (size_t)tv.tv_usec ); */
}
@ -662,8 +668,8 @@ tr_sessionInitImpl( void * vdata )
tr_sessionGetDefaultSettings( data->configDir, &settings );
tr_bencMergeDicts( &settings, clientSettings );
session->nowTimer = tr_new0( struct event, 1 );
evtimer_set( session->nowTimer, onNowTimer, session );
session->nowTimer = tr_new0( struct event, 1 );
evtimer_set( session->nowTimer, onNowTimer, session );
onNowTimer( 0, 0, session );
#ifndef WIN32