From 974a5e403890f924980be2add6983913c520c94f Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Tue, 5 Aug 2008 22:12:27 +0300 Subject: [PATCH] libvlccore: push threads cancellation down vlc_thread_create --- src/input/decoder.c | 4 ++-- src/input/demux.c | 2 ++ src/input/input.c | 8 +++++++- src/input/vlm.c | 2 ++ src/interface/interaction.c | 5 +++-- src/interface/interface.c | 6 ++++++ src/misc/beos_specific.cpp | 2 ++ src/misc/update.c | 11 +++++++++++ src/network/httpd.c | 2 ++ src/playlist/services_discovery.c | 7 +++++-- src/playlist/thread.c | 8 ++++++++ src/stream_output/sap.c | 6 ++++++ src/video_output/video_output.c | 6 +++++- 13 files changed, 61 insertions(+), 8 deletions(-) diff --git a/src/input/decoder.c b/src/input/decoder.c index 0544da0035..42756890fd 100644 --- a/src/input/decoder.c +++ b/src/input/decoder.c @@ -573,12 +573,12 @@ static decoder_t * CreateDecoder( input_thread_t *p_input, * The decoding main loop * * \param p_dec the decoder - * \return 0 */ static void* DecoderThread( vlc_object_t *p_this ) { decoder_t * p_dec = (decoder_t *)p_this; block_t *p_block; + int canc = vlc_savecancel (); /* The decoder's main loop */ while( !p_dec->b_die && !p_dec->b_error ) @@ -604,7 +604,7 @@ static void* DecoderThread( vlc_object_t *p_this ) /* We do it here because of the dll loader that wants close() in the * same thread than open()/decode() */ module_Unneed( p_dec, p_dec->p_module ); - + vlc_restorecancel (canc); return NULL; } diff --git a/src/input/demux.c b/src/input/demux.c index aa9c89fd2e..f8d7cc7a07 100644 --- a/src/input/demux.c +++ b/src/input/demux.c @@ -542,6 +542,7 @@ static void* DStreamThread( vlc_object_t* p_this ) stream_t *s = (stream_t *)p_this; d_stream_sys_t *p_sys = (d_stream_sys_t*)s->p_sys; demux_t *p_demux; + int canc = vlc_savecancel (); /* Create the demuxer */ if( !(p_demux = demux_New( s, "", p_sys->psz_name, "", s, p_sys->out, @@ -558,6 +559,7 @@ static void* DStreamThread( vlc_object_t* p_this ) if( p_demux->pf_demux( p_demux ) <= 0 ) break; } + vlc_restorecancel (canc); vlc_object_kill( p_demux ); return NULL; } diff --git a/src/input/input.c b/src/input/input.c index 933dbc748c..86acdd6384 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -492,6 +492,8 @@ sout_instance_t * input_DetachSout( input_thread_t *p_input ) static void* Run( vlc_object_t *p_this ) { input_thread_t *p_input = (input_thread_t *)p_this; + int canc = vlc_savecancel (); + /* Signal that the thread is launched */ vlc_thread_ready( p_input ); @@ -536,7 +538,7 @@ static void* Run( vlc_object_t *p_this ) /* Clean up */ End( p_input ); - + vlc_restorecancel (canc); return NULL; } @@ -548,8 +550,11 @@ static void* Run( vlc_object_t *p_this ) static void* RunAndDestroy( vlc_object_t *p_this ) { input_thread_t *p_input = (input_thread_t *)p_this; + int canc; + /* Signal that the thread is launched */ vlc_thread_ready( p_input ); + canc = vlc_savecancel (); if( Init( p_input ) ) goto exit; @@ -579,6 +584,7 @@ static void* RunAndDestroy( vlc_object_t *p_this ) exit: /* Release memory */ vlc_object_release( p_input ); + vlc_restorecancel (canc); return 0; } diff --git a/src/input/vlm.c b/src/input/vlm.c index c511c7c7ed..9397cb089f 100644 --- a/src/input/vlm.c +++ b/src/input/vlm.c @@ -309,6 +309,7 @@ static void* Manage( void* p_object ) mtime_t i_lastcheck; mtime_t i_time; + int canc = vlc_savecancel (); i_lastcheck = vlm_Date(); while( !vlm->b_die ) @@ -412,6 +413,7 @@ static void* Manage( void* p_object ) msleep( 100000 ); } + vlc_restorecancel (canc); return NULL; } diff --git a/src/interface/interaction.c b/src/interface/interaction.c index 293dc330e1..4b0f0b79e7 100644 --- a/src/interface/interaction.c +++ b/src/interface/interaction.c @@ -558,8 +558,8 @@ static int DialogSend( vlc_object_t *p_this, interaction_dialog_t *p_dialog ) static void* InteractionLoop( vlc_object_t *p_this ) { - int i; interaction_t *p_interaction = (interaction_t*) p_this; + int canc = vlc_savecancel (); vlc_object_lock( p_this ); while( vlc_object_alive( p_this ) ) @@ -570,12 +570,13 @@ static void* InteractionLoop( vlc_object_t *p_this ) vlc_object_unlock( p_this ); /* Remove all dialogs - Interfaces must be able to clean up their data */ - for( i = p_interaction->i_dialogs -1 ; i >= 0; i-- ) + for( int i = p_interaction->i_dialogs -1 ; i >= 0; i-- ) { interaction_dialog_t * p_dialog = p_interaction->pp_dialogs[i]; DialogDestroy( p_dialog ); REMOVE_ELEM( p_interaction->pp_dialogs, p_interaction->i_dialogs, i ); } + vlc_restorecancel (canc); return NULL; } diff --git a/src/interface/interface.c b/src/interface/interface.c index 990335dff3..e268c7c8d0 100644 --- a/src/interface/interface.c +++ b/src/interface/interface.c @@ -198,6 +198,7 @@ static void* RunInterface( vlc_object_t *p_this ) intf_thread_t *p_intf = (intf_thread_t *)p_this; vlc_value_t val, text; char *psz_intf; + int canc = vlc_savecancel (); /* Variable used for interface spawning */ var_Create( p_intf, "intf-add", VLC_VAR_STRING | @@ -258,6 +259,8 @@ static void* RunInterface( vlc_object_t *p_this ) p_intf->p_module = module_Need( p_intf, "interface", psz_intf, 0 ); } while( p_intf->p_module ); + + vlc_restorecancel (canc); return NULL; } @@ -269,6 +272,8 @@ static void * MonitorLibVLCDeath( vlc_object_t * p_this ) { intf_thread_t *p_intf = (intf_thread_t *)p_this; libvlc_int_t * p_libvlc = p_intf->p_libvlc; + int canc = vlc_savecancel (); + vlc_object_lock( p_libvlc ); while(vlc_object_alive( p_libvlc ) ) { @@ -292,6 +297,7 @@ static void * MonitorLibVLCDeath( vlc_object_t * p_this ) vlc_object_kill( p_intf ); } vlc_list_release( p_list ); + vlc_restorecancel (canc); return NULL; } #endif diff --git a/src/misc/beos_specific.cpp b/src/misc/beos_specific.cpp index 226725b42b..f1a14d08f7 100644 --- a/src/misc/beos_specific.cpp +++ b/src/misc/beos_specific.cpp @@ -122,6 +122,7 @@ void system_End( libvlc_int_t *p_this ) *****************************************************************************/ static void* AppThread( vlc_object_t * p_this ) { + int canc = vlc_savecancel (); VlcApplication * BeApp = new VlcApplication("application/x-vnd.videolan-vlc"); vlc_object_attach( p_this, p_this->p_libvlc ); @@ -129,6 +130,7 @@ static void* AppThread( vlc_object_t * p_this ) BeApp->Run(); vlc_object_detach( p_this ); delete BeApp; + vlc_restorecancel (canc); return NULL; } diff --git a/src/misc/update.c b/src/misc/update.c index ed3bc7e062..b05e4b2291 100644 --- a/src/misc/update.c +++ b/src/misc/update.c @@ -1385,6 +1385,9 @@ void* update_CheckReal( vlc_object_t* p_this ) { update_check_thread_t *p_uct = (update_check_thread_t *)p_this; bool b_ret; + int canc; + + vlc_savecancel (&canc); vlc_mutex_lock( &p_uct->p_update->lock ); EmptyRelease( p_uct->p_update ); @@ -1393,6 +1396,8 @@ void* update_CheckReal( vlc_object_t* p_this ) if( p_uct->pf_callback ) (p_uct->pf_callback)( p_uct->p_data, b_ret ); + + vlc_restorecancel (canc); return NULL; } @@ -1504,11 +1509,13 @@ static void* update_DownloadReal( vlc_object_t *p_this ) stream_t *p_stream = NULL; void* p_buffer = NULL; int i_read; + int canc; update_t *p_update = p_udt->p_update; char *psz_destdir = p_udt->psz_destdir; msg_Dbg( p_udt, "Opening Stream '%s'", p_update->release.psz_url ); + canc = vlc_savecancel (); /* Open the stream */ p_stream = stream_UrlNew( p_udt, p_update->release.psz_url ); @@ -1699,6 +1706,10 @@ end: free( p_buffer ); free( psz_size ); + p_udt->p_update->p_download = NULL; + + vlc_object_release( p_udt ); + vlc_restorecancel (canc); return NULL; } diff --git a/src/network/httpd.c b/src/network/httpd.c index c98b51c227..65c5c69e2e 100644 --- a/src/network/httpd.c +++ b/src/network/httpd.c @@ -2027,6 +2027,7 @@ static void* httpd_HostThread( vlc_object_t *p_this ) counter_t *p_active_counter = stats_CounterCreate( host, VLC_VAR_INTEGER, STATS_COUNTER ); int evfd; bool b_die; + int canc = vlc_savecancel (); retry: vlc_object_lock( host ); @@ -2568,6 +2569,7 @@ retry: stats_CounterClean( p_total_counter ); if( p_active_counter ) stats_CounterClean( p_active_counter ); + vlc_restorecancel (canc); return NULL; } diff --git a/src/playlist/services_discovery.c b/src/playlist/services_discovery.c index 13b01bb64a..35feabc6b9 100644 --- a/src/playlist/services_discovery.c +++ b/src/playlist/services_discovery.c @@ -205,15 +205,18 @@ services_discovery_RemoveItem ( services_discovery_t * p_sd, input_item_t * p_it static void* RunSD( vlc_object_t *p_this ) { services_discovery_t *p_sd = (services_discovery_t *)p_this; - vlc_event_t event; + vlc_event_t event = { + .type = vlc_ServicesDiscoveryStarted + }; + int canc = vlc_savecancel (); - event.type = vlc_ServicesDiscoveryStarted; vlc_event_send( &p_sd->event_manager, &event ); p_sd->pf_run( p_sd ); event.type = vlc_ServicesDiscoveryEnded; vlc_event_send( &p_sd->event_manager, &event ); + vlc_restorecancel (canc); return NULL; } diff --git a/src/playlist/thread.c b/src/playlist/thread.c index 4143494e28..d8821a7a3f 100644 --- a/src/playlist/thread.c +++ b/src/playlist/thread.c @@ -138,6 +138,7 @@ static void* RunControlThread ( vlc_object_t *p_this ) /* Tell above that we're ready */ vlc_thread_ready( p_playlist ); + int canc = vlc_savecancel (); vlc_object_lock( p_playlist ); while( vlc_object_alive( p_playlist ) ) { @@ -165,6 +166,7 @@ static void* RunControlThread ( vlc_object_t *p_this ) vlc_object_unlock( p_playlist ); playlist_LastLoop( p_playlist ); + vlc_restorecancel (canc); return NULL; } @@ -174,9 +176,13 @@ static void* RunControlThread ( vlc_object_t *p_this ) static void* RunPreparse ( vlc_object_t *p_this ) { playlist_preparse_t *p_obj = (playlist_preparse_t*)p_this; + int canc; + /* Tell above that we're ready */ vlc_thread_ready( p_obj ); + canc = vlc_savecancel (); playlist_PreparseLoop( p_obj ); + vlc_restorecancel (canc); return NULL; } @@ -185,7 +191,9 @@ static void* RunFetcher( vlc_object_t *p_this ) playlist_fetcher_t *p_obj = (playlist_fetcher_t *)p_this; /* Tell above that we're ready */ vlc_thread_ready( p_obj ); + int canc = vlc_savecancel (); playlist_FetcherLoop( p_obj ); + vlc_restorecancel (canc); return NULL; } diff --git a/src/stream_output/sap.c b/src/stream_output/sap.c index b23e71dc79..0c4e3f9dc3 100644 --- a/src/stream_output/sap.c +++ b/src/stream_output/sap.c @@ -192,6 +192,11 @@ static void * RunThread( vlc_object_t *p_this) { sap_handler_t *p_sap = (sap_handler_t*)p_this; sap_session_t *p_session; + int canc = vlc_savecancel (); + /* TODO: Once net_Write() is cancel-safe, so will this whole thread. + * However, there is a more serious issues here: msleep(SAP_IDLE). + * This thread should really use poll(). + */ while( !p_sap->b_die ) { @@ -236,6 +241,7 @@ static void * RunThread( vlc_object_t *p_this) } vlc_object_unlock( p_sap ); } + vlc_restorecancel (canc); return NULL; } diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c index d2d4719fe7..bb76692a61 100644 --- a/src/video_output/video_output.c +++ b/src/video_output/video_output.c @@ -717,6 +717,7 @@ static void* RunThread( vlc_object_t *p_this ) bool b_drop_late; int i_displayed = 0, i_lost = 0, i_loops = 0; + int canc = vlc_savecancel (); /* * Initialize thread @@ -735,6 +736,7 @@ static void* RunThread( vlc_object_t *p_this ) { EndThread( p_vout ); vlc_mutex_unlock( &p_vout->change_lock ); + vlc_restorecancel (canc); return NULL; } @@ -1121,6 +1123,7 @@ static void* RunThread( vlc_object_t *p_this ) vlc_mutex_unlock( &p_vout->change_lock ); vlc_object_unlock( p_vout ); + vlc_restorecancel (canc); return NULL; } @@ -1381,6 +1384,7 @@ typedef struct suxor_thread_t static void* SuxorRestartVideoES( vlc_object_t * p_vlc_t ) { suxor_thread_t *p_this = (suxor_thread_t *) p_vlc_t; + int canc = vlc_savecancel (); /* Now restart current video stream */ int val = var_GetInteger( p_this->p_input, "video-es" ); if( val >= 0 ) @@ -1390,8 +1394,8 @@ static void* SuxorRestartVideoES( vlc_object_t * p_vlc_t ) } vlc_object_release( p_this->p_input ); - vlc_object_release( p_this ); + vlc_restorecancel (canc); return NULL; } -- 2.39.2