mirror of
https://github.com/transmission/transmission
synced 2025-02-22 06:00:41 +00:00
code cleanup for tr_peerMgrTorrentAvailability().
1. move responsibility for getting a thread lock back to the public API fucntion, tr_torrentAvailability(). 2. if the torrent doesn't have metadata, stop after zeroing out the table 3. minor code formatting cleanup
This commit is contained in:
parent
7f01f0c3ee
commit
7ce0cf2322
2 changed files with 32 additions and 31 deletions
|
@ -2134,42 +2134,37 @@ tr_peerMgrRemoveTorrent( tr_torrent * tor )
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tr_peerMgrTorrentAvailability( const tr_torrent * tor,
|
tr_peerMgrTorrentAvailability( const tr_torrent * tor, int8_t * tab, unsigned int tabCount )
|
||||||
int8_t * tab,
|
|
||||||
unsigned int tabCount )
|
|
||||||
{
|
{
|
||||||
tr_piece_index_t i;
|
assert( tr_isTorrent( tor ) );
|
||||||
const Torrent * t;
|
assert( torrentIsLocked( tor->torrentPeers ) );
|
||||||
float interval;
|
assert( tab != NULL );
|
||||||
tr_bool isSeed;
|
assert( tabCount > 0 );
|
||||||
int peerCount;
|
|
||||||
const tr_peer ** peers;
|
|
||||||
tr_torrentLock( tor );
|
|
||||||
|
|
||||||
t = tor->torrentPeers;
|
|
||||||
tor = t->tor;
|
|
||||||
interval = tor->info.pieceCount / (float)tabCount;
|
|
||||||
isSeed = tor && ( tr_cpGetStatus ( &tor->completion ) == TR_SEED );
|
|
||||||
peers = (const tr_peer **) tr_ptrArrayBase( &t->peers );
|
|
||||||
peerCount = tr_ptrArraySize( &t->peers );
|
|
||||||
|
|
||||||
memset( tab, 0, tabCount );
|
memset( tab, 0, tabCount );
|
||||||
|
|
||||||
for( i = 0; tor && i < tabCount; ++i )
|
if( tr_torrentHasMetadata( tor ) )
|
||||||
{
|
{
|
||||||
const int piece = i * interval;
|
tr_piece_index_t i;
|
||||||
|
const int peerCount = tr_ptrArraySize( &tor->torrentPeers->peers );
|
||||||
|
const tr_peer ** peers = (const tr_peer**) tr_ptrArrayBase( &tor->torrentPeers->peers );
|
||||||
|
const float interval = tor->info.pieceCount / (float)tabCount;
|
||||||
|
const tr_bool isSeed = tr_cpGetStatus( &tor->completion ) == TR_SEED;
|
||||||
|
|
||||||
if( isSeed || tr_cpPieceIsComplete( &tor->completion, piece ) )
|
for( i=0; i<tabCount; ++i )
|
||||||
tab[i] = -1;
|
{
|
||||||
else if( peerCount ) {
|
const int piece = i * interval;
|
||||||
int j;
|
|
||||||
for( j = 0; j < peerCount; ++j )
|
if( isSeed || tr_cpPieceIsComplete( &tor->completion, piece ) )
|
||||||
if( tr_bitsetHas( &peers[j]->have, piece ) )
|
tab[i] = -1;
|
||||||
++tab[i];
|
else if( peerCount ) {
|
||||||
|
int j;
|
||||||
|
for( j=0; j<peerCount; ++j )
|
||||||
|
if( tr_bitsetHas( &peers[j]->have, piece ) )
|
||||||
|
++tab[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tr_torrentUnlock( tor );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns the pieces that are available from peers */
|
/* Returns the pieces that are available from peers */
|
||||||
|
|
|
@ -1437,11 +1437,17 @@ tr_torrentTrackersFree( tr_tracker_stat * trackers,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tr_torrentAvailability( const tr_torrent * tor,
|
tr_torrentAvailability( const tr_torrent * tor, int8_t * tab, int size )
|
||||||
int8_t * tab,
|
|
||||||
int size )
|
|
||||||
{
|
{
|
||||||
|
assert( tr_isTorrent( tor ) );
|
||||||
|
assert( tab != NULL );
|
||||||
|
assert( size > 0 );
|
||||||
|
|
||||||
|
tr_torrentLock( tor );
|
||||||
|
|
||||||
tr_peerMgrTorrentAvailability( tor, tab, size );
|
tr_peerMgrTorrentAvailability( tor, tab, size );
|
||||||
|
|
||||||
|
tr_torrentUnlock( tor );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue