mirror of
https://github.com/transmission/transmission
synced 2025-03-12 15:14:12 +00:00
(libt) Fix tr_cacheFlushDone overrunning run_info
This commit is contained in:
parent
07e37057f2
commit
a42c86a701
1 changed files with 8 additions and 7 deletions
|
@ -118,8 +118,9 @@ enum
|
|||
};
|
||||
/* Calculte runs
|
||||
* - Stale runs, runs sitting in cache for a long time or runs not growing, get priority.
|
||||
* Returns number of runs.
|
||||
*/
|
||||
static void
|
||||
static int
|
||||
calcRuns( tr_cache * cache, struct run_info * runs )
|
||||
{
|
||||
const int n = tr_ptrArraySize( &cache->blocks );
|
||||
|
@ -146,9 +147,9 @@ calcRuns( tr_cache * cache, struct run_info * runs )
|
|||
//fprintf(stderr,"block run at pos %d of length %d and age %ld adjusted +%d\n",runs[i].pos,runs[i].len,now-runs[i].last_block_time,rank-runs[i].len);
|
||||
}
|
||||
|
||||
//fprintf( stderr, "%d block runs\n", i-1 );
|
||||
//fprintf( stderr, "%d block runs\n", i );
|
||||
qsort( runs, i, sizeof( struct run_info ), compareRuns );
|
||||
//return i;
|
||||
return i;
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -399,11 +400,11 @@ int tr_cacheFlushDone( tr_cache * cache )
|
|||
|
||||
if( tr_ptrArraySize( &cache->blocks ) > 0 )
|
||||
{
|
||||
struct run_info * runs = tr_new0( struct run_info, tr_ptrArraySize( &cache->blocks ) );
|
||||
int i = 0;
|
||||
struct run_info * runs = tr_new( struct run_info, tr_ptrArraySize( &cache->blocks ) );
|
||||
int i = 0, n;
|
||||
|
||||
calcRuns( cache, runs );
|
||||
while( runs[i].is_piece_done || runs[i].is_multi_piece )
|
||||
n = calcRuns( cache, runs );
|
||||
while( i < n && ( runs[i].is_piece_done || runs[i].is_multi_piece ) )
|
||||
runs[i++].rank |= SESSIONFLAG;
|
||||
err = flushRuns( cache, runs, i );
|
||||
tr_free( runs );
|
||||
|
|
Loading…
Add table
Reference in a new issue