Changeset 7558


Ignore:
Timestamp:
Dec 31, 2008, 2:29:28 PM (12 years ago)
Author:
charles
Message:

(trunk libT) make the evbuffer pool threadsafe

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/utils.c

    r7549 r7558  
    13021302static tr_list * _bufferList = NULL;
    13031303
     1304static tr_lock *
     1305getBufferLock( void )
     1306{
     1307    static tr_lock * lock = NULL;
     1308    if( lock == NULL )
     1309        lock = tr_lockNew( );
     1310    return lock;
     1311}
     1312
    13041313struct evbuffer*
    13051314tr_getBuffer( void )
    13061315{
    1307     struct evbuffer * buf = tr_list_pop_front( &_bufferList );
     1316    struct evbuffer * buf;
     1317    tr_lock * l = getBufferLock( );
     1318    tr_lockLock( l );
     1319
     1320    buf = tr_list_pop_front( &_bufferList );
    13081321    if( buf == NULL )
    13091322        buf = evbuffer_new( );
    1310     assert( !EVBUFFER_LENGTH( buf ) );
     1323
     1324    tr_lockUnlock( l );
    13111325    return buf;
    13121326}
     
    13151329tr_releaseBuffer( struct evbuffer * buf )
    13161330{
     1331    tr_lock * l = getBufferLock( );
     1332    tr_lockLock( l );
     1333
    13171334    evbuffer_drain( buf, EVBUFFER_LENGTH( buf ) );
     1335    assert( EVBUFFER_LENGTH( buf ) == 0 );
    13181336    tr_list_prepend( &_bufferList, buf );
    1319 }
     1337
     1338    tr_lockUnlock( l );
     1339}
Note: See TracChangeset for help on using the changeset viewer.