Ignore:
Timestamp:
Jul 30, 2007, 3:27:52 PM (15 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/fdlimit.c

    r2544 r2552  
    6464typedef struct tr_fd_s
    6565{
    66     tr_lock_t       lock;
    67     tr_cond_t       cond;
     66    tr_lock_t     * lock;
     67    tr_cond_t     * cond;
    6868   
    6969    int             reserved;
     
    101101
    102102    /* Init lock and cond */
    103     tr_lockInit( &gFd->lock );
    104     tr_condInit( &gFd->cond );
     103    gFd->lock = tr_lockNew( );
     104    gFd->cond = tr_condNew( );
    105105
    106106    /* Detect the maximum number of open files or sockets */
     
    144144    uint64_t date;
    145145
    146     tr_lockLock( &gFd->lock );
     146    tr_lockLock( gFd->lock );
    147147
    148148    /* Is it already open? */
     
    159159            /* File is being closed by another thread, wait until
    160160             * it's done before we reopen it */
    161             tr_condWait( &gFd->cond, &gFd->lock );
     161            tr_condWait( gFd->cond, gFd->lock );
    162162            i = -1;
    163163            continue;
     
    210210
    211211        /* All used! Wait a bit and try again */
    212         tr_condWait( &gFd->cond, &gFd->lock );
     212        tr_condWait( gFd->cond, gFd->lock );
    213213    }
    214214
     
    216216    if( ( ret = OpenFile( winner, folder, name, write ) ) )
    217217    {
    218         tr_lockUnlock( &gFd->lock );
     218        tr_lockUnlock( gFd->lock );
    219219        return ret;
    220220    }
     
    226226    gFd->open[winner].status = STATUS_USED;
    227227    gFd->open[winner].date   = tr_date();
    228     tr_lockUnlock( &gFd->lock );
     228    tr_lockUnlock( gFd->lock );
    229229   
    230230    return gFd->open[winner].file;
     
    237237{
    238238    int i;
    239     tr_lockLock( &gFd->lock );
     239    tr_lockLock( gFd->lock );
    240240
    241241    for( i = 0; i < TR_MAX_OPEN_FILES; i++ )
     
    248248    }
    249249   
    250     tr_condSignal( &gFd->cond );
    251     tr_lockUnlock( &gFd->lock );
     250    tr_condSignal( gFd->cond );
     251    tr_lockUnlock( gFd->lock );
    252252}
    253253
     
    259259    int i;
    260260
    261     tr_lockLock( &gFd->lock );
     261    tr_lockLock( gFd->lock );
    262262
    263263    for( i = 0; i < TR_MAX_OPEN_FILES; i++ )
     
    274274    }
    275275
    276     tr_lockUnlock( &gFd->lock );
     276    tr_lockUnlock( gFd->lock );
    277277}
    278278
     
    334334    int s = -1;
    335335
    336     tr_lockLock( &gFd->lock );
     336    tr_lockLock( gFd->lock );
    337337
    338338    if( priority && gFd->reserved >= TR_RESERVED_FDS )
     
    351351            gFd->normal++;
    352352    }
    353     tr_lockUnlock( &gFd->lock );
     353    tr_lockUnlock( gFd->lock );
    354354
    355355    return s;
     
    362362    struct sockaddr_in sock;
    363363
    364     tr_lockLock( &gFd->lock );
     364    tr_lockLock( gFd->lock );
    365365    if( gFd->normal < gFd->normalMax )
    366366    {
     
    381381        gFd->normal++;
    382382    }
    383     tr_lockUnlock( &gFd->lock );
     383    tr_lockUnlock( gFd->lock );
    384384
    385385    return s;
     
    391391void tr_fdSocketClose( int s )
    392392{
    393     tr_lockLock( &gFd->lock );
     393    tr_lockLock( gFd->lock );
    394394#ifdef BEOS_NETSERVER
    395395    closesocket( s );
     
    401401    else
    402402        gFd->normal--;
    403     tr_lockUnlock( &gFd->lock );
     403    tr_lockUnlock( gFd->lock );
    404404}
    405405
     
    409409void tr_fdClose()
    410410{
    411     tr_lockClose( &gFd->lock );
    412     tr_condClose( &gFd->cond );
     411    tr_lockFree( gFd->lock );
     412    tr_condFree( gFd->cond );
    413413    free( gFd );
    414414}
     
    505505    while( file->status & STATUS_CLOSING )
    506506    {
    507         tr_condWait( &gFd->cond, &gFd->lock );
     507        tr_condWait( gFd->cond, gFd->lock );
    508508    }
    509509    if( file->status & STATUS_INVALID )
     
    519519    tr_dbg( "Closing %s in %s (%d)", file->name, file->folder, file->write );
    520520    file->status = STATUS_CLOSING;
    521     tr_lockUnlock( &gFd->lock );
     521    tr_lockUnlock( gFd->lock );
    522522    close( file->file );
    523     tr_lockLock( &gFd->lock );
     523    tr_lockLock( gFd->lock );
    524524    file->status = STATUS_INVALID;
    525     tr_condSignal( &gFd->cond );
    526 }
    527 
     525    tr_condSignal( gFd->cond );
     526}
     527
Note: See TracChangeset for help on using the changeset viewer.