Changeset 7525
- Timestamp:
- Dec 29, 2008, 9:51:54 AM (12 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/completion.c
r7199 r7525 39 39 40 40 /* do we have this block? */ 41 tr_bitfield *blockBitfield;41 tr_bitfield blockBitfield; 42 42 43 43 /* do we have this piece? */ 44 tr_bitfield *pieceBitfield;44 tr_bitfield pieceBitfield; 45 45 46 46 /* a block is complete if and only if we have it */ … … 64 64 tr_cpReset( tr_completion * cp ) 65 65 { 66 tr_bitfieldClear( cp->pieceBitfield );67 tr_bitfieldClear( cp->blockBitfield );66 tr_bitfieldClear( &cp->pieceBitfield ); 67 tr_bitfieldClear( &cp->blockBitfield ); 68 68 memset( cp->completeBlocks, 0, 69 69 sizeof( uint16_t ) * cp->tor->info.pieceCount ); … … 79 79 80 80 cp->tor = tor; 81 cp->blockBitfield = tr_bitfieldNew( tor->blockCount );82 cp->pieceBitfield = tr_bitfieldNew( tor->info.pieceCount );83 81 cp->completeBlocks = tr_new( uint16_t, tor->info.pieceCount ); 82 tr_bitfieldConstruct( &cp->blockBitfield, tor->blockCount ); 83 tr_bitfieldConstruct( &cp->pieceBitfield, tor->info.pieceCount ); 84 84 tr_cpReset( cp ); 85 85 return cp; … … 89 89 tr_cpClose( tr_completion * cp ) 90 90 { 91 tr_free 92 tr_bitfield Free(cp->pieceBitfield );93 tr_bitfield Free(cp->blockBitfield );91 tr_free( cp->completeBlocks ); 92 tr_bitfieldDestruct( &cp->pieceBitfield ); 93 tr_bitfieldDestruct( &cp->blockBitfield ); 94 94 tr_free ( cp ); 95 95 } … … 156 156 tr_cpPieceBitfield( const tr_completion * cp ) 157 157 { 158 return cp->pieceBitfield;158 return &cp->pieceBitfield; 159 159 } 160 160 … … 194 194 cp->haveValidIsDirty = 1; 195 195 cp->completeBlocks[piece] = 0; 196 tr_bitfieldRemRange ( cp->blockBitfield, start, end );197 tr_bitfieldRem( cp->pieceBitfield, piece );196 tr_bitfieldRemRange ( &cp->blockBitfield, start, end ); 197 tr_bitfieldRem( &cp->pieceBitfield, piece ); 198 198 } 199 199 … … 202 202 tr_block_index_t block ) 203 203 { 204 return tr_bitfieldHas( cp->blockBitfield, block );204 return tr_bitfieldHas( &cp->blockBitfield, block ); 205 205 } 206 206 … … 220 220 221 221 if( tr_cpPieceIsComplete( cp, piece ) ) 222 tr_bitfieldAdd( cp->pieceBitfield, piece );223 224 tr_bitfieldAdd( cp->blockBitfield, block );222 tr_bitfieldAdd( &cp->pieceBitfield, piece ); 223 224 tr_bitfieldAdd( &cp->blockBitfield, block ); 225 225 226 226 cp->sizeNow += blockSize; … … 235 235 { 236 236 assert( cp ); 237 assert( cp->blockBitfield ); 238 assert( cp->blockBitfield->bits ); 239 assert( cp->blockBitfield->bitCount ); 240 241 return cp->blockBitfield; 237 assert( cp->blockBitfield.bits ); 238 assert( cp->blockBitfield.bitCount ); 239 240 return &cp->blockBitfield; 242 241 } 243 242 … … 250 249 assert( cp ); 251 250 assert( bitfield ); 252 assert( cp->blockBitfield );253 251 254 252 if( tr_bitfieldTestFast( bitfield, cp->tor->blockCount - 1 ) ) -
trunk/libtransmission/torrent.c
r7524 r7525 538 538 tor->error = 0; 539 539 540 t or->checkedPieces = tr_bitfieldNew(tor->info.pieceCount );540 tr_bitfieldConstruct( &tor->checkedPieces, tor->info.pieceCount ); 541 541 tr_torrentUncheck( tor ); 542 542 … … 1064 1064 tor->tracker = NULL; 1065 1065 1066 tr_bitfield Free(tor->checkedPieces );1066 tr_bitfieldDestruct( &tor->checkedPieces ); 1067 1067 1068 1068 tr_free( tor->downloadDir ); … … 1602 1602 tr_piece_index_t piece ) 1603 1603 { 1604 return tr_bitfieldHas( tor->checkedPieces, piece );1604 return tr_bitfieldHas( &tor->checkedPieces, piece ); 1605 1605 } 1606 1606 … … 1611 1611 { 1612 1612 if( isChecked ) 1613 tr_bitfieldAdd( tor->checkedPieces, piece );1613 tr_bitfieldAdd( &tor->checkedPieces, piece ); 1614 1614 else 1615 tr_bitfieldRem( tor->checkedPieces, piece );1615 tr_bitfieldRem( &tor->checkedPieces, piece ); 1616 1616 } 1617 1617 … … 1626 1626 1627 1627 if( isChecked ) 1628 tr_bitfieldAddRange ( tor->checkedPieces, begin, end );1628 tr_bitfieldAddRange ( &tor->checkedPieces, begin, end ); 1629 1629 else 1630 tr_bitfieldRemRange ( tor->checkedPieces, begin, end );1630 tr_bitfieldRemRange ( &tor->checkedPieces, begin, end ); 1631 1631 } 1632 1632 … … 1651 1651 tr_torrentUncheck( tr_torrent * tor ) 1652 1652 { 1653 tr_bitfieldRemRange ( tor->checkedPieces, 0, tor->info.pieceCount );1653 tr_bitfieldRemRange ( &tor->checkedPieces, 0, tor->info.pieceCount ); 1654 1654 } 1655 1655 … … 1657 1657 tr_torrentCountUncheckedPieces( const tr_torrent * tor ) 1658 1658 { 1659 return tor->info.pieceCount - tr_bitfieldCountTrueBits( 1660 tor->checkedPieces ); 1659 return tor->info.pieceCount - tr_bitfieldCountTrueBits( &tor->checkedPieces ); 1661 1660 } 1662 1661 -
trunk/libtransmission/torrent.h
r7368 r7525 27 27 #endif 28 28 29 #include "utils.h" /* tr_bitfield */ 30 29 31 #ifndef TR_TORRENT_H 30 32 #define TR_TORRENT_H 1 … … 206 208 struct tr_completion * completion; 207 209 208 struct tr_bitfield *checkedPieces;210 struct tr_bitfield checkedPieces; 209 211 tr_completeness completeness; 210 212 -
trunk/libtransmission/utils.c
r7446 r7525 747 747 748 748 tr_bitfield* 749 tr_bitfieldConstruct( tr_bitfield * b, size_t bitCount ) 750 { 751 b->bitCount = bitCount; 752 b->byteCount = ( bitCount + 7u ) / 8u; 753 b->bits = tr_new0( uint8_t, b->byteCount ); 754 return b; 755 } 756 757 void 758 tr_bitfieldDestruct( tr_bitfield * b ) 759 { 760 tr_free( b->bits ); 761 } 762 763 tr_bitfield* 749 764 tr_bitfieldNew( size_t bitCount ) 750 765 { 751 tr_bitfield * ret = tr_new0( tr_bitfield, 1 ); 752 753 ret->bitCount = bitCount; 754 ret->byteCount = ( bitCount + 7u ) / 8u; 755 ret->bits = tr_new0( uint8_t, ret->byteCount ); 756 return ret; 766 return tr_bitfieldConstruct( tr_new0( tr_bitfield, 1 ), bitCount ); 757 767 } 758 768 … … 773 783 if( bitfield ) 774 784 { 775 tr_ free( bitfield->bits);785 tr_bitfieldDestruct( bitfield ); 776 786 tr_free( bitfield ); 777 787 } -
trunk/libtransmission/utils.h
r7113 r7525 300 300 ***/ 301 301 302 struct tr_bitfield302 typedef struct tr_bitfield 303 303 { 304 304 uint8_t * bits; 305 305 size_t bitCount; 306 306 size_t byteCount; 307 }; 308 309 typedef struct tr_bitfield tr_bitfield; 307 } 308 tr_bitfield; 309 310 tr_bitfield* tr_bitfieldConstruct( tr_bitfield*, size_t bitcount ); 311 312 void tr_bitfieldDestruct( tr_bitfield* ); 310 313 311 314 tr_bitfield* tr_bitfieldNew( size_t bitcount ) TR_GNUC_MALLOC; … … 347 350 start looping. */ 348 351 #define tr_bitfieldHasFast( bitfield, nth ) \ 349 ( ( bitfield->bits[( nth ) >> 3u] << ( ( nth ) & 7u ) & 0x80 ) != 0 )352 ( ( (bitfield)->bits[( nth ) >> 3u] << ( ( nth ) & 7u ) & 0x80 ) != 0 ) 350 353 351 354 /** @param high the highest nth bit you're going to access */
Note: See TracChangeset
for help on using the changeset viewer.