Changeset 1203


Ignore:
Timestamp:
Dec 14, 2006, 3:50:33 AM (15 years ago)
Author:
titer
Message:

Adds tr_cond* and use them in fdlimit instead of tr_wait

Location:
branches/io/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/io/libtransmission/fdlimit.c

    r1201 r1203  
    4949{
    5050    tr_lock_t       lock;
     51    tr_cond_t       cond;
    5152   
    5253    int             reserved;
     
    7778    f = calloc( sizeof( tr_fd_t ), 1 );
    7879
    79     /* Init lock */
     80    /* Init lock and cond */
    8081    tr_lockInit( &f->lock );
     82    tr_condInit( &f->cond );
    8183
    8284    /* Detect the maximum number of open files or sockets */
     
    134136            /* File is being closed by another thread, wait until
    135137             * it's done before we reopen it */
    136             tr_lockUnlock( &f->lock );
    137             tr_wait( 10 );
    138             tr_lockLock( &f->lock );
     138            tr_condWait( &f->cond, &f->lock );
    139139            i = -1;
    140140            continue;
     
    195195
    196196        /* All used! Wait a bit and try again */
    197         tr_lockUnlock( &f->lock );
    198         tr_wait( 10 );
    199         tr_lockLock( &f->lock );
     197        tr_condWait( &f->cond, &f->lock );
    200198    }
    201199
     
    241239    }
    242240   
     241    tr_condSignal( &f->cond );
    243242    tr_lockUnlock( &f->lock );
    244243}
     
    334333{
    335334    tr_lockClose( &f->lock );
     335    tr_condClose( &f->cond );
    336336    free( f );
    337337}
     
    372372    tr_lockLock( &f->lock );
    373373    f->open[i].status = STATUS_INVALID;
     374    tr_condSignal( &f->cond );
    374375}
    375376
  • branches/io/libtransmission/platform.c

    r1000 r1203  
    233233}
    234234
     235
     236void tr_condCreate( tr_cond_t * c )
     237{
     238#ifdef SYS_BEOS
     239    *c = -1;
     240#else
     241    pthread_cond_init( c, NULL );
     242#endif
     243}
     244
     245void tr_condWait( tr_cond_t * c, tr_lock_t * l )
     246{
     247#ifdef SYS_BEOS
     248    *c = find_thread( NULL );
     249    release_sem( *l );
     250    suspend_thread( *c );
     251    acquire_sem( *l );
     252    *c = -1;
     253#else
     254    pthread_cond_wait( c, l );
     255#endif
     256}
     257
     258void tr_condSignal( tr_cond_t * c )
     259{
     260#ifdef SYS_BEOS
     261    while( *c != -1 )
     262    {
     263        thread_info info;
     264        get_thread_info( *c, &info );
     265        if( info.state == B_THREAD_SUSPENDED )
     266        {
     267            resume_thread( *c );
     268            break;
     269        }
     270A       snooze( 5000 );
     271    }
     272#else
     273    pthread_cond_signal( c );
     274#endif
     275}
     276
     277void tr_condClose( tr_cond_t * c )
     278{
     279#ifndef SYS_BEOS
     280    pthread_cond_destroy( c );
     281#endif
     282}
     283
     284
    235285#if defined( BSD )
    236286
  • branches/io/libtransmission/platform.h

    r920 r1203  
    2929  typedef thread_id tr_thread_t;
    3030  typedef sem_id    tr_lock_t;
     31  typedef int       tr_cond_t;
    3132#else
    3233  #include <pthread.h>
    3334  typedef pthread_t       tr_thread_t;
    3435  typedef pthread_mutex_t tr_lock_t;
     36  typedef pthread_cond_t  tr_cond_t;
    3537#endif
    3638
     
    6163}
    6264
     65void tr_condCreate( tr_cond_t * );
     66void tr_condWait( tr_cond_t *, tr_lock_t * );
     67void tr_condSignal( tr_cond_t * );
     68void tr_condClose( tr_cond_t * );
     69
    6370int
    6471tr_getDefaultRoute( struct in_addr * addr );
Note: See TracChangeset for help on using the changeset viewer.