Changeset 5342


Ignore:
Timestamp:
Mar 23, 2008, 8:54:54 PM (14 years ago)
Author:
charles
Message:

save a few bytes from each torrent by removing some vestigal rate control locks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/ratecontrol.c

    r4404 r5342  
    3030#include "utils.h"
    3131
    32 #define GRANULARITY_MSEC 250
     32#define GRANULARITY_MSEC 500
    3333#define SHORT_INTERVAL_MSEC 4000
    3434#define LONG_INTERVAL_MSEC 8000
     
    4343struct tr_ratecontrol
    4444{
    45     tr_lock * lock;
    4645    int limit;
    4746    int newest;
     
    7978    tr_ratecontrol * r = tr_new0( tr_ratecontrol, 1 );
    8079    r->limit = 0;
    81     r->lock = tr_lockNew( );
    8280    return r;
    8381}
     
    8785{
    8886    tr_rcReset( r );
    89     tr_lockFree( r->lock );
    9087    tr_free( r );
    9188}
     
    10299    if( r != NULL )
    103100    {
    104         float cur, max, kb;
    105  
    106         tr_lockLock( (tr_lock*)r->lock );
    107 
    108         cur = rateForInterval( r, SHORT_INTERVAL_MSEC );
    109         max = r->limit;
    110         kb = max>cur ? max-cur : 0;
     101        const float cur = rateForInterval( r, SHORT_INTERVAL_MSEC );
     102        const float max = r->limit;
     103        const float kb = max>cur ? max-cur : 0;
    111104        bytes = (size_t)(kb * 1024);
    112 
    113         tr_lockUnlock( (tr_lock*)r->lock );
    114105    }
    115106
     
    120111tr_rcRate( const tr_ratecontrol * r )
    121112{
    122     float ret;
     113    float ret = 0.0f;
    123114
    124     if( r == NULL )
    125         ret = 0.0f;
    126     else {
    127         tr_lockLock( (tr_lock*)r->lock );
     115    if( r )
    128116        ret = rateForInterval( r, LONG_INTERVAL_MSEC );
    129         tr_lockUnlock( (tr_lock*)r->lock );
    130     }
    131117
    132118    return ret;
     
    140126tr_rcTransferred( tr_ratecontrol * r, size_t size )
    141127{
    142     uint64_t now;
     128    const uint64_t now = tr_date ();
    143129
    144     tr_lockLock( (tr_lock*)r->lock );
    145 
    146     now = tr_date ();
    147130    if( r->transfers[r->newest].date + GRANULARITY_MSEC >= now )
    148131        r->transfers[r->newest].size += size;
     
    152135        r->transfers[r->newest].size = size;
    153136    }
    154 
    155     tr_lockUnlock( (tr_lock*)r->lock );
    156137}
    157138
     
    159140tr_rcReset( tr_ratecontrol * r )
    160141{
    161     tr_lockLock( (tr_lock*)r->lock );
    162142    r->newest = 0;
    163143    memset( r->transfers, 0, sizeof(struct tr_transfer) * HISTORY_SIZE );
    164     tr_lockUnlock( (tr_lock*)r->lock );
    165144}
    166145
     
    168147tr_rcSetLimit( tr_ratecontrol * r, int limit )
    169148{
    170     tr_lockLock( (tr_lock*)r->lock );
    171149    r->limit = limit;
    172     tr_lockUnlock( (tr_lock*)r->lock );
    173150}
    174151
Note: See TracChangeset for help on using the changeset viewer.