use a straight lock, rather than a rwlock, for rate control
This commit is contained in:
parent
f0b4524fbe
commit
65b81d09b6
|
@ -44,7 +44,7 @@ tr_transfer_t;
|
|||
|
||||
struct tr_ratecontrol_s
|
||||
{
|
||||
tr_rwlock_t * lock;
|
||||
tr_lock_t * lock;
|
||||
int limit;
|
||||
int newest;
|
||||
tr_transfer_t transfers[HISTORY_SIZE];
|
||||
|
@ -80,7 +80,7 @@ tr_rcInit( void )
|
|||
{
|
||||
tr_ratecontrol_t * r = tr_new0( tr_ratecontrol_t, 1 );
|
||||
r->limit = 0;
|
||||
r->lock = tr_rwNew( );
|
||||
r->lock = tr_lockNew( );
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ void
|
|||
tr_rcClose( tr_ratecontrol_t * r )
|
||||
{
|
||||
tr_rcReset( r );
|
||||
tr_rwFree( r->lock );
|
||||
tr_lockFree( r->lock );
|
||||
tr_free( r );
|
||||
}
|
||||
|
||||
|
@ -100,11 +100,11 @@ int
|
|||
tr_rcCanTransfer( const tr_ratecontrol_t * r )
|
||||
{
|
||||
int ret;
|
||||
tr_rwReaderLock( (tr_rwlock_t*)r->lock );
|
||||
tr_lockLock( (tr_lock_t*)r->lock );
|
||||
|
||||
ret = rateForInterval( r, SHORT_INTERVAL_MSEC ) < r->limit;
|
||||
|
||||
tr_rwReaderUnlock( (tr_rwlock_t*)r->lock );
|
||||
tr_lockUnlock( (tr_lock_t*)r->lock );
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -112,11 +112,11 @@ float
|
|||
tr_rcRate( const tr_ratecontrol_t * r )
|
||||
{
|
||||
float ret;
|
||||
tr_rwReaderLock( (tr_rwlock_t*)r->lock );
|
||||
tr_lockLock( (tr_lock_t*)r->lock );
|
||||
|
||||
ret = rateForInterval( r, LONG_INTERVAL_MSEC );
|
||||
|
||||
tr_rwReaderUnlock( (tr_rwlock_t*)r->lock );
|
||||
tr_lockUnlock( (tr_lock_t*)r->lock );
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,7 @@ tr_rcTransferred( tr_ratecontrol_t * r, int size )
|
|||
if( size < 100 ) /* don't count small messages */
|
||||
return;
|
||||
|
||||
tr_rwWriterLock( r->lock );
|
||||
tr_lockLock( (tr_lock_t*)r->lock );
|
||||
|
||||
now = tr_date ();
|
||||
if( r->transfers[r->newest].date + GRANULARITY_MSEC >= now )
|
||||
|
@ -143,24 +143,24 @@ tr_rcTransferred( tr_ratecontrol_t * r, int size )
|
|||
r->transfers[r->newest].size = size;
|
||||
}
|
||||
|
||||
tr_rwWriterUnlock( r->lock );
|
||||
tr_lockUnlock( (tr_lock_t*)r->lock );
|
||||
}
|
||||
|
||||
void
|
||||
tr_rcReset( tr_ratecontrol_t * r )
|
||||
{
|
||||
tr_rwWriterLock( r->lock );
|
||||
tr_lockLock( (tr_lock_t*)r->lock );
|
||||
r->newest = 0;
|
||||
memset( r->transfers, 0, sizeof(tr_transfer_t) * HISTORY_SIZE );
|
||||
tr_rwWriterUnlock( r->lock );
|
||||
tr_lockUnlock( (tr_lock_t*)r->lock );
|
||||
}
|
||||
|
||||
void
|
||||
tr_rcSetLimit( tr_ratecontrol_t * r, int limit )
|
||||
{
|
||||
tr_rwWriterLock( r->lock );
|
||||
tr_lockLock( (tr_lock_t*)r->lock );
|
||||
r->limit = limit;
|
||||
tr_rwWriterUnlock( r->lock );
|
||||
tr_lockUnlock( (tr_lock_t*)r->lock );
|
||||
}
|
||||
|
||||
int
|
||||
|
|
Loading…
Reference in New Issue