Changeset 7050
- Timestamp:
- Nov 5, 2008, 4:50:03 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/completion.c
r7027 r7050 34 34 { 35 35 unsigned int sizeWhenDoneIsDirty : 1; 36 unsigned int haveValidIsDirty : 1; 36 37 37 38 tr_torrent * tor; … … 50 51 use tr_cpSizeWhenDone() instead! */ 51 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; 52 58 53 59 /* number of bytes we want or have now. [0..sizeWhenDone] */ … … 64 70 cp->sizeNow = 0; 65 71 cp->sizeWhenDoneIsDirty = 1; 72 cp->haveValidIsDirty = 1; 66 73 } 67 74 … … 143 150 tr_piece_index_t piece ) 144 151 { 145 return cp->completeBlocks[piece] == tr_torPieceCountBlocks( cp->tor, 146 piece ); 152 return cp->completeBlocks[piece] == tr_torPieceCountBlocks( cp->tor, piece ); 147 153 } 148 154 … … 186 192 187 193 cp->sizeWhenDoneIsDirty = 1; 194 cp->haveValidIsDirty = 1; 188 195 cp->completeBlocks[piece] = 0; 189 196 tr_bitfieldRemRange ( cp->blockBitfield, start, end ); … … 212 219 ++cp->completeBlocks[piece]; 213 220 214 if( cp->completeBlocks[piece] == tr_torPieceCountBlocks( tor, piece ) )221 if( tr_cpPieceIsComplete( cp, piece ) ) 215 222 tr_bitfieldAdd( cp->pieceBitfield, piece ); 216 223 … … 219 226 cp->sizeNow += blockSize; 220 227 228 cp->haveValidIsDirty = 1; 221 229 cp->sizeWhenDoneIsDirty = 1; 222 230 } … … 261 269 tr_piece_index_t piece ) 262 270 { 263 return tr_torPieceCountBlocks( cp->tor, 264 piece ) - cp->completeBlocks[piece]; 271 return tr_torPieceCountBlocks( cp->tor, piece ) - cp->completeBlocks[piece]; 265 272 } 266 273 … … 301 308 } 302 309 303 uint64_t304 tr_cpHaveValid( const tr_completion *cp )310 static uint64_t 311 calculateHaveValid( const tr_completion * ccp ) 305 312 { 306 313 uint64_t b = 0; 307 314 tr_piece_index_t i; 308 const tr_torrent * tor = c p->tor;315 const tr_torrent * tor = ccp->tor; 309 316 const uint64_t pieceSize = tor->info.pieceSize; 310 317 const uint64_t lastPieceSize = tor->lastPieceSize; … … 312 319 313 320 for( i=0; i!=lastPiece; ++i ) 314 if( tr_cpPieceIsComplete( c p, i ) )321 if( tr_cpPieceIsComplete( ccp, i ) ) 315 322 b += pieceSize; 316 323 317 if( tr_cpPieceIsComplete( c p, lastPiece ) )324 if( tr_cpPieceIsComplete( ccp, lastPiece ) ) 318 325 b += lastPieceSize; 319 326 320 327 return b; 328 } 329 330 uint64_t 331 tr_cpHaveValid( const tr_completion * ccp ) 332 { 333 if( ccp->haveValidIsDirty ) 334 { 335 tr_completion * cp = (tr_completion *) ccp; /* mutable */ 336 cp->haveValidLazy = calculateHaveValid( ccp ); 337 cp->haveValidIsDirty = 0; 338 } 339 340 return ccp->haveValidLazy; 321 341 } 322 342
Note: See TracChangeset
for help on using the changeset viewer.