Changeset 11704


Ignore:
Timestamp:
Jan 18, 2011, 10:51:29 PM (11 years ago)
Author:
jordan
Message:

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
Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-mgr.c

    r11703 r11704  
    21352135
    21362136void
    2137 tr_peerMgrTorrentAvailability( const tr_torrent * tor,
    2138                                int8_t           * tab,
    2139                                unsigned int       tabCount )
    2140 {
    2141     tr_piece_index_t   i;
    2142     const Torrent *    t;
    2143     float              interval;
    2144     tr_bool            isSeed;
    2145     int                peerCount;
    2146     const tr_peer **   peers;
    2147     tr_torrentLock( tor );
    2148 
    2149     t = tor->torrentPeers;
    2150     tor = t->tor;
    2151     interval = tor->info.pieceCount / (float)tabCount;
    2152     isSeed = tor && ( tr_cpGetStatus ( &tor->completion ) == TR_SEED );
    2153     peers = (const tr_peer **) tr_ptrArrayBase( &t->peers );
    2154     peerCount = tr_ptrArraySize( &t->peers );
     2137tr_peerMgrTorrentAvailability( const tr_torrent * tor, int8_t * tab, unsigned int tabCount )
     2138{
     2139    assert( tr_isTorrent( tor ) );
     2140    assert( torrentIsLocked( tor->torrentPeers ) );
     2141    assert( tab != NULL );
     2142    assert( tabCount > 0 );
    21552143
    21562144    memset( tab, 0, tabCount );
    21572145
    2158     for( i = 0; tor && i < tabCount; ++i )
    2159     {
    2160         const int piece = i * interval;
    2161 
    2162         if( isSeed || tr_cpPieceIsComplete( &tor->completion, piece ) )
    2163             tab[i] = -1;
    2164         else if( peerCount ) {
    2165             int j;
    2166             for( j = 0; j < peerCount; ++j )
    2167                 if( tr_bitsetHas( &peers[j]->have, piece ) )
    2168                     ++tab[i];
    2169         }
    2170     }
    2171 
    2172     tr_torrentUnlock( tor );
     2146    if( tr_torrentHasMetadata( tor ) )
     2147    {
     2148        tr_piece_index_t i;
     2149        const int peerCount = tr_ptrArraySize( &tor->torrentPeers->peers );
     2150        const tr_peer ** peers = (const tr_peer**) tr_ptrArrayBase( &tor->torrentPeers->peers );
     2151        const float interval = tor->info.pieceCount / (float)tabCount;
     2152        const tr_bool isSeed = tr_cpGetStatus( &tor->completion ) == TR_SEED;
     2153
     2154        for( i=0; i<tabCount; ++i )
     2155        {
     2156            const int piece = i * interval;
     2157
     2158            if( isSeed || tr_cpPieceIsComplete( &tor->completion, piece ) )
     2159                tab[i] = -1;
     2160            else if( peerCount ) {
     2161                int j;
     2162                for( j=0; j<peerCount; ++j )
     2163                    if( tr_bitsetHas( &peers[j]->have, piece ) )
     2164                        ++tab[i];
     2165            }
     2166        }
     2167    }
    21732168}
    21742169
  • trunk/libtransmission/torrent.c

    r11696 r11704  
    14381438
    14391439void
    1440 tr_torrentAvailability( const tr_torrent * tor,
    1441                         int8_t *           tab,
    1442                         int                size )
    1443 {
     1440tr_torrentAvailability( const tr_torrent * tor, int8_t * tab, int size )
     1441{
     1442    assert( tr_isTorrent( tor ) );
     1443    assert( tab != NULL );
     1444    assert( size > 0 );
     1445
     1446    tr_torrentLock( tor );
     1447
    14441448    tr_peerMgrTorrentAvailability( tor, tab, size );
     1449
     1450    tr_torrentUnlock( tor );
    14451451}
    14461452
Note: See TracChangeset for help on using the changeset viewer.