Changeset 7584


Ignore:
Timestamp:
Jan 2, 2009, 8:42:35 PM (12 years ago)
Author:
charles
Message:

(trunk libT) avoid some unnecessary memory fragmentation... for composited objects that have a tr_ratecontrol, contain the it directly rather than a pointer to one allocated elsewhere on the heap.

Location:
trunk/libtransmission
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-msgs.c

    r7578 r7584  
    14581458            }
    14591459            updatePeerProgress( msgs );
    1460             tr_rcTransferred( msgs->torrent->swarmSpeed,
     1460            tr_rcTransferred( &msgs->torrent->swarmSpeed,
    14611461                              msgs->torrent->info.pieceSize );
    14621462            break;
  • trunk/libtransmission/ratecontrol.c

    r7069 r7584  
    3030#include "utils.h"
    3131
    32 enum
    33 {
    34     INTERVAL_MSEC = TR_RATECONTROL_HISTORY_MSEC,
    35 
    36     GRANULARITY_MSEC = 250,
    37 
    38     HISTORY_SIZE = ( INTERVAL_MSEC / GRANULARITY_MSEC )
    39 };
    40 
    41 struct tr_transfer
    42 {
    43     uint64_t    date;
    44     uint64_t    size;
    45 };
    46 
    47 struct tr_ratecontrol
    48 {
    49     int                   newest;
    50     struct tr_transfer    transfers[HISTORY_SIZE];
    51 };
    52 
    5332/* return the xfer rate over the last `interval' seconds in KiB/sec */
    5433static float
     
    6746        bytes += r->transfers[i].size;
    6847
    69         if( --i == -1 ) i = HISTORY_SIZE - 1; /* circular history */
     48        if( --i == -1 ) i = TR_RC_HISTORY_SIZE - 1; /* circular history */
    7049        if( i == r->newest ) break; /* we've come all the way around */
    7150    }
    7251
    7352    return ( bytes / 1024.0 ) * ( 1000.0 / interval_msec );
    74 }
    75 
    76 /***
    77 ****
    78 ***/
    79 
    80 tr_ratecontrol*
    81 tr_rcInit( void )
    82 {
    83     return tr_new0( tr_ratecontrol, 1 );
    84 }
    85 
    86 void
    87 tr_rcClose( tr_ratecontrol * r )
    88 {
    89     memset( r, 0, sizeof( tr_ratecontrol ) );
    90     tr_free( r );
    9153}
    9254
     
    10163
    10264    if( r )
    103         ret = rateForInterval( r, INTERVAL_MSEC );
     65        ret = rateForInterval( r, TR_RC_HISTORY_MSEC );
    10466
    10567    return ret;
     
    11678    const uint64_t now = tr_date ( );
    11779
    118     if( r->transfers[r->newest].date + GRANULARITY_MSEC >= now )
     80    if( r->transfers[r->newest].date + TR_RC_GRANULARITY_MSEC >= now )
    11981        r->transfers[r->newest].size += size;
    12082    else
    12183    {
    122         if( ++r->newest == HISTORY_SIZE ) r->newest = 0;
     84        if( ++r->newest == TR_RC_HISTORY_SIZE ) r->newest = 0;
    12385        r->transfers[r->newest].date = now;
    12486        r->transfers[r->newest].size = size;
  • trunk/libtransmission/ratecontrol.h

    r7151 r7584  
    3030#define _TR_RATECONTROL_H_
    3131
     32#include <string.h> /* memset() */
     33
     34#include "transmission.h"
     35
     36/* these are PRIVATE IMPLEMENTATION details that should not be touched.
     37 * it's included in the header for inlining and composition. */
    3238enum
    3339{
    34     TR_RATECONTROL_HISTORY_MSEC = 2000
     40    TR_RC_HISTORY_MSEC = 2000,
     41    TR_RC_GRANULARITY_MSEC = 250,
     42    TR_RC_HISTORY_SIZE = ( TR_RC_HISTORY_MSEC / TR_RC_GRANULARITY_MSEC )
    3543};
    3644
    37 typedef struct tr_ratecontrol tr_ratecontrol;
     45/* these are PRIVATE IMPLEMENTATION details that should not be touched.
     46 * it's included in the header for inlining and composition. */
     47struct tr_transfer
     48{
     49    uint64_t    date;
     50    uint64_t    size;
     51};
    3852
     53/* these are PRIVATE IMPLEMENTATION details that should not be touched.
     54 * it's included in the header for inlining and composition. */
     55typedef struct tr_ratecontrol
     56{
     57    int                   newest;
     58    struct tr_transfer    transfers[TR_RC_HISTORY_SIZE];
     59}
     60tr_ratecontrol;
    3961
    40 tr_ratecontrol * tr_rcInit        ( void );
     62/***
     63****
     64***/
    4165
    42 void             tr_rcClose       ( tr_ratecontrol         * ratecontrol );
     66static inline void tr_rcConstruct ( tr_ratecontrol * rc ) { memset( rc, 0, sizeof( tr_ratecontrol ) ); }
     67
     68static inline void tr_rcDestruct  ( tr_ratecontrol * rc ) { memset( rc, 0xDEAD, sizeof( tr_ratecontrol ) ); }
    4369
    4470void             tr_rcTransferred ( tr_ratecontrol         * ratecontrol,
  • trunk/libtransmission/torrent.c

    r7578 r7584  
    502502    tr_torrentInitFilePieces( tor );
    503503
    504     tor->swarmSpeed = tr_rcInit( );
     504    tr_rcConstruct( &tor->swarmSpeed );
    505505
    506506    tr_sha1( tor->obfuscatedHash, "req2", 4,
     
    793793                       : 0.0;
    794794
    795     s->swarmSpeed = tr_rcRate( tor->swarmSpeed );
     795    s->swarmSpeed = tr_rcRate( &tor->swarmSpeed );
    796796
    797797    s->activityDate = tor->activityDate;
     
    10351035    tr_cpDestruct( &tor->completion );
    10361036
    1037     tr_rcClose( tor->swarmSpeed );
     1037    tr_rcDestruct( &tor->swarmSpeed );
    10381038
    10391039    tr_trackerUnsubscribe( tor->tracker, tor->trackerSubscription );
  • trunk/libtransmission/torrent.h

    r7578 r7584  
    3131
    3232#include "completion.h" /* tr_completion */
     33#include "ratecontrol.h" /* tr_ratecontrol */
    3334#include "session.h" /* tr_globalLock(), tr_globalUnlock() */
    3435#include "utils.h" /* tr_bitfield */
     
    147148    tr_speedlimit            speedLimitMode[2];
    148149
    149     struct tr_ratecontrol *  swarmSpeed;
     150    struct tr_ratecontrol    swarmSpeed;
    150151
    151152    int                      error;
  • trunk/libtransmission/webseed.c

    r7549 r7584  
    4141    uint32_t            byteCount;
    4242
    43     tr_ratecontrol    * rateDown;
     43    tr_ratecontrol      rateDown;
    4444
    4545    tr_session        * session;
     
    170170        {
    171171            fireClientGotData( w, response_byte_count );
    172             tr_rcTransferred( w->rateDown, response_byte_count );
     172            tr_rcTransferred( &w->rateDown, response_byte_count );
    173173        }
    174174
     
    257257    const int isActive = tr_webseedIsActive( w );
    258258
    259     *setme_KiBs = isActive ? tr_rcRate( w->rateDown ) : 0.0f;
     259    *setme_KiBs = isActive ? tr_rcRate( &w->rateDown ) : 0.0f;
    260260    return isActive;
    261261}
     
    276276    w->session = torrent->session;
    277277    w->content = evbuffer_new( );
    278     w->rateDown = tr_rcInit( );
    279278    w->url = tr_strdup( url );
    280279    w->callback = callback;
    281280    w->callback_userdata = callback_userdata;
     281    tr_rcConstruct( &w->rateDown );
    282282/*fprintf( stderr, "w->callback_userdata is %p\n", w->callback_userdata );*/
    283283    return w;
     
    296296        {
    297297            evbuffer_free( w->content );
    298             tr_rcClose( w->rateDown );
     298            tr_rcDestruct( &w->rateDown );
    299299            tr_free( w->url );
    300300            tr_free( w );
Note: See TracChangeset for help on using the changeset viewer.