mirror of
https://github.com/transmission/transmission
synced 2024-12-26 01:27:28 +00:00
save a few bytes from each torrent by removing some vestigal rate control locks
This commit is contained in:
parent
bc188e86f0
commit
c6d57fcdbe
1 changed files with 7 additions and 30 deletions
|
@ -29,7 +29,7 @@
|
|||
#include "ratecontrol.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define GRANULARITY_MSEC 250
|
||||
#define GRANULARITY_MSEC 500
|
||||
#define SHORT_INTERVAL_MSEC 4000
|
||||
#define LONG_INTERVAL_MSEC 8000
|
||||
#define HISTORY_SIZE (LONG_INTERVAL_MSEC / GRANULARITY_MSEC)
|
||||
|
@ -42,7 +42,6 @@ struct tr_transfer
|
|||
|
||||
struct tr_ratecontrol
|
||||
{
|
||||
tr_lock * lock;
|
||||
int limit;
|
||||
int newest;
|
||||
struct tr_transfer transfers[HISTORY_SIZE];
|
||||
|
@ -78,7 +77,6 @@ tr_rcInit( void )
|
|||
{
|
||||
tr_ratecontrol * r = tr_new0( tr_ratecontrol, 1 );
|
||||
r->limit = 0;
|
||||
r->lock = tr_lockNew( );
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -86,7 +84,6 @@ void
|
|||
tr_rcClose( tr_ratecontrol * r )
|
||||
{
|
||||
tr_rcReset( r );
|
||||
tr_lockFree( r->lock );
|
||||
tr_free( r );
|
||||
}
|
||||
|
||||
|
@ -101,16 +98,10 @@ tr_rcBytesLeft( const tr_ratecontrol * r )
|
|||
|
||||
if( r != NULL )
|
||||
{
|
||||
float cur, max, kb;
|
||||
|
||||
tr_lockLock( (tr_lock*)r->lock );
|
||||
|
||||
cur = rateForInterval( r, SHORT_INTERVAL_MSEC );
|
||||
max = r->limit;
|
||||
kb = max>cur ? max-cur : 0;
|
||||
const float cur = rateForInterval( r, SHORT_INTERVAL_MSEC );
|
||||
const float max = r->limit;
|
||||
const float kb = max>cur ? max-cur : 0;
|
||||
bytes = (size_t)(kb * 1024);
|
||||
|
||||
tr_lockUnlock( (tr_lock*)r->lock );
|
||||
}
|
||||
|
||||
return bytes;
|
||||
|
@ -119,15 +110,10 @@ tr_rcBytesLeft( const tr_ratecontrol * r )
|
|||
float
|
||||
tr_rcRate( const tr_ratecontrol * r )
|
||||
{
|
||||
float ret;
|
||||
float ret = 0.0f;
|
||||
|
||||
if( r == NULL )
|
||||
ret = 0.0f;
|
||||
else {
|
||||
tr_lockLock( (tr_lock*)r->lock );
|
||||
if( r )
|
||||
ret = rateForInterval( r, LONG_INTERVAL_MSEC );
|
||||
tr_lockUnlock( (tr_lock*)r->lock );
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -139,11 +125,8 @@ tr_rcRate( const tr_ratecontrol * r )
|
|||
void
|
||||
tr_rcTransferred( tr_ratecontrol * r, size_t size )
|
||||
{
|
||||
uint64_t now;
|
||||
const uint64_t now = tr_date ();
|
||||
|
||||
tr_lockLock( (tr_lock*)r->lock );
|
||||
|
||||
now = tr_date ();
|
||||
if( r->transfers[r->newest].date + GRANULARITY_MSEC >= now )
|
||||
r->transfers[r->newest].size += size;
|
||||
else {
|
||||
|
@ -151,25 +134,19 @@ tr_rcTransferred( tr_ratecontrol * r, size_t size )
|
|||
r->transfers[r->newest].date = now;
|
||||
r->transfers[r->newest].size = size;
|
||||
}
|
||||
|
||||
tr_lockUnlock( (tr_lock*)r->lock );
|
||||
}
|
||||
|
||||
void
|
||||
tr_rcReset( tr_ratecontrol * r )
|
||||
{
|
||||
tr_lockLock( (tr_lock*)r->lock );
|
||||
r->newest = 0;
|
||||
memset( r->transfers, 0, sizeof(struct tr_transfer) * HISTORY_SIZE );
|
||||
tr_lockUnlock( (tr_lock*)r->lock );
|
||||
}
|
||||
|
||||
void
|
||||
tr_rcSetLimit( tr_ratecontrol * r, int limit )
|
||||
{
|
||||
tr_lockLock( (tr_lock*)r->lock );
|
||||
r->limit = limit;
|
||||
tr_lockUnlock( (tr_lock*)r->lock );
|
||||
}
|
||||
|
||||
int
|
||||
|
|
Loading…
Reference in a new issue