From 8c9d5359b5ab760215191156294d5983da5da9fe Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 26 Jan 2009 02:51:50 +0000 Subject: [PATCH] (trunk libT) add more assertions to make Biiaru crash more^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^Hhelp track down the cause of Biiaru's crashes --- libtransmission/peer-io.c | 9 +++++++++ libtransmission/session.c | 4 +--- libtransmission/trevent.c | 16 +++++++++++----- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/libtransmission/peer-io.c b/libtransmission/peer-io.c index 707dc0894..f740d0127 100644 --- a/libtransmission/peer-io.c +++ b/libtransmission/peer-io.c @@ -420,7 +420,10 @@ static void io_dtor( void * vio ) { tr_peerIo * io = vio; + assert( tr_isPeerIo( io ) ); + assert( tr_amInEventThread( io->session ) ); + assert( io->session->events != NULL ); dbgmsg( io, "in tr_peerIo destructor" ); event_del( &io->event_read ); @@ -844,6 +847,8 @@ tr_peerIoFlush( tr_peerIo * io, tr_direction dir, size_t limit ) static void event_enable( tr_peerIo * io, short event ) { + assert( tr_amInEventThread( io->session ) ); + assert( io->session->events != NULL ); assert( event_initialized( &io->event_read ) ); assert( event_initialized( &io->event_write ) ); @@ -865,6 +870,8 @@ event_enable( tr_peerIo * io, short event ) static void event_disable( struct tr_peerIo * io, short event ) { + assert( tr_amInEventThread( io->session ) ); + assert( io->session->events != NULL ); assert( event_initialized( &io->event_read ) ); assert( event_initialized( &io->event_write ) ); @@ -893,6 +900,8 @@ tr_peerIoSetEnabled( tr_peerIo * io, assert( tr_isPeerIo( io ) ); assert( tr_isDirection( dir ) ); + assert( tr_amInEventThread( io->session ) ); + assert( io->session->events != NULL ); if( isEnabled ) event_enable( io, event ); diff --git a/libtransmission/session.c b/libtransmission/session.c index ff72aa2ad..e8abd2c2b 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -455,10 +455,8 @@ tr_sessionInit( const char * tag, tr_setConfigDir( session, configDir ); tr_netInit( ); /* must go before tr_eventInit */ - tr_eventInit( session ); - while( !session->events ) - tr_wait( 50 ); + assert( session->events != NULL ); session->peerMgr = tr_peerMgrNew( session ); diff --git a/libtransmission/trevent.c b/libtransmission/trevent.c index 7a958800d..2ed25d831 100644 --- a/libtransmission/trevent.c +++ b/libtransmission/trevent.c @@ -232,7 +232,6 @@ static void libeventThreadFunc( void * veh ) { tr_event_handle * eh = veh; - tr_dbg( "Starting libevent thread" ); #ifndef WIN32 @@ -240,16 +239,18 @@ libeventThreadFunc( void * veh ) signal( SIGPIPE, SIG_IGN ); #endif + eh->base = event_init( ); eh->session->events = eh; /* listen to the pipe's read fd */ - event_set( &eh->pipeEvent, eh->fds[0], EV_READ | EV_PERSIST, - readFromPipe, - veh ); + event_set( &eh->pipeEvent, eh->fds[0], EV_READ | EV_PERSIST, readFromPipe, veh ); event_add( &eh->pipeEvent, NULL ); event_set_log_callback( logFunc ); + + /* loop until all the events are done */ event_dispatch( ); + /* shut down the thread */ tr_lockFree( eh->lock ); event_base_free( eh->base ); eh->session->events = NULL; @@ -262,12 +263,17 @@ tr_eventInit( tr_session * session ) { tr_event_handle * eh; + session->events = NULL; + eh = tr_new0( tr_event_handle, 1 ); eh->lock = tr_lockNew( ); pipe( eh->fds ); eh->session = session; - eh->base = event_init( ); eh->thread = tr_threadNew( libeventThreadFunc, eh ); + + /* wait until the libevent thread is running */ + while( session->events == NULL ) + tr_wait( 100 ); } void