Changeset 7578


Ignore:
Timestamp:
Jan 2, 2009, 5:01:55 PM (12 years ago)
Author:
charles
Message:

(trunk libT) avoid some unnecessary memory fragmentation... for composited objects that have a tr_completion, contain the it directly rather than a pointer to one allocated elsewhere on the heap.

Location:
trunk/libtransmission
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/completion.c

    r7576 r7578  
    3131#include "utils.h"
    3232
    33 struct tr_completion
    34 {
    35     tr_bool  sizeWhenDoneIsDirty;
    36     tr_bool  haveValidIsDirty;
    37 
    38     tr_torrent *    tor;
    39 
    40     /* do we have this block? */
    41     tr_bitfield    blockBitfield;
    42 
    43     /* do we have this piece? */
    44     tr_bitfield    pieceBitfield;
    45 
    46     /* a block is complete if and only if we have it */
    47     uint16_t *  completeBlocks;
    48 
    49     /* number of bytes we'll have when done downloading. [0..info.totalSize]
    50        DON'T access this directly; it's a lazy field.
    51        use tr_cpSizeWhenDone() instead! */
    52     uint64_t    sizeWhenDoneLazy;
    53 
    54     /* number of bytes we'll have when done downloading. [0..info.totalSize]
    55        DON'T access this directly; it's a lazy field.
    56        use tr_cpHaveValid() instead! */
    57     uint64_t    haveValidLazy;
    58 
    59     /* number of bytes we want or have now. [0..sizeWhenDone] */
    60     uint64_t    sizeNow;
    61 };
    62 
    6333static void
    6434tr_cpReset( tr_completion * cp )
     
    7444
    7545tr_completion *
    76 tr_cpInit( tr_torrent * tor )
    77 {
    78     tr_completion * cp  = tr_new( tr_completion, 1 );
    79 
    80     cp->tor             = tor;
     46tr_cpConstruct( tr_completion * cp, tr_torrent * tor )
     47{
     48    cp->tor = tor;
    8149    cp->completeBlocks  = tr_new( uint16_t, tor->info.pieceCount );
    8250    tr_bitfieldConstruct( &cp->blockBitfield, tor->blockCount );
     
    8654}
    8755
    88 void
    89 tr_cpClose( tr_completion * cp )
     56tr_completion*
     57tr_cpDestruct( tr_completion * cp )
    9058{
    9159    tr_free( cp->completeBlocks );
    9260    tr_bitfieldDestruct( &cp->pieceBitfield );
    9361    tr_bitfieldDestruct( &cp->blockBitfield );
    94     tr_free        ( cp );
     62    return cp;
    9563}
    9664
     
    146114}
    147115
    148 int
    149 tr_cpPieceIsComplete( const tr_completion * cp,
    150                       tr_piece_index_t      piece )
    151 {
    152     return cp->completeBlocks[piece] == tr_torPieceCountBlocks( cp->tor, piece );
    153 }
    154 
    155 const tr_bitfield *
    156 tr_cpPieceBitfield( const tr_completion * cp )
    157 {
    158     return &cp->pieceBitfield;
    159 }
    160 
    161116void
    162117tr_cpPieceAdd( tr_completion *  cp,
     
    198153}
    199154
    200 int
    201 tr_cpBlockIsComplete( const tr_completion * cp,
    202                       tr_block_index_t      block )
    203 {
    204     return tr_bitfieldHas( &cp->blockBitfield, block );
    205 }
    206 
    207155void
    208156tr_cpBlockAdd( tr_completion *  cp,
     
    229177        cp->sizeWhenDoneIsDirty = 1;
    230178    }
    231 }
    232 
    233 const tr_bitfield *
    234 tr_cpBlockBitfield( const tr_completion * cp )
    235 {
    236     assert( cp );
    237     assert( cp->blockBitfield.bits );
    238     assert( cp->blockBitfield.bitCount );
    239 
    240     return &cp->blockBitfield;
    241179}
    242180
     
    263201}
    264202
    265 int
    266 tr_cpMissingBlocksInPiece( const tr_completion * cp,
    267                            tr_piece_index_t      piece )
    268 {
    269     return tr_torPieceCountBlocks( cp->tor, piece ) - cp->completeBlocks[piece];
    270 }
    271 
    272203/***
    273204****
    274205***/
    275 
    276 float
    277 tr_cpPercentDone( const tr_completion * cp )
    278 {
    279     return tr_getRatio( cp->sizeNow, tr_cpSizeWhenDone( cp ) );
    280 }
    281 
    282 float
    283 tr_cpPercentComplete( const tr_completion * cp )
    284 {
    285     return tr_getRatio( cp->sizeNow, cp->tor->info.totalSize );
    286 }
    287 
    288 uint64_t
    289 tr_cpLeftUntilDone( const tr_completion * cp )
    290 {
    291     return tr_cpSizeWhenDone( cp ) - cp->sizeNow;
    292 }
    293 
    294 uint64_t
    295 tr_cpLeftUntilComplete( const tr_completion * cp )
    296 {
    297     return cp->tor->info.totalSize - cp->sizeNow;
    298 }
    299206
    300207tr_completeness
     
    339246}
    340247
    341 uint64_t
    342 tr_cpHaveTotal( const tr_completion * cp )
    343 {
    344     return cp->sizeNow;
    345 }
    346 
    347248void
    348249tr_cpGetAmountDone( const tr_completion * cp,
     
    353254    const tr_torrent * tor = cp->tor;
    354255    const float        interval = tor->info.pieceCount / (float)tabCount;
    355     const int          isSeed = tr_cpGetStatus ( tor->completion ) == TR_SEED;
     256    const int          isSeed = tr_cpGetStatus( cp ) == TR_SEED;
    356257
    357258    for( i = 0; i < tabCount; ++i )
     
    368269    }
    369270}
     271
     272int
     273tr_cpMissingBlocksInPiece( const tr_completion * cp, tr_piece_index_t piece )
     274{
     275    return tr_torPieceCountBlocks( cp->tor, piece ) - cp->completeBlocks[piece];
     276}
     277
     278
     279int
     280tr_cpPieceIsComplete( const tr_completion * cp, tr_piece_index_t piece )
     281{
     282    return cp->completeBlocks[piece] == tr_torPieceCountBlocks( cp->tor, piece );
     283}
  • trunk/libtransmission/completion.h

    r7576 r7578  
    3030#endif
    3131
     32#include <assert.h>
     33
    3234#include "transmission.h"
     35#include "utils.h" /* tr_bitfield */
    3336
    34 struct tr_bitfield;
    35 typedef struct tr_completion tr_completion;
     37typedef struct tr_completion
     38{
     39    tr_bool  sizeWhenDoneIsDirty;
     40    tr_bool  haveValidIsDirty;
    3641
    37 tr_completion *            tr_cpInit( tr_torrent * );
     42    tr_torrent *    tor;
    3843
    39 void                       tr_cpClose( tr_completion * );
     44    /* do we have this block? */
     45    tr_bitfield    blockBitfield;
    4046
    41 /* General */
     47    /* do we have this piece? */
     48    tr_bitfield    pieceBitfield;
     49
     50    /* a block is complete if and only if we have it */
     51    uint16_t *  completeBlocks;
     52
     53    /* number of bytes we'll have when done downloading. [0..info.totalSize]
     54       DON'T access this directly; it's a lazy field.
     55       use tr_cpSizeWhenDone() instead! */
     56    uint64_t    sizeWhenDoneLazy;
     57
     58    /* number of bytes we'll have when done downloading. [0..info.totalSize]
     59       DON'T access this directly; it's a lazy field.
     60       use tr_cpHaveValid() instead! */
     61    uint64_t    haveValidLazy;
     62
     63    /* number of bytes we want or have now. [0..sizeWhenDone] */
     64    uint64_t    sizeNow;
     65}
     66tr_completion;
     67
     68/**
     69*** Life Cycle
     70**/
     71
     72tr_completion * tr_cpConstruct( tr_completion *, tr_torrent * );
     73
     74tr_completion * tr_cpDestruct( tr_completion * );
     75
     76static inline tr_completion* tr_cpNew( tr_torrent * tor )
     77{
     78    return tr_cpConstruct( tr_new0( tr_completion, 1 ), tor );
     79}
     80
     81static inline void tr_cpFree( tr_completion * cp )
     82{
     83    tr_free( tr_cpDestruct( cp ) );
     84}
     85
     86/**
     87*** General
     88**/
    4289
    4390tr_completeness            tr_cpGetStatus( const tr_completion * );
    4491
    45 extern inline uint64_t     tr_cpHaveTotal( const tr_completion * );
    46 
    4792uint64_t                   tr_cpHaveValid( const tr_completion * );
    4893
    49 extern inline uint64_t     tr_cpLeftUntilComplete( const tr_completion * );
    50 
    51 extern inline uint64_t     tr_cpLeftUntilDone( const tr_completion * );
    52 
    5394uint64_t                   tr_cpSizeWhenDone( const tr_completion * );
    54 
    55 extern inline float        tr_cpPercentComplete( const tr_completion * );
    56 
    57 extern inline float        tr_cpPercentDone( const tr_completion * );
    5895
    5996void                       tr_cpInvalidateDND( tr_completion * );
     
    63100                                               int                     tabCount );
    64101
    65 /* Pieces */
    66 extern inline int          tr_cpPieceIsComplete( const tr_completion * completion,
    67                                                  tr_piece_index_t      piece );
     102static inline uint64_t tr_cpHaveTotal( const tr_completion * cp )
     103{
     104    return cp->sizeNow;
     105}
    68106
    69 void                       tr_cpPieceAdd( tr_completion    * completion,
    70                                           tr_piece_index_t   piece );
     107static inline uint64_t tr_cpLeftUntilComplete( const tr_completion * cp )
     108{
     109    return tr_torrentInfo(cp->tor)->totalSize - cp->sizeNow;
     110}
    71111
    72 void                       tr_cpPieceRem( tr_completion     * completion,
    73                                            tr_piece_index_t   piece );
     112static inline uint64_t tr_cpLeftUntilDone( const tr_completion * cp )
     113{
     114    return tr_cpSizeWhenDone( cp ) - cp->sizeNow;
     115}
    74116
    75 /* Blocks */
    76 extern inline int          tr_cpBlockIsComplete( const tr_completion * completion,
    77                                                  tr_block_index_t block );
     117static inline float tr_cpPercentComplete( const tr_completion * cp )
     118{
     119    return tr_getRatio( cp->sizeNow, tr_torrentInfo(cp->tor)->totalSize );
     120}
     121
     122static inline float tr_cpPercentDone( const tr_completion * cp )
     123{
     124    return tr_getRatio( cp->sizeNow, tr_cpSizeWhenDone( cp ) );
     125}
     126
     127/**
     128*** Pieces
     129**/
     130
     131int tr_cpMissingBlocksInPiece( const tr_completion  * cp,
     132                               tr_piece_index_t       piece );
     133
     134int    tr_cpPieceIsComplete( const tr_completion * cp,
     135                             tr_piece_index_t      piece );
     136
     137void   tr_cpPieceAdd( tr_completion    * completion,
     138                      tr_piece_index_t   piece );
     139
     140void   tr_cpPieceRem( tr_completion     * completion,
     141                      tr_piece_index_t   piece );
     142
     143/**
     144*** Blocks
     145**/
     146
     147static inline int tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t block ) {
     148    return tr_bitfieldHas( &cp->blockBitfield, block );
     149}
    78150
    79151void                       tr_cpBlockAdd( tr_completion * completion,
     
    83155                                                  struct tr_bitfield * blocks );
    84156
    85 extern inline int          tr_cpMissingBlocksInPiece( const tr_completion  * completion,
    86                                                       tr_piece_index_t       piece );
     157/***
     158****
     159***/
    87160
     161static inline const struct tr_bitfield * tr_cpPieceBitfield( const tr_completion * cp ) {
     162    return &cp->pieceBitfield;
     163}
    88164
    89 extern inline const struct tr_bitfield *
    90                            tr_cpPieceBitfield( const tr_completion* );
    91 
    92 extern inline const struct tr_bitfield *
    93                            tr_cpBlockBitfield( const tr_completion * );
     165static inline const struct tr_bitfield * tr_cpBlockBitfield( const tr_completion * cp ) {
     166    assert( cp );
     167    assert( cp->blockBitfield.bits );
     168    assert( cp->blockBitfield.bitCount );
     169    return &cp->blockBitfield;
     170}
    94171
    95172#endif
  • trunk/libtransmission/fastresume.c

    r7567 r7578  
    283283        bitfield.bitCount = bitfield.byteCount * 8;
    284284        bitfield.bits = (uint8_t*) walk;
    285         if( tr_cpBlockBitfieldSet( tor->completion, &bitfield ) )
     285        if( tr_cpBlockBitfieldSet( &tor->completion, &bitfield ) )
    286286            ret = TR_FR_PROGRESS;
    287287        else {
     
    297297        for( i = 0; i < tor->info.pieceCount; ++i )
    298298            if( !tr_torrentIsPieceChecked( tor, i ) )
    299                 tr_cpPieceRem( tor->completion, i );
     299                tr_cpPieceRem( &tor->completion, i );
    300300    }
    301301
  • trunk/libtransmission/peer-mgr.c

    r7566 r7578  
    629629    for( i = 0; i < inf->pieceCount; ++i )
    630630        if( !tor->info.pieces[i].dnd
    631                 && !tr_cpPieceIsComplete( tor->completion, i ) )
     631                && !tr_cpPieceIsComplete( &tor->completion, i ) )
    632632            pool[poolSize++] = i;
    633633
     
    650650            setme->pendingRequestCount = getPieceRequests( t, piece );
    651651            setme->missingBlockCount
    652                          = tr_cpMissingBlocksInPiece( tor->completion, piece );
     652                         = tr_cpMissingBlocksInPiece( &tor->completion, piece );
    653653
    654654            for( k = 0; k < peerCount; ++k )
     
    712712        i->blockIndex = 0;
    713713        for( block=b; block!=e; ++block )
    714             if( !tr_cpBlockIsComplete( tor->completion, block ) )
     714            if( !tr_cpBlockIsComplete( &tor->completion, block ) )
    715715                i->blocks[i->blockCount++] = block;
    716716    }
     
    10821082            tr_block_index_t block = _tr_block( tor, e->pieceIndex, e->offset );
    10831083
    1084             tr_cpBlockAdd( tor->completion, block );
     1084            tr_cpBlockAdd( &tor->completion, block );
    10851085            decrementPieceRequests( t, e->pieceIndex );
    10861086
    10871087            broadcastGotBlock( t, e->pieceIndex, e->offset, e->length );
    10881088
    1089             if( tr_cpPieceIsComplete( tor->completion, e->pieceIndex ) )
     1089            if( tr_cpPieceIsComplete( &tor->completion, e->pieceIndex ) )
    10901090            {
    10911091                const tr_piece_index_t p = e->pieceIndex;
     
    16641664    tor = t->tor;
    16651665    interval = tor->info.pieceCount / (float)tabCount;
    1666     isSeed = tor && ( tr_cpGetStatus ( tor->completion ) == TR_SEED );
     1666    isSeed = tor && ( tr_cpGetStatus ( &tor->completion ) == TR_SEED );
    16671667    peers = (const tr_peer **) TR_PTR_ARRAY_DATA( &t->peers );
    16681668    peerCount = TR_PTR_ARRAY_LENGTH( &t->peers );
     
    16741674        const int piece = i * interval;
    16751675
    1676         if( isSeed || tr_cpPieceIsComplete( tor->completion, piece ) )
     1676        if( isSeed || tr_cpPieceIsComplete( &tor->completion, piece ) )
    16771677            tab[i] = -1;
    16781678        else if( peerCount ) {
     
    20752075        if( atom->flags & ADDED_F_SEED_FLAG )
    20762076            peerHasEverything = TRUE;
    2077         else if( peer->progress < tr_cpPercentDone( tor->completion ) )
     2077        else if( peer->progress < tr_cpPercentDone( &tor->completion ) )
    20782078            peerHasEverything = FALSE;
    20792079        else {
    2080             tr_bitfield * tmp = tr_bitfieldDup( tr_cpPieceBitfield( tor->completion ) );
     2080            tr_bitfield * tmp = tr_bitfieldDup( tr_cpPieceBitfield( &tor->completion ) );
    20812081            tr_bitfieldDifference( tmp, peer->have );
    20822082            peerHasEverything = tr_bitfieldCountTrueBits( tmp ) == 0;
  • trunk/libtransmission/peer-msgs.c

    r7576 r7578  
    718718
    719719    return ( !torrent->info.pieces[piece].dnd )                 /* we want it */
    720           && ( !tr_cpPieceIsComplete( torrent->completion, piece ) ) /* !have */
     720          && ( !tr_cpPieceIsComplete( &torrent->completion, piece ) ) /* !have */
    721721          && ( tr_bitfieldHas( msgs->peer->have, piece ) );    /* peer has it */
    722722}
     
    738738
    739739    torrent = msgs->torrent;
    740     bitfield = tr_cpPieceBitfield( torrent->completion );
     740    bitfield = tr_cpPieceBitfield( &torrent->completion );
    741741
    742742    if( !msgs->peer->have )
     
    927927        /* don't ask for it if we've already got it... this block may have
    928928         * come in from a different peer after we cancelled a request for it */
    929         if( !tr_cpBlockIsComplete( msgs->torrent->completion, block ) )
     929        if( !tr_cpBlockIsComplete( &msgs->torrent->completion, block ) )
    930930        {
    931931            protocolSendRequest( msgs, &req );
     
    12921292    const tr_bool fext = tr_peerIoSupportsFEXT( msgs->peer->io );
    12931293    const int reqIsValid = requestIsValid( msgs, req );
    1294     const int clientHasPiece = reqIsValid && tr_cpPieceIsComplete( msgs->torrent->completion, req->index );
     1294    const int clientHasPiece = reqIsValid && tr_cpPieceIsComplete( &msgs->torrent->completion, req->index );
    12951295    const int peerIsChoked = msgs->peer->peerIsChoked;
    12961296
     
    16411641    **/
    16421642
    1643     if( tr_cpBlockIsComplete( tor->completion, block ) ) {
     1643    if( tr_cpBlockIsComplete( &tor->completion, block ) ) {
    16441644        dbgmsg( msgs, "we have this block already..." );
    16451645        clientGotUnwantedBlock( msgs, req );
     
    17531753    {
    17541754        if( requestIsValid( msgs, &req )
    1755             && tr_cpPieceIsComplete( msgs->torrent->completion, req.index ) )
     1755            && tr_cpPieceIsComplete( &msgs->torrent->completion, req.index ) )
    17561756        {
    17571757            int err;
     
    18501850    size_t            lazyCount = 0;
    18511851
    1852     field = tr_bitfieldDup( tr_cpPieceBitfield( msgs->torrent->completion ) );
     1852    field = tr_bitfieldDup( tr_cpPieceBitfield( &msgs->torrent->completion ) );
    18531853
    18541854    if( tr_sessionIsLazyBitfieldEnabled( msgs->session ) )
     
    18991899    const tr_bool fext = tr_peerIoSupportsFEXT( msgs->peer->io );
    19001900
    1901     if( fext && ( tr_cpGetStatus( msgs->torrent->completion ) == TR_SEED ) )
     1901    if( fext && ( tr_cpGetStatus( &msgs->torrent->completion ) == TR_SEED ) )
    19021902    {
    19031903        protocolSendHaveAll( msgs );
    19041904    }
    1905     else if( fext && ( tr_cpHaveValid( msgs->torrent->completion ) == 0 ) )
     1905    else if( fext && ( tr_cpHaveValid( &msgs->torrent->completion ) == 0 ) )
    19061906    {
    19071907        protocolSendHaveNone( msgs );
  • trunk/libtransmission/resume.c

    r7476 r7578  
    309309
    310310    /* add the bitfield */
    311     bitfield = tr_cpBlockBitfield( tor->completion );
     311    bitfield = tr_cpBlockBitfield( &tor->completion );
    312312    tr_bencDictAddRaw( p, KEY_PROGRESS_BITFIELD,
    313313                       bitfield->bits, bitfield->byteCount );
     
    377377            tmp.bitCount = tmp.byteCount * 8;
    378378            tmp.bits = (uint8_t*) raw;
    379             if( !tr_cpBlockBitfieldSet( tor->completion, &tmp ) )
     379            if( !tr_cpBlockBitfieldSet( &tor->completion, &tmp ) )
    380380            {
    381381                tr_torrentUncheck( tor );
  • trunk/libtransmission/torrent.c

    r7576 r7578  
    8888}
    8989
    90 tr_bool
    91 tr_torrentExists( const tr_session * session, const uint8_t *   torrentHash )
    92 {
    93     return tr_torrentFindFromHash( (tr_session*)session, torrentHash ) != NULL;
    94 }
    95 
    9690tr_torrent*
    9791tr_torrentFindFromHash( tr_session * session, const uint8_t * torrentHash )
     
    119113
    120114    return NULL;
    121 }
    122 
    123 /***
    124 ****  LOCKS
    125 ***/
    126 
    127 void
    128 tr_torrentLock( const tr_torrent * tor )
    129 {
    130     tr_globalLock( tor->session );
    131 }
    132 
    133 void
    134 tr_torrentUnlock( const tr_torrent * tor )
    135 {
    136     tr_globalUnlock( tor->session );
    137115}
    138116
     
    520498    assert( t == (uint64_t)tor->blockCount );
    521499
    522     tor->completion = tr_cpInit( tor );
     500    tr_cpConstruct( &tor->completion, tor );
    523501
    524502    tr_torrentInitFilePieces( tor );
     
    557535    }
    558536
    559     tor->completeness = tr_cpGetStatus( tor->completion );
     537    tor->completeness = tr_cpGetStatus( &tor->completion );
    560538
    561539    tor->tracker = tr_trackerNew( tor );
     
    803781    usableSeeds += tor->info.webseedCount;
    804782
    805     s->percentComplete = tr_cpPercentComplete ( tor->completion );
    806 
    807     s->percentDone = tr_cpPercentDone( tor->completion );
    808     s->leftUntilDone = tr_cpLeftUntilDone( tor->completion );
    809     s->sizeWhenDone = tr_cpSizeWhenDone( tor->completion );
     783    s->percentComplete = tr_cpPercentComplete ( &tor->completion );
     784
     785    s->percentDone   = tr_cpPercentDone  ( &tor->completion );
     786    s->leftUntilDone = tr_cpLeftUntilDone( &tor->completion );
     787    s->sizeWhenDone  = tr_cpSizeWhenDone ( &tor->completion );
    810788
    811789    s->recheckProgress = s->activity == TR_STATUS_CHECK
     
    825803    s->downloadedEver  = tor->downloadedCur + tor->downloadedPrev;
    826804    s->uploadedEver    = tor->uploadedCur   + tor->uploadedPrev;
    827     s->haveValid       = tr_cpHaveValid( tor->completion );
    828     s->haveUnchecked   = tr_cpHaveTotal( tor->completion ) - s->haveValid;
     805    s->haveValid       = tr_cpHaveValid( &tor->completion );
     806    s->haveUnchecked   = tr_cpHaveTotal( &tor->completion ) - s->haveValid;
    829807
    830808
     
    847825        for( i = 0; i < tor->info.pieceCount; ++i )
    848826            if( !tor->info.pieces[i].dnd && tr_bitfieldHas( peerPieces, i ) )
    849                 s->desiredAvailable += tr_cpMissingBlocksInPiece(
    850                     tor->completion, i );
     827                s->desiredAvailable += tr_cpMissingBlocksInPiece( &tor->completion, i );
    851828        s->desiredAvailable *= tor->blockSize;
    852829        tr_bitfieldFree( peerPieces );
     
    904881    if( firstBlock == lastBlock )
    905882    {
    906         if( tr_cpBlockIsComplete( tor->completion, firstBlock ) )
     883        if( tr_cpBlockIsComplete( &tor->completion, firstBlock ) )
    907884            haveBytes += lastBlockOffset + 1 - firstBlockOffset;
    908885    }
     
    911888        tr_block_index_t i;
    912889
    913         if( tr_cpBlockIsComplete( tor->completion, firstBlock ) )
     890        if( tr_cpBlockIsComplete( &tor->completion, firstBlock ) )
    914891            haveBytes += tor->blockSize - firstBlockOffset;
    915892
    916893        for( i = firstBlock + 1; i < lastBlock; ++i )
    917             if( tr_cpBlockIsComplete( tor->completion, i ) )
     894            if( tr_cpBlockIsComplete( &tor->completion, i ) )
    918895                haveBytes += tor->blockSize;
    919896
    920         if( tr_cpBlockIsComplete( tor->completion, lastBlock ) )
     897        if( tr_cpBlockIsComplete( &tor->completion, lastBlock ) )
    921898            haveBytes += lastBlockOffset + 1;
    922899    }
     
    1001978{
    1002979    tr_torrentLock( tor );
    1003     tr_cpGetAmountDone( tor->completion, tab, size );
     980    tr_cpGetAmountDone( &tor->completion, tab, size );
    1004981    tr_torrentUnlock( tor );
    1005982}
     
    10311008
    10321009    if( has )
    1033         tr_cpPieceAdd( tor->completion, pieceIndex );
     1010        tr_cpPieceAdd( &tor->completion, pieceIndex );
    10341011    else
    1035         tr_cpPieceRem( tor->completion, pieceIndex );
     1012        tr_cpPieceRem( &tor->completion, pieceIndex );
    10361013
    10371014    tr_torrentUnlock( tor );
     
    10561033    tr_peerMgrRemoveTorrent( session->peerMgr, tor->info.hash );
    10571034
    1058     tr_cpClose( tor->completion );
     1035    tr_cpDestruct( &tor->completion );
    10591036
    10601037    tr_rcClose( tor->swarmSpeed );
     
    11031080    *tor->errorString = '\0';
    11041081    tr_torrentResetTransferStats( tor );
    1105     tor->completeness = tr_cpGetStatus( tor->completion );
     1082    tor->completeness = tr_cpGetStatus( &tor->completion );
    11061083    tr_torrentSaveResume( tor );
    11071084    tor->startDate = time( NULL );
     
    13071284    tr_torrentLock( tor );
    13081285
    1309     completeness = tr_cpGetStatus( tor->completion );
     1286    completeness = tr_cpGetStatus( &tor->completion );
    13101287
    13111288    if( completeness != tor->completeness )
     
    15001477    for( i = 0; i < fileCount; ++i )
    15011478        setFileDND( tor, files[i], doDownload );
    1502     tr_cpInvalidateDND ( tor->completion );
     1479    tr_cpInvalidateDND ( &tor->completion );
    15031480
    15041481    tr_torrentUnlock( tor );
  • trunk/libtransmission/torrent.h

    r7576 r7578  
    2727#endif
    2828
    29 #include "utils.h" /* tr_bitfield */
    30 
    3129#ifndef TR_TORRENT_H
    3230#define TR_TORRENT_H 1
     31
     32#include "completion.h" /* tr_completion */
     33#include "session.h" /* tr_globalLock(), tr_globalUnlock() */
     34#include "utils.h" /* tr_bitfield */
    3335
    3436struct tr_bandwidth;
     
    6466                                   tr_bool          has );
    6567
    66 extern inline void
    67             tr_torrentLock( const tr_torrent * session );
    68 
    69 extern inline void
    70             tr_torrentUnlock( const tr_torrent * session );
    71 
    7268tr_bool     tr_torrentIsSeed( const tr_torrent * session );
    7369
    7470void        tr_torrentChangeMyPort( tr_torrent * session );
    75 
    76 extern inline tr_bool
    77             tr_torrentExists( const tr_session * session,
    78                               const uint8_t    * hash );
    7971
    8072tr_torrent* tr_torrentFindFromId( tr_session * session,
     
    184176    uint32_t                   blockCountInLastPiece;
    185177
    186     struct tr_completion *     completion;
     178    struct tr_completion       completion;
    187179
    188180    struct tr_bitfield         checkedPieces;
     
    262254}
    263255
     256static inline void
     257tr_torrentLock( const tr_torrent * tor )
     258{
     259    tr_globalLock( tor->session );
     260}
     261
     262static inline void
     263tr_torrentUnlock( const tr_torrent * tor )
     264{
     265    tr_globalUnlock( tor->session );
     266}
     267
     268static inline tr_bool
     269tr_torrentExists( const tr_session * session, const uint8_t *   torrentHash )
     270{
     271    return tr_torrentFindFromHash( (tr_session*)session, torrentHash ) != NULL;
     272}
     273
     274
    264275#endif
  • trunk/libtransmission/tracker.c

    r7541 r7578  
    768768                              torrent->downloadedCur,
    769769                              torrent->corruptCur,
    770                               tr_cpLeftUntilComplete( torrent->completion ),
     770                              tr_cpLeftUntilComplete( &torrent->completion ),
    771771                              numwant,
    772772                              t->key_param );
     
    794794    /* BEP 21: In order to tell the tracker that a peer is a partial seed, it MUST send
    795795     * an event=paused parameter in every announce while it is a partial seed. */
    796     if( tr_cpGetStatus( torrent->completion ) == TR_PARTIAL_SEED )
     796    if( tr_cpGetStatus( &torrent->completion ) == TR_PARTIAL_SEED )
    797797        reqtype = TR_REQ_PAUSED;
    798798
  • trunk/libtransmission/transmission.h

    r7576 r7578  
    827827 * tr_info.hashString.
    828828 */
    829 extern inline int tr_torrentId( const tr_torrent * torrent );
     829int tr_torrentId( const tr_torrent * torrent );
    830830
    831831/****
  • trunk/libtransmission/verify.c

    r7559 r7578  
    8787        else if( !tr_torrentIsPieceChecked( tor, i ) )
    8888        {
    89             const int wasComplete = tr_cpPieceIsComplete( tor->completion, i );
     89            const int wasComplete = tr_cpPieceIsComplete( &tor->completion, i );
    9090
    9191            if( tr_ioTestPiece( tor, i, buffer, buflen ) ) /* yay */
Note: See TracChangeset for help on using the changeset viewer.