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/bitfield.h

    r12204 r12248  
    1818#define TR_BITFIELD_H 1
    1919
     20#include <assert.h>
    2021#include "transmission.h"
    2122
     
    2425{
    2526    uint8_t *  bits;
    26     size_t     bitCount;
    27     size_t     byteCount;
     27    size_t     bit_count;
     28    size_t     byte_count;
     29    size_t     true_count;
     30
     31    /* Special cases for when full or empty but we don't know the bitCount.
     32       This occurs when a magnet link's peers send have all / have none */
     33    bool       have_all_hint;
     34    bool       have_none_hint;
    2835}
    2936tr_bitfield;
    3037
     38/***
     39****  life cycle
     40***/
     41
    3142extern const tr_bitfield TR_BITFIELD_INIT;
    3243
    33 tr_bitfield* tr_bitfieldConstruct( tr_bitfield*, size_t bitCount );
     44void   tr_bitfieldConstruct( tr_bitfield*, size_t bit_count );
    3445
    35 tr_bitfield* tr_bitfieldDestruct( tr_bitfield* );
     46void  tr_bitfieldDestruct( tr_bitfield* );
    3647
    37 tr_bitfield* tr_bitfieldNew( size_t bitCount );
     48/***
     49****
     50***/
    3851
    39 void tr_bitfieldFree( tr_bitfield * b );
     52void   tr_bitfieldSetHasAll( tr_bitfield* );
    4053
    41 void         tr_bitfieldClear( tr_bitfield* );
     54void   tr_bitfieldSetHasNone( tr_bitfield* );
    4255
    43 int          tr_bitfieldAdd( tr_bitfield*, size_t bit );
     56void   tr_bitfieldAdd( tr_bitfield*, size_t bit );
    4457
    45 int          tr_bitfieldRem( tr_bitfield*, size_t bit );
     58void   tr_bitfieldRem( tr_bitfield*, size_t bit );
    4659
    47 int          tr_bitfieldAddRange( tr_bitfield *, size_t begin, size_t end );
     60void   tr_bitfieldAddRange( tr_bitfield*, size_t begin, size_t end );
    4861
    49 int          tr_bitfieldRemRange( tr_bitfield*, size_t begin, size_t end );
     62void   tr_bitfieldRemRange( tr_bitfield*, size_t begin, size_t end );
    5063
    51 size_t       tr_bitfieldCountTrueBits( const tr_bitfield* );
     64/***
     65****
     66***/
    5267
    53 size_t       tr_bitfieldCountRange( const tr_bitfield * b, size_t begin, size_t end );
     68bool   tr_bitfieldSetFromBitfield( tr_bitfield*, const tr_bitfield* );
    5469
     70bool   tr_bitfieldSetRaw( tr_bitfield*, const void * bits, size_t byte_count );
    5571
    56 tr_bitfield* tr_bitfieldOr( tr_bitfield*, const tr_bitfield* );
     72void*  tr_bitfieldGetRaw( const tr_bitfield * b, size_t * byte_count );
     73
     74/***
     75****
     76***/
     77
     78size_t  tr_bitfieldCountRange( const tr_bitfield*, size_t begin, size_t end );
     79
     80static inline size_t
     81tr_bitfieldCountTrueBits( const tr_bitfield * b )
     82{
     83    assert( b->true_count == tr_bitfieldCountRange( b, 0, b->bit_count ) );
     84    return b->true_count;
     85}
     86
     87static inline bool
     88tr_bitfieldHasAll( const tr_bitfield * b )
     89{
     90    return b->bit_count ? ( b->true_count == b->bit_count ) : b->have_all_hint;
     91}
     92
     93static inline bool
     94tr_bitfieldHasNone( const tr_bitfield * b )
     95{
     96    return b->bit_count ? ( b->true_count == 0 ) : b->have_none_hint;
     97}
    5798
    5899/** A stripped-down version of bitfieldHas to be used
     
    61102    need to call tr_bitfieldTestFast() first before you
    62103    start looping. */
    63 static inline bool tr_bitfieldHasFast( const tr_bitfield * b, const size_t nth )
     104static inline bool
     105tr_bitfieldHasFast( const tr_bitfield * b, const size_t n )
    64106{
    65     return ( b->bits[nth>>3u] << ( nth & 7u ) & 0x80 ) != 0;
     107    if( tr_bitfieldHasAll( b ) ) return true;
     108    if( tr_bitfieldHasNone( b ) ) return false;
     109    return ( b->bits[n>>3u] << ( n & 7u ) & 0x80 ) != 0;
    66110}
    67111
    68112/** @param high the highest nth bit you're going to access */
    69 static inline bool tr_bitfieldTestFast( const tr_bitfield * b, const size_t high )
     113static inline bool
     114tr_bitfieldTestFast( const tr_bitfield * b, const size_t high )
    70115{
    71116    return ( b != NULL )
    72         && ( b->bits != NULL )
    73         && ( high < b->bitCount );
     117        && ( high < b->bit_count );
    74118}
    75119
    76 static inline bool tr_bitfieldHas( const tr_bitfield * b, size_t nth )
     120static inline bool
     121tr_bitfieldHas( const tr_bitfield * b, size_t n )
    77122{
    78     return tr_bitfieldTestFast( b, nth ) && tr_bitfieldHasFast( b, nth );
     123    return tr_bitfieldTestFast( b, n )
     124        && tr_bitfieldHasFast( b, n );
    79125}
    80126
Note: See TracChangeset for help on using the changeset viewer.