1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-24 00:34:04 +00:00

(trunk libT) make the evbuffer pool threadsafe

This commit is contained in:
Charles Kerr 2008-12-31 14:29:28 +00:00
parent 217d3d3c91
commit 2ea88f30f5

View file

@ -1301,19 +1301,39 @@ tr_int2ptr( int i )
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*
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 )
buf = evbuffer_new( );
assert( !EVBUFFER_LENGTH( buf ) );
tr_lockUnlock( l );
return buf;
}
void
tr_releaseBuffer( struct evbuffer * buf )
{
tr_lock * l = getBufferLock( );
tr_lockLock( l );
evbuffer_drain( buf, EVBUFFER_LENGTH( buf ) );
assert( EVBUFFER_LENGTH( buf ) == 0 );
tr_list_prepend( &_bufferList, buf );
tr_lockUnlock( l );
}