From 91940d1c07aa7d9ae2d6707f1c65a9aec14af9e9 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 25 Feb 2009 13:04:51 +0000 Subject: [PATCH] (trunk libT) #1829: high CPU use in refillPiece() --- libtransmission/peer-mgr.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index 6db21acc3..8dfe8c0b1 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -705,6 +705,12 @@ blockIteratorNext( struct tr_blockIterator * i, tr_block_index_t * setme ) return found; } +static void +blockIteratorSkipCurrentPiece( struct tr_blockIterator * i ) +{ + i->blockIndex = i->blockCount; +} + static void blockIteratorFree( struct tr_blockIterator ** inout ) { @@ -812,7 +818,7 @@ refillPulse( void * vtorrent ) && (( hasNext = blockIteratorNext( t->refillQueue, &block ))) ) { int j; - int handled = FALSE; + tr_bool handled = FALSE; const tr_piece_index_t index = tr_torBlockPiece( tor, block ); const uint32_t offset = getBlockOffsetInPiece( tor, block ); @@ -867,6 +873,9 @@ refillPulse( void * vtorrent ) break; } } + + if( !handled ) + blockIteratorSkipCurrentPiece( t->refillQueue ); } /* cleanup */