1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 17:17:31 +00:00

(trunk) #1663 "crashes on shutdown if libevent loop doesn't exit soon enough" -- maybe crash less frequently now.

This commit is contained in:
Charles Kerr 2009-11-30 04:58:03 +00:00
parent 66ab7bff4a
commit 12bfde0c2b
2 changed files with 27 additions and 12 deletions

View file

@ -701,13 +701,10 @@ winsetup( struct cbdata * cbdata,
setupdrag( GTK_WIDGET( wind ), cbdata ); setupdrag( GTK_WIDGET( wind ), cbdata );
} }
static gpointer static gboolean
quitThreadFunc( gpointer gdata ) onSessionClosed( gpointer gdata )
{ {
struct cbdata * cbdata = gdata; struct cbdata * cbdata = gdata;
gdk_threads_enter( );
tr_core_close( cbdata->core );
/* shutdown the gui */ /* shutdown the gui */
if( cbdata->details ) { if( cbdata->details ) {
@ -732,8 +729,21 @@ quitThreadFunc( gpointer gdata )
g_free( cbdata ); g_free( cbdata );
gtk_main_quit( ); gtk_main_quit( );
gdk_threads_leave( );
return FALSE;
}
static gpointer
sessionCloseThreadFunc( gpointer gdata )
{
/* since tr_sessionClose() is a blocking function,
* call it from another thread... when it's done,
* punt the GUI teardown back to the GTK+ thread */
struct cbdata * cbdata = gdata;
gdk_threads_enter( );
tr_core_close( cbdata->core );
gtr_idle_add( onSessionClosed, gdata );
gdk_threads_leave( );
return NULL; return NULL;
} }
@ -800,7 +810,7 @@ wannaquit( gpointer vdata )
pref_int_get( PREF_KEY_MAIN_WINDOW_Y ) ); pref_int_get( PREF_KEY_MAIN_WINDOW_Y ) );
/* shut down libT */ /* shut down libT */
g_thread_create( quitThreadFunc, vdata, TRUE, NULL ); g_thread_create( sessionCloseThreadFunc, vdata, TRUE, NULL );
} }
static void static void

View file

@ -1586,7 +1586,7 @@ deadlineReached( const uint64_t deadline )
return tr_date( ) >= deadline; return tr_date( ) >= deadline;
} }
#define SHUTDOWN_MAX_SECONDS 30 #define SHUTDOWN_MAX_SECONDS 20
void void
tr_sessionClose( tr_session * session ) tr_sessionClose( tr_session * session )
@ -1602,8 +1602,7 @@ tr_sessionClose( tr_session * session )
tr_runInEventThread( session, sessionCloseImpl, session ); tr_runInEventThread( session, sessionCloseImpl, session );
while( !session->isClosed && !deadlineReached( deadline ) ) while( !session->isClosed && !deadlineReached( deadline ) )
{ {
dbgmsg( dbgmsg( "waiting for the libtransmission thread to finish" );
"waiting for the shutdown commands to run in the main thread" );
tr_wait( 100 ); tr_wait( 100 );
} }
@ -1623,10 +1622,16 @@ tr_sessionClose( tr_session * session )
/* close the libtransmission thread */ /* close the libtransmission thread */
tr_eventClose( session ); tr_eventClose( session );
while( session->events && !deadlineReached( deadline ) ) while( session->events != NULL )
{ {
dbgmsg( "waiting for the libevent thread to shutdown cleanly" ); static tr_bool forced = FALSE;
dbgmsg( "waiting for libtransmission thread to finish" );
tr_wait( 100 ); tr_wait( 100 );
if( deadlineReached( deadline ) && !forced )
{
event_loopbreak( );
forced = TRUE;
}
} }
/* free the session memory */ /* free the session memory */