mirror of
https://github.com/transmission/transmission
synced 2024-12-25 01:03:01 +00:00
(trunk libT) make the evbuffer pool threadsafe
This commit is contained in:
parent
217d3d3c91
commit
2ea88f30f5
1 changed files with 22 additions and 2 deletions
|
@ -1301,19 +1301,39 @@ tr_int2ptr( int i )
|
||||||
|
|
||||||
static tr_list * _bufferList = NULL;
|
static tr_list * _bufferList = NULL;
|
||||||
|
|
||||||
|
static tr_lock *
|
||||||
|
getBufferLock( void )
|
||||||
|
{
|
||||||
|
static tr_lock * lock = NULL;
|
||||||
|
if( lock == NULL )
|
||||||
|
lock = tr_lockNew( );
|
||||||
|
return lock;
|
||||||
|
}
|
||||||
|
|
||||||
struct evbuffer*
|
struct evbuffer*
|
||||||
tr_getBuffer( void )
|
tr_getBuffer( void )
|
||||||
{
|
{
|
||||||
struct evbuffer * buf = tr_list_pop_front( &_bufferList );
|
struct evbuffer * buf;
|
||||||
|
tr_lock * l = getBufferLock( );
|
||||||
|
tr_lockLock( l );
|
||||||
|
|
||||||
|
buf = tr_list_pop_front( &_bufferList );
|
||||||
if( buf == NULL )
|
if( buf == NULL )
|
||||||
buf = evbuffer_new( );
|
buf = evbuffer_new( );
|
||||||
assert( !EVBUFFER_LENGTH( buf ) );
|
|
||||||
|
tr_lockUnlock( l );
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tr_releaseBuffer( struct evbuffer * buf )
|
tr_releaseBuffer( struct evbuffer * buf )
|
||||||
{
|
{
|
||||||
|
tr_lock * l = getBufferLock( );
|
||||||
|
tr_lockLock( l );
|
||||||
|
|
||||||
evbuffer_drain( buf, EVBUFFER_LENGTH( buf ) );
|
evbuffer_drain( buf, EVBUFFER_LENGTH( buf ) );
|
||||||
|
assert( EVBUFFER_LENGTH( buf ) == 0 );
|
||||||
tr_list_prepend( &_bufferList, buf );
|
tr_list_prepend( &_bufferList, buf );
|
||||||
|
|
||||||
|
tr_lockUnlock( l );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue