Ignore:
Timestamp:
Mar 28, 2011, 4:31:05 PM (11 years ago)
Author:
jordan
Message:

(trunk libT) break the mac build and introduce new crashes.

This is partially to address #4145 "Downloads stuck at 100%" by refactoring the bitset, bitfield, and tr_completion; however, the ripple effect is larger than usual so things may get worse in the short term before getting better.

livings124: to fix the mac build, remove bitset.[ch] from xcode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/completion.h

    r12204 r12248  
    1818#define TR_COMPLETION_H
    1919
    20 #include <assert.h>
    21 
    2220#include "transmission.h"
    23 #include "bitset.h"
     21#include "bitfield.h"
    2422#include "utils.h" /* tr_getRatio() */
    2523
    2624typedef struct tr_completion
    2725{
    28     bool  sizeWhenDoneIsDirty;
    29     bool  blocksWantedIsDirty;
    30     bool  haveValidIsDirty;
    31 
    32     tr_torrent *    tor;
     26    tr_torrent * tor;
    3327
    3428    /* do we have this block? */
    35     tr_bitset    blockBitset;
    36 
    37     /* a block is complete if and only if we have it */
    38     uint16_t *  completeBlocks;
    39 
    40     /* total number of blocks that we want downloaded
    41        DON'T access this directly; it's a lazy field.
    42        Used by tr_cpBlocksMissing(). */
    43     tr_block_index_t    blocksWantedLazy;
    44 
    45     /* total number of completed blocks that we want downloaded
    46        DON'T access this directly; it's a lazy field.
    47        Used by tr_cpBlocksMissing(). */
    48     tr_block_index_t    blocksWantedCompleteLazy;
     29    tr_bitfield blockBitfield;
    4930
    5031    /* number of bytes we'll have when done downloading. [0..info.totalSize]
    5132       DON'T access this directly; it's a lazy field.
    5233       use tr_cpSizeWhenDone() instead! */
    53     uint64_t    sizeWhenDoneLazy;
     34    uint64_t sizeWhenDoneLazy;
     35
     36    /* whether or not sizeWhenDone needs to be recalculated */
     37    bool sizeWhenDoneIsDirty;
    5438
    5539    /* number of bytes we'll have when done downloading. [0..info.totalSize]
    5640       DON'T access this directly; it's a lazy field.
    5741       use tr_cpHaveValid() instead! */
    58     uint64_t    haveValidLazy;
     42    uint64_t haveValidLazy;
     43
     44    /* whether or not haveValidLazy needs to be recalculated */
     45    bool haveValidIsDirty;
    5946
    6047    /* number of bytes we want or have now. [0..sizeWhenDone] */
    61     uint64_t    sizeNow;
     48    uint64_t sizeNow;
    6249}
    6350tr_completion;
     
    6754**/
    6855
    69 tr_completion * tr_cpConstruct( tr_completion *, tr_torrent * );
     56void              tr_cpConstruct( tr_completion *, tr_torrent * );
    7057
    71 tr_completion * tr_cpDestruct( tr_completion * );
     58void              tr_cpDestruct( tr_completion * );
    7259
    7360/**
     
    7562**/
    7663
    77 tr_completeness    tr_cpGetStatus( const tr_completion * );
     64double            tr_cpPercentComplete( const tr_completion * cp );
    7865
    79 uint64_t           tr_cpHaveValid( const tr_completion * );
     66double            tr_cpPercentDone( const tr_completion * cp );
    8067
    81 tr_block_index_t   tr_cpBlocksMissing( const tr_completion * );
     68tr_completeness   tr_cpGetStatus( const tr_completion * );
    8269
    83 uint64_t           tr_cpSizeWhenDone( const tr_completion * );
     70uint64_t          tr_cpHaveValid( const tr_completion * );
    8471
    85 void               tr_cpInvalidateDND( tr_completion * );
     72uint64_t          tr_cpSizeWhenDone( const tr_completion * );
    8673
    87 void               tr_cpGetAmountDone( const   tr_completion * completion,
    88                                        float                 * tab,
    89                                        int                     tabCount );
     74uint64_t          tr_cpLeftUntilComplete( const tr_completion * );
     75
     76uint64_t          tr_cpLeftUntilDone( const tr_completion * );
     77
     78void              tr_cpGetAmountDone( const   tr_completion * completion,
     79                                      float                 * tab,
     80                                      int                     tabCount );
     81
     82static inline bool tr_cpHasAll( const tr_completion * cp )
     83{
     84    return tr_bitfieldHasAll( &cp->blockBitfield );
     85}
     86
     87static inline bool tr_cpHasNone( const tr_completion * cp )
     88{
     89    return tr_bitfieldHasNone( &cp->blockBitfield );
     90}
    9091
    9192static inline uint64_t tr_cpHaveTotal( const tr_completion * cp )
     
    9495}
    9596
    96 static inline uint64_t tr_cpLeftUntilComplete( const tr_completion * cp )
    97 {
    98     return tr_torrentInfo(cp->tor)->totalSize - cp->sizeNow;
    99 }
    100 
    101 static inline uint64_t tr_cpLeftUntilDone( const tr_completion * cp )
    102 {
    103     return tr_cpSizeWhenDone( cp ) - cp->sizeNow;
    104 }
    105 
    106 static inline double tr_cpPercentComplete( const tr_completion * cp )
    107 {
    108     const double ratio = tr_getRatio( cp->sizeNow, tr_torrentInfo(cp->tor)->totalSize );
    109     if( (int)ratio == TR_RATIO_NA )
    110         return 0.0;
    111     else if( (int)ratio == TR_RATIO_INF )
    112         return 1.0;
    113     else
    114         return ratio;
    115 }
    116 
    117 static inline double tr_cpPercentDone( const tr_completion * cp )
    118 {
    119     const double ratio = tr_getRatio( cp->sizeNow, tr_cpSizeWhenDone( cp ) );
    120     const int iratio = (int)ratio;
    121     return ((iratio == TR_RATIO_NA) || (iratio == TR_RATIO_INF)) ? 0.0 : ratio;
    122 }
    123 
    12497/**
    125 *** Pieces
     98***  Pieces
    12699**/
    127100
    128 int tr_cpMissingBlocksInPiece( const tr_completion * cp, tr_piece_index_t i );
     101void    tr_cpPieceAdd( tr_completion * cp, tr_piece_index_t i );
     102
     103void    tr_cpPieceRem( tr_completion * cp, tr_piece_index_t i );
     104
     105size_t  tr_cpMissingBlocksInPiece( const tr_completion *, tr_piece_index_t );
     106
     107size_t  tr_cpMissingBytesInPiece ( const tr_completion *, tr_piece_index_t );
    129108
    130109static inline bool
     
    134113}
    135114
    136 void tr_cpPieceAdd( tr_completion * cp, tr_piece_index_t i );
    137 
    138 void tr_cpPieceRem( tr_completion * cp, tr_piece_index_t i );
    139 
    140 bool tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t );
    141 
    142115/**
    143 *** Blocks
     116***  Blocks
    144117**/
    145118
     
    147120tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t i )
    148121{
    149     return tr_bitsetHas( &cp->blockBitset, i );
     122    return tr_bitfieldHas( &cp->blockBitfield, i );
    150123}
    151124
    152 void tr_cpBlockAdd( tr_completion * cp, tr_block_index_t i );
     125void  tr_cpBlockAdd( tr_completion * cp, tr_block_index_t i );
    153126
    154 bool tr_cpBlockBitsetInit( tr_completion * cp, const tr_bitset * blocks );
     127bool  tr_cpBlockInit( tr_completion * cp, const tr_bitfield * blocks );
    155128
    156129/***
    157 ****
     130****  Misc
    158131***/
    159132
    160 static inline const tr_bitset *
    161 tr_cpBlockBitset( const tr_completion * cp )
    162 {
    163     return &cp->blockBitset;
    164 }
     133bool  tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t );
    165134
    166 tr_bitfield * tr_cpCreatePieceBitfield( const tr_completion * cp );
     135void  tr_cpInvalidateDND( tr_completion * );
     136
     137void* tr_cpCreatePieceBitfield( const tr_completion * cp, size_t * byte_count );
     138
    167139
    168140#endif
Note: See TracChangeset for help on using the changeset viewer.