Ignore:
Timestamp:
Jul 30, 2007, 3:27:52 PM (14 years ago)
Author:
charles
Message:

better encapsulation of platform-specific constructs: tr_thread_t, tr_cond_t, tr_lock_t

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/net.c

    r2544 r2552  
    5757}
    5858
    59 static tr_thread_t  resolveThread;
    60 static tr_lock_t    resolveLock;
    61 static tr_cond_t    resolveCond;
    62 static volatile int resolveDie;
     59static tr_thread_t  * resolveThread;
     60static tr_lock_t    * resolveLock;
     61static tr_cond_t    * resolveCond;
     62static volatile int   resolveDie;
    6363static tr_resolve_t * resolveQueue;
    6464
     
    8686    resolveDie   = 0;
    8787    resolveQueue = NULL;
    88     tr_lockInit( &resolveLock );
    89     tr_condInit( &resolveCond );
    90     tr_threadCreate( &resolveThread, resolveFunc, NULL, "resolve" );
     88    resolveLock = tr_lockNew( );
     89    resolveCond = tr_condNew( );
     90    resolveThread = tr_threadNew( resolveFunc, NULL, "resolve" );
    9191}
    9292
     
    100100void tr_netResolveThreadClose()
    101101{
    102     tr_lockLock( &resolveLock );
     102    tr_lockLock( resolveLock );
    103103    resolveDie = 1;
    104     tr_lockUnlock( &resolveLock );
    105     tr_condSignal( &resolveCond );
     104    tr_lockUnlock( resolveLock );
     105    tr_condSignal( resolveCond );
    106106    tr_wait( 200 );
    107107}
     
    114114tr_resolve_t * tr_netResolveInit( const char * address )
    115115{
    116     tr_resolve_t * r;
    117 
    118     r           = malloc( sizeof( tr_resolve_t ) );
     116    tr_resolve_t * r = tr_new0( tr_resolve_t, 1 );
    119117    r->status   = TR_NET_WAIT;
    120118    r->address  = strdup( address );
     
    122120    r->next     = NULL;
    123121
    124     tr_lockLock( &resolveLock );
     122    tr_lockLock( resolveLock );
    125123    if( !resolveQueue )
    126124    {
     
    133131        iter->next = r;
    134132    }
    135     tr_lockUnlock( &resolveLock );
    136     tr_condSignal( &resolveCond );
     133    tr_lockUnlock( resolveLock );
     134    tr_condSignal( resolveCond );
    137135
    138136    return r;
     
    148146    tr_tristate_t ret;
    149147
    150     tr_lockLock( &resolveLock );
     148    tr_lockLock( resolveLock );
    151149    ret = r->status;
    152150    if( ret == TR_NET_OK )
     
    154152        *addr = r->addr;
    155153    }
    156     tr_lockUnlock( &resolveLock );
     154    tr_lockUnlock( resolveLock );
    157155
    158156    return ret;
     
    197195    struct hostent * host;
    198196
    199     tr_lockLock( &resolveLock );
     197    tr_lockLock( resolveLock );
    200198
    201199    while( !resolveDie )
     
    203201        if( !( r = resolveQueue ) )
    204202        {
    205             tr_condWait( &resolveCond, &resolveLock );
     203            tr_condWait( resolveCond, resolveLock );
    206204            continue;
    207205        }
    208206
    209207        /* Blocking resolution */
    210         tr_lockUnlock( &resolveLock );
     208        tr_lockUnlock( resolveLock );
    211209        host = gethostbyname( r->address );
    212         tr_lockLock( &resolveLock );
     210        tr_lockLock( resolveLock );
    213211
    214212        if( host )
     
    227225
    228226    /* Clean up  */
    229     tr_lockUnlock( &resolveLock );
    230     tr_lockClose( &resolveLock );
     227    tr_lockUnlock( resolveLock );
     228    tr_lockFree( resolveLock );
     229    resolveLock = NULL;
    231230    while( ( r = resolveQueue ) )
    232231    {
Note: See TracChangeset for help on using the changeset viewer.