(trunk libT) #2335: when verifying local data, pause a few msec between pieces to give the system some breathing room and other processes a shot at the disk IO

This commit is contained in:
Charles Kerr 2009-08-14 20:55:22 +00:00
parent 30bc1c6e7a
commit f7129f2f30
1 changed files with 11 additions and 0 deletions

View File

@ -46,6 +46,7 @@ verifyTorrent( tr_torrent * tor, tr_bool * stopFlag )
tr_bool changed = 0;
tr_bool hadPiece = 0;
uint32_t piecePos = 0;
uint32_t pieceBytesRead = 0;
tr_file_index_t fileIndex = 0;
tr_piece_index_t pieceIndex = 0;
const int64_t buflen = tor->info.pieceSize;
@ -89,6 +90,8 @@ verifyTorrent( tr_torrent * tor, tr_bool * stopFlag )
/* read a bit */
if( (fd>=0) && tr_lseek( fd, filePos, SEEK_SET ) != -1 ) {
const int64_t numRead = read( fd, buffer, bytesThisPass );
if( numRead > 0 )
pieceBytesRead += numRead;
if( numRead == bytesThisPass )
SHA1_Update( &sha, buffer, numRead );
}
@ -120,9 +123,17 @@ verifyTorrent( tr_torrent * tor, tr_bool * stopFlag )
tr_torrentSetPieceChecked( tor, pieceIndex, TRUE );
tor->anyDate = time( NULL );
/* going full-throttle on a verify can choke other processes'
* disk IO, so wait a fwe msec between pieces.
* The msec is arbitrary, and the "if" clause is to make sure we
* don't slow down verification of files that don't exist */
if( pieceBytesRead == tr_torPieceCountBytes( tor, pieceIndex ) )
tr_wait( 50 );
SHA1_Init( &sha );
++pieceIndex;
piecePos = 0;
pieceBytesRead = 0;
}
/* if we're finishing a file... */