Changeset 3050


Ignore:
Timestamp:
Sep 12, 2007, 3:58:53 AM (14 years ago)
Author:
charles
Message:

fix race condition that could cause crash-on-startup

Location:
branches/encryption/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/encryption/libtransmission/transmission.c

    r3049 r3050  
    102102
    103103    tr_eventInit( h );
     104    while( !h->events )
     105        tr_wait( 50 );
     106
    104107    tr_netInit();
    105108
  • branches/encryption/libtransmission/trevent.c

    r3049 r3050  
    1717#include <stdio.h>
    1818
     19#include <signal.h>
    1920#include <sys/queue.h> /* for evhttp */
    2021#include <sys/types.h> /* for evhttp */
     
    5152    struct timeval pulseInterval;
    5253    uint8_t die;
     54
     55    int timerCount;
    5356}
    5457tr_event_handle;
     
    123126        {
    124127            case TR_EV_TIMER_ADD:
    125 fprintf( stderr, "adding timer %p from queue \n", cmd->timer );
    126128                timeout_add( &cmd->timer->event, &cmd->timer->tv );
    127129                break;
     
    130132                event_del( &cmd->timer->event );
    131133                tr_free( cmd->timer );
     134                --eh->timerCount;
    132135                break;
    133136
     
    166169        timeout_add( &eh->pulse, &eh->pulseInterval );
    167170    else {
     171        assert( eh->timerCount ==  0 );
    168172        evdns_shutdown( FALSE );
    169173        event_del( &eh->pulse );
     
    194198    tr_dbg( "Starting libevent thread" );
    195199
     200#ifndef WIN32
     201    /* Don't exit when writing on a broken socket */
     202    signal( SIGPIPE, SIG_IGN );
     203#endif
     204
    196205    eh->base = event_init( );
    197206    //event_set_log_callback( logFunc );
     
    199208    timeout_set( &eh->pulse, pumpList, veh );
    200209    timeout_add( &eh->pulse, &eh->pulseInterval );
     210    eh->h->events = eh;
    201211
    202212    event_dispatch( );
     
    222232    eh->pulseInterval = timevalMsec( 20 );
    223233    eh->thread = tr_threadNew( libeventThreadFunc, eh, "libeventThreadFunc" );
    224 
    225     handle->events = eh;
    226234}
    227235
     
    358366    if( timer!=NULL && !timer->inCallback ) {
    359367        if( tr_amInThread( timer->eh->thread ) ) {
     368            --timer->eh->timerCount;
    360369            event_del( &timer->event );
    361370            tr_free( timer );
     
    388397        cmd->mode = TR_EV_TIMER_ADD;
    389398        cmd->timer = timer;
    390 fprintf( stderr, "queueing timer %p\n", cmd->timer );
    391         pushList( handle->events, cmd );
     399        pushList( handle->events, cmd );
     400        ++handle->events->timerCount;
    392401    }
    393402
     
    433442    /* purge pending commands from the list */
    434443    tr_lockLock( eh->lock );
    435     while(( v = tr_list_remove( &eh->commands, bufev, bufCompareFunc ) )) {
    436         fprintf( stderr, "---> I AM PURGING A QUEUED COMMAND BECAUSE ITS BUFEV IS GOING AWAY <--\n" );
     444    while(( v = tr_list_remove( &eh->commands, bufev, bufCompareFunc ) ))
    437445        tr_free( v );
    438     }
    439446    tr_lockUnlock( eh->lock );
    440447
Note: See TracChangeset for help on using the changeset viewer.