Ignore:
Timestamp:
Jul 10, 2007, 2:00:20 PM (14 years ago)
Author:
titer
Message:

Adds BeOS tr_condBroadcast implementation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/platform.c

    r2202 r2323  
    271271{
    272272#ifdef SYS_BEOS
    273     #error how is this done in beos
     273    return acquire_sem_etc( *l, 1, B_RELATIVE_TIMEOUT, 0 );
    274274#else
    275275    /* success on zero! */
     
    300300{
    301301#ifdef SYS_BEOS
    302     *c = -1;
     302    c->sem = create_sem( 1, "" );
     303    c->start = 0;
     304    c->end = 0;
    303305#else
    304306    pthread_cond_init( c, NULL );
     
    309311{
    310312#ifdef SYS_BEOS
    311     *c = find_thread( NULL );
     313    /* Keep track of that thread */
     314    acquire_sem( c->sem );
     315    c->threads[c->end] = find_thread( NULL );
     316    c->end = ( c->end + 1 ) % BEOS_MAX_THREADS;
     317    assert( c->end != c->start ); /* We hit BEOS_MAX_THREADS, arggh */
     318    release_sem( c->sem );
     319
    312320    release_sem( *l );
    313     suspend_thread( *c );
     321    suspend_thread( find_thread( NULL ) ); /* Wait for signal */
    314322    acquire_sem( *l );
    315     *c = -1;
    316323#else
    317324    pthread_cond_wait( c, l );
     
    319326}
    320327
     328#ifdef SYS_BEOS
     329static int condTrySignal( tr_cond_t * c )
     330{
     331    if( c->start == c->end )
     332        return 1;
     333
     334    for( ;; )
     335    {
     336        thread_info info;
     337        get_thread_info( c->threads[c->start], &info );
     338        if( info.state == B_THREAD_SUSPENDED )
     339        {
     340            resume_thread( c->threads[c->start] );
     341            c->start = ( c->start + 1 ) % BEOS_MAX_THREADS;
     342            break;
     343        }
     344        /* The thread is not suspended yet, which can happen since
     345         * tr_condWait does not atomically suspends after releasing
     346         * the semaphore. Wait a bit and try again. */
     347        snooze( 5000 );
     348    }
     349    return 0;
     350}
     351#endif
    321352void tr_condSignal( tr_cond_t * c )
    322353{
    323354#ifdef SYS_BEOS
    324     while( *c != -1 )
    325     {
    326         thread_info info;
    327         get_thread_info( *c, &info );
    328         if( info.state == B_THREAD_SUSPENDED )
    329         {
    330             resume_thread( *c );
    331             break;
    332         }
    333         snooze( 5000 );
    334     }
     355    acquire_sem( c->sem );
     356    condTrySignal( c );
     357    release_sem( c->sem );
    335358#else
    336359    pthread_cond_signal( c );
     
    340363{
    341364#ifdef SYS_BEOS
    342     #error how is this done in beos
     365    acquire_sem( c->sem );
     366    while( !condTrySignal( c ) );
     367    release_sem( c->sem );
    343368#else
    344369    pthread_cond_broadcast( c );
     
    349374{
    350375#ifdef SYS_BEOS
    351     *c = -1; /* Shut up gcc */
     376    delete_sem( c->sem );
    352377#else
    353378    pthread_cond_destroy( c );
Note: See TracChangeset for help on using the changeset viewer.