mirror of
https://github.com/transmission/transmission
synced 2025-02-03 21:12:05 +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:
parent
e1c6b792aa
commit
d7d5bb6db7
1 changed files with 18 additions and 12 deletions
|
@ -631,6 +631,9 @@ static void useAltSpeedTime( tr_session * session, tr_bool enabled, tr_bool byUs
|
||||||
static void
|
static void
|
||||||
onNowTimer( int foo UNUSED, short bar UNUSED, void * vsession )
|
onNowTimer( int foo UNUSED, short bar UNUSED, void * vsession )
|
||||||
{
|
{
|
||||||
|
int usec;
|
||||||
|
const int min = 100;
|
||||||
|
const int max = 999999;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
tr_session * session = vsession;
|
tr_session * session = vsession;
|
||||||
|
|
||||||
|
@ -639,7 +642,10 @@ onNowTimer( int foo UNUSED, short bar UNUSED, void * vsession )
|
||||||
|
|
||||||
/* schedule the next timer for right after the next second begins */
|
/* schedule the next timer for right after the next second begins */
|
||||||
gettimeofday( &tv, NULL );
|
gettimeofday( &tv, NULL );
|
||||||
tr_timerAdd( session->nowTimer, 0, 1000000 - tv.tv_usec );
|
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 );
|
tr_timeUpdate( tv.tv_sec );
|
||||||
/* fprintf( stderr, "time %zu sec, %zu microsec\n", (size_t)tr_time(), (size_t)tv.tv_usec ); */
|
/* fprintf( stderr, "time %zu sec, %zu microsec\n", (size_t)tr_time(), (size_t)tv.tv_usec ); */
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue