Changeset 12280


Ignore:
Timestamp:
Mar 31, 2011, 2:53:22 PM (11 years ago)
Author:
jordan
Message:

(trunk libT) use aggregation for the tr_bandwidth objects owned by tr_session and tr_torrent

Location:
trunk/libtransmission
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bandwidth.c

    r12226 r12280  
    9696***/
    9797
    98 tr_bandwidth*
     98void
    9999tr_bandwidthConstruct( tr_bandwidth * b, tr_session * session, tr_bandwidth * parent )
    100100{
     
    105105    b->band[TR_DOWN].honorParentLimits = true;
    106106    tr_bandwidthSetParent( b, parent );
    107     return b;
    108 }
    109 
    110 tr_bandwidth*
     107}
     108
     109void
    111110tr_bandwidthDestruct( tr_bandwidth * b )
    112111{
     
    117116
    118117    memset( b, ~0, sizeof( tr_bandwidth ) );
    119     return b;
    120118}
    121119
  • trunk/libtransmission/bandwidth.h

    r12204 r12280  
    123123**/
    124124
    125 tr_bandwidth* tr_bandwidthConstruct( tr_bandwidth * bandwidth,
    126                                      tr_session   * session,
    127                                      tr_bandwidth * parent );
    128 
    129 /** @brief create a new tr_bandwidth object */
    130 static inline tr_bandwidth* tr_bandwidthNew( tr_session * session, tr_bandwidth * parent )
    131 {
    132     return tr_bandwidthConstruct( tr_new0( tr_bandwidth, 1 ), session, parent );
    133 }
    134 
    135 tr_bandwidth* tr_bandwidthDestruct( tr_bandwidth * bandwidth );
    136 
    137 /** @brief free a tr_bandwidth object */
    138 static inline void tr_bandwidthFree( tr_bandwidth * bandwidth )
    139 {
    140     tr_free( tr_bandwidthDestruct( bandwidth ) );
    141 }
     125void tr_bandwidthConstruct( tr_bandwidth * bandwidth,
     126                            tr_session   * session,
     127                            tr_bandwidth * parent );
     128
     129void tr_bandwidthDestruct( tr_bandwidth * bandwidth );
    142130
    143131/** @brief test to see if the pointer refers to a live bandwidth object */
     
    259247}
    260248
    261 static inline bool tr_bandwidthAreParentLimitsHonored( tr_bandwidth  * bandwidth,
    262                                                        tr_direction    direction )
     249static inline bool tr_bandwidthAreParentLimitsHonored( const tr_bandwidth  * bandwidth,
     250                                                       tr_direction          direction )
    263251{
    264252    assert( tr_isBandwidth( bandwidth ) );
  • trunk/libtransmission/peer-mgr.c

    r12272 r12280  
    20312031                peer->io = tr_handshakeStealIO( handshake ); /* this steals its refcount too, which is
    20322032                                                                balanced by our unref in peerDelete()  */
    2033                 tr_peerIoSetParent( peer->io, t->tor->bandwidth );
     2033                tr_peerIoSetParent( peer->io, &t->tor->bandwidth );
    20342034                tr_peerMsgsNew( t->tor, peer, peerCallbackFunc, t );
    20352035
     
    20792079        tr_handshake * handshake;
    20802080
    2081         io = tr_peerIoNewIncoming( session, session->bandwidth, addr, port, socket, utp_socket );
     2081        io = tr_peerIoNewIncoming( session, &session->bandwidth, addr, port, socket, utp_socket );
    20822082
    20832083        handshake = tr_handshakeNew( io,
     
    30483048    const tr_session * session = t->manager->session;
    30493049    const int chokeAll = !tr_torrentIsPieceTransferAllowed( t->tor, TR_CLIENT_TO_PEER );
    3050     const bool isMaxedOut = isBandwidthMaxedOut( t->tor->bandwidth, now, TR_UP );
     3050    const bool isMaxedOut = isBandwidthMaxedOut( &t->tor->bandwidth, now, TR_UP );
    30513051
    30523052    assert( torrentIsLocked( t ) );
     
    35433543
    35443544    /* allocate bandwidth to the peers */
    3545     tr_bandwidthAllocate( mgr->session->bandwidth, TR_UP, BANDWIDTH_PERIOD_MSEC );
    3546     tr_bandwidthAllocate( mgr->session->bandwidth, TR_DOWN, BANDWIDTH_PERIOD_MSEC );
     3545    tr_bandwidthAllocate( &mgr->session->bandwidth, TR_UP, BANDWIDTH_PERIOD_MSEC );
     3546    tr_bandwidthAllocate( &mgr->session->bandwidth, TR_DOWN, BANDWIDTH_PERIOD_MSEC );
    35473547
    35483548    /* possibly stop torrents that have seeded enough */
     
    38533853
    38543854        /* if we've already got enough speed in this torrent... */
    3855         if( tr_torrentIsSeed( tor ) && isBandwidthMaxedOut( tor->bandwidth, now_msec, TR_UP ) )
     3855        if( tr_torrentIsSeed( tor ) && isBandwidthMaxedOut( &tor->bandwidth, now_msec, TR_UP ) )
    38563856            continue;
    38573857
     
    38963896
    38973897    io = tr_peerIoNewOutgoing( mgr->session,
    3898                                mgr->session->bandwidth,
     3898                               &mgr->session->bandwidth,
    38993899                               &atom->addr,
    39003900                               atom->port,
  • trunk/libtransmission/session.c

    r12263 r12280  
    568568    session->udp_socket = -1;
    569569    session->udp6_socket = -1;
    570     session->bandwidth = tr_bandwidthNew( session, NULL );
    571570    session->lock = tr_lockNew( );
    572571    session->cache = tr_cacheNew( 1024*1024*2 );
     
    574573    session->magicNumber = SESSION_MAGIC_NUMBER;
    575574    session->buffer = tr_valloc( SESSION_BUFFER_SIZE );
     575    tr_bandwidthConstruct( &session->bandwidth, session, NULL );
    576576    tr_peerIdInit( session->peer_id );
    577577    tr_bencInitList( &session->removedTorrents, 0 );
     
    662662
    663663    dbgmsg( "tr_sessionInit: the session's top-level bandwidth object is %p",
    664             session->bandwidth );
     664            &session->bandwidth );
    665665
    666666    tr_bencInitDict( &settings, 0 );
     
    12451245    const bool zeroCase = isLimited && !limit_Bps;
    12461246
    1247     tr_bandwidthSetLimited( session->bandwidth, dir, isLimited && !zeroCase );
    1248 
    1249     tr_bandwidthSetDesiredSpeed_Bps( session->bandwidth, dir, limit_Bps );
     1247    tr_bandwidthSetLimited( &session->bandwidth, dir, isLimited && !zeroCase );
     1248
     1249    tr_bandwidthSetDesiredSpeed_Bps( &session->bandwidth, dir, limit_Bps );
    12501250}
    12511251
     
    16811681tr_sessionGetPieceSpeed_Bps( const tr_session * session, tr_direction dir )
    16821682{
    1683     return tr_isSession( session ) ? tr_bandwidthGetPieceSpeed_Bps( session->bandwidth, 0, dir ) : 0;
     1683    return tr_isSession( session ) ? tr_bandwidthGetPieceSpeed_Bps( &session->bandwidth, 0, dir ) : 0;
    16841684}
    16851685
     
    16871687tr_sessionGetRawSpeed_Bps( const tr_session * session, tr_direction dir )
    16881688{
    1689     return tr_isSession( session ) ? tr_bandwidthGetRawSpeed_Bps( session->bandwidth, 0, dir ) : 0;
     1689    return tr_isSession( session ) ? tr_bandwidthGetRawSpeed_Bps( &session->bandwidth, 0, dir ) : 0;
    16901690}
    16911691double
     
    18551855    /* free the session memory */
    18561856    tr_bencFree( &session->removedTorrents );
    1857     tr_bandwidthFree( session->bandwidth );
     1857    tr_bandwidthDestruct( &session->bandwidth );
    18581858    tr_bitfieldDestruct( &session->turtle.minutes );
    18591859    tr_lockFree( session->lock );
  • trunk/libtransmission/session.h

    r12204 r12280  
    2828#endif
    2929
     30#include "bandwidth.h"
    3031#include "bencode.h"
    3132#include "bitfield.h"
     
    4748struct tr_announcer;
    4849struct tr_announcer_udp;
    49 struct tr_bandwidth;
    5050struct tr_bindsockets;
    5151struct tr_cache;
     
    198198
    199199    /* monitors the "global pool" speeds */
    200     struct tr_bandwidth        * bandwidth;
     200    struct tr_bandwidth          bandwidth;
    201201
    202202    double                       desiredRatio;
  • trunk/libtransmission/torrent.c

    r12273 r12280  
    180180    assert( Bps >= 0 );
    181181
    182     if( tr_bandwidthSetDesiredSpeed_Bps( tor->bandwidth, dir, Bps ) )
     182    if( tr_bandwidthSetDesiredSpeed_Bps( &tor->bandwidth, dir, Bps ) )
    183183        tr_torrentSetDirty( tor );
    184184}
     
    195195    assert( tr_isDirection( dir ) );
    196196
    197     return tr_bandwidthGetDesiredSpeed_Bps( tor->bandwidth, dir );
     197    return tr_bandwidthGetDesiredSpeed_Bps( &tor->bandwidth, dir );
    198198}
    199199int
     
    209209    assert( tr_isDirection( dir ) );
    210210
    211     if( tr_bandwidthSetLimited( tor->bandwidth, dir, do_use ) )
     211    if( tr_bandwidthSetLimited( &tor->bandwidth, dir, do_use ) )
    212212        tr_torrentSetDirty( tor );
    213213}
     
    219219    assert( tr_isDirection( dir ) );
    220220
    221     return tr_bandwidthIsLimited( tor->bandwidth, dir );
     221    return tr_bandwidthIsLimited( &tor->bandwidth, dir );
    222222}
    223223
     
    229229    assert( tr_isTorrent( tor ) );
    230230
    231     changed = tr_bandwidthHonorParentLimits( tor->bandwidth, TR_UP, doUse );
    232     changed |= tr_bandwidthHonorParentLimits( tor->bandwidth, TR_DOWN, doUse );
     231    changed = tr_bandwidthHonorParentLimits( &tor->bandwidth, TR_UP, doUse );
     232    changed |= tr_bandwidthHonorParentLimits( &tor->bandwidth, TR_DOWN, doUse );
    233233
    234234    if( changed )
     
    241241    assert( tr_isTorrent( tor ) );
    242242
    243     return tr_bandwidthAreParentLimitsHonored( tor->bandwidth, TR_UP );
     243    return tr_bandwidthAreParentLimitsHonored( &tor->bandwidth, TR_UP );
    244244}
    245245
     
    828828        tor->incompleteDir = tr_strdup( dir );
    829829
    830     tor->bandwidth = tr_bandwidthNew( session, session->bandwidth );
    831 
    832     tor->bandwidth->priority = tr_ctorGetBandwidthPriority( ctor );
     830    tr_bandwidthConstruct( &tor->bandwidth, session, &session->bandwidth );
     831
     832    tor->bandwidth.priority = tr_ctorGetBandwidthPriority( ctor );
    833833
    834834    tor->error = TR_STAT_OK;
     
    11691169
    11701170    now = tr_time_msec( );
    1171     s->rawUploadSpeed_KBps     = toSpeedKBps( tr_bandwidthGetRawSpeed_Bps  ( tor->bandwidth, now, TR_UP ) );
    1172     s->pieceUploadSpeed_KBps   = toSpeedKBps( tr_bandwidthGetPieceSpeed_Bps( tor->bandwidth, now, TR_UP ) );
    1173     s->rawDownloadSpeed_KBps   = toSpeedKBps( tr_bandwidthGetRawSpeed_Bps  ( tor->bandwidth, now, TR_DOWN ) );
    1174     s->pieceDownloadSpeed_KBps = toSpeedKBps( tr_bandwidthGetPieceSpeed_Bps( tor->bandwidth, now, TR_DOWN ) );
     1171    s->rawUploadSpeed_KBps     = toSpeedKBps( tr_bandwidthGetRawSpeed_Bps  ( &tor->bandwidth, now, TR_UP ) );
     1172    s->pieceUploadSpeed_KBps   = toSpeedKBps( tr_bandwidthGetPieceSpeed_Bps( &tor->bandwidth, now, TR_UP ) );
     1173    s->rawDownloadSpeed_KBps   = toSpeedKBps( tr_bandwidthGetRawSpeed_Bps  ( &tor->bandwidth, now, TR_DOWN ) );
     1174    s->pieceDownloadSpeed_KBps = toSpeedKBps( tr_bandwidthGetPieceSpeed_Bps( &tor->bandwidth, now, TR_DOWN ) );
    11751175
    11761176    s->percentComplete = tr_cpPercentComplete ( &tor->completion );
     
    15011501    session->torrentCount--;
    15021502
    1503     tr_bandwidthFree( tor->bandwidth );
     1503    tr_bandwidthDestruct( &tor->bandwidth );
    15041504
    15051505    tr_metainfoFree( inf );
     
    21852185    assert( tr_isTorrent( tor ) );
    21862186
    2187     return tor->bandwidth->priority;
     2187    return tor->bandwidth.priority;
    21882188}
    21892189
     
    21942194    assert( tr_isPriority( priority ) );
    21952195
    2196     if( tor->bandwidth->priority != priority )
    2197     {
    2198         tor->bandwidth->priority = priority;
     2196    if( tor->bandwidth.priority != priority )
     2197    {
     2198        tor->bandwidth.priority = priority;
    21992199
    22002200        tr_torrentSetDirty( tor );
  • trunk/libtransmission/torrent.h

    r12204 r12280  
    1818#define TR_TORRENT_H 1
    1919
     20#include "bandwidth.h" /* tr_bandwidth */
    2021#include "completion.h" /* tr_completion */
    2122#include "session.h" /* tr_sessionLock(), tr_sessionUnlock() */
    2223#include "utils.h" /* TR_GNUC_PRINTF */
    2324
    24 struct tr_bandwidth;
    2525struct tr_torrent_tiers;
    2626struct tr_magnet_info;
     
    254254    int                        uniqueId;
    255255
    256     struct tr_bandwidth      * bandwidth;
     256    struct tr_bandwidth        bandwidth;
    257257
    258258    struct tr_torrent_peers  * torrentPeers;
  • trunk/libtransmission/webseed.c

    r12248 r12280  
    348348    w->callback_data = callback_data;
    349349    //tr_rcConstruct( &w->download_rate );
    350     tr_bandwidthConstruct( &w->bandwidth, tor->session, tor->bandwidth );
     350    tr_bandwidthConstruct( &w->bandwidth, tor->session, &tor->bandwidth );
    351351    w->timer = evtimer_new( w->session->event_base, webseed_timer_func, w );
    352352    tr_timerAddMsec( w->timer, TR_IDLE_TIMER_MSEC );
Note: See TracChangeset for help on using the changeset viewer.