Commit 974a5e40 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

libvlccore: push threads cancellation down vlc_thread_create

parent 1cc00146
...@@ -573,12 +573,12 @@ static decoder_t * CreateDecoder( input_thread_t *p_input, ...@@ -573,12 +573,12 @@ static decoder_t * CreateDecoder( input_thread_t *p_input,
* The decoding main loop * The decoding main loop
* *
* \param p_dec the decoder * \param p_dec the decoder
* \return 0
*/ */
static void* DecoderThread( vlc_object_t *p_this ) static void* DecoderThread( vlc_object_t *p_this )
{ {
decoder_t * p_dec = (decoder_t *)p_this; decoder_t * p_dec = (decoder_t *)p_this;
block_t *p_block; block_t *p_block;
int canc = vlc_savecancel ();
/* The decoder's main loop */ /* The decoder's main loop */
while( !p_dec->b_die && !p_dec->b_error ) while( !p_dec->b_die && !p_dec->b_error )
...@@ -604,7 +604,7 @@ static void* DecoderThread( vlc_object_t *p_this ) ...@@ -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 /* We do it here because of the dll loader that wants close() in the
* same thread than open()/decode() */ * same thread than open()/decode() */
module_Unneed( p_dec, p_dec->p_module ); module_Unneed( p_dec, p_dec->p_module );
vlc_restorecancel (canc);
return NULL; return NULL;
} }
......
...@@ -542,6 +542,7 @@ static void* DStreamThread( vlc_object_t* p_this ) ...@@ -542,6 +542,7 @@ static void* DStreamThread( vlc_object_t* p_this )
stream_t *s = (stream_t *)p_this; stream_t *s = (stream_t *)p_this;
d_stream_sys_t *p_sys = (d_stream_sys_t*)s->p_sys; d_stream_sys_t *p_sys = (d_stream_sys_t*)s->p_sys;
demux_t *p_demux; demux_t *p_demux;
int canc = vlc_savecancel ();
/* Create the demuxer */ /* Create the demuxer */
if( !(p_demux = demux_New( s, "", p_sys->psz_name, "", s, p_sys->out, 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 ) ...@@ -558,6 +559,7 @@ static void* DStreamThread( vlc_object_t* p_this )
if( p_demux->pf_demux( p_demux ) <= 0 ) break; if( p_demux->pf_demux( p_demux ) <= 0 ) break;
} }
vlc_restorecancel (canc);
vlc_object_kill( p_demux ); vlc_object_kill( p_demux );
return NULL; return NULL;
} }
......
...@@ -492,6 +492,8 @@ sout_instance_t * input_DetachSout( input_thread_t *p_input ) ...@@ -492,6 +492,8 @@ sout_instance_t * input_DetachSout( input_thread_t *p_input )
static void* Run( vlc_object_t *p_this ) static void* Run( vlc_object_t *p_this )
{ {
input_thread_t *p_input = (input_thread_t *)p_this; input_thread_t *p_input = (input_thread_t *)p_this;
int canc = vlc_savecancel ();
/* Signal that the thread is launched */ /* Signal that the thread is launched */
vlc_thread_ready( p_input ); vlc_thread_ready( p_input );
...@@ -536,7 +538,7 @@ static void* Run( vlc_object_t *p_this ) ...@@ -536,7 +538,7 @@ static void* Run( vlc_object_t *p_this )
/* Clean up */ /* Clean up */
End( p_input ); End( p_input );
vlc_restorecancel (canc);
return NULL; return NULL;
} }
...@@ -548,8 +550,11 @@ static void* Run( vlc_object_t *p_this ) ...@@ -548,8 +550,11 @@ static void* Run( vlc_object_t *p_this )
static void* RunAndDestroy( vlc_object_t *p_this ) static void* RunAndDestroy( vlc_object_t *p_this )
{ {
input_thread_t *p_input = (input_thread_t *)p_this; input_thread_t *p_input = (input_thread_t *)p_this;
int canc;
/* Signal that the thread is launched */ /* Signal that the thread is launched */
vlc_thread_ready( p_input ); vlc_thread_ready( p_input );
canc = vlc_savecancel ();
if( Init( p_input ) ) if( Init( p_input ) )
goto exit; goto exit;
...@@ -579,6 +584,7 @@ static void* RunAndDestroy( vlc_object_t *p_this ) ...@@ -579,6 +584,7 @@ static void* RunAndDestroy( vlc_object_t *p_this )
exit: exit:
/* Release memory */ /* Release memory */
vlc_object_release( p_input ); vlc_object_release( p_input );
vlc_restorecancel (canc);
return 0; return 0;
} }
......
...@@ -309,6 +309,7 @@ static void* Manage( void* p_object ) ...@@ -309,6 +309,7 @@ static void* Manage( void* p_object )
mtime_t i_lastcheck; mtime_t i_lastcheck;
mtime_t i_time; mtime_t i_time;
int canc = vlc_savecancel ();
i_lastcheck = vlm_Date(); i_lastcheck = vlm_Date();
while( !vlm->b_die ) while( !vlm->b_die )
...@@ -412,6 +413,7 @@ static void* Manage( void* p_object ) ...@@ -412,6 +413,7 @@ static void* Manage( void* p_object )
msleep( 100000 ); msleep( 100000 );
} }
vlc_restorecancel (canc);
return NULL; return NULL;
} }
......
...@@ -558,8 +558,8 @@ static int DialogSend( vlc_object_t *p_this, interaction_dialog_t *p_dialog ) ...@@ -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 ) static void* InteractionLoop( vlc_object_t *p_this )
{ {
int i;
interaction_t *p_interaction = (interaction_t*) p_this; interaction_t *p_interaction = (interaction_t*) p_this;
int canc = vlc_savecancel ();
vlc_object_lock( p_this ); vlc_object_lock( p_this );
while( vlc_object_alive( p_this ) ) while( vlc_object_alive( p_this ) )
...@@ -570,12 +570,13 @@ static void* InteractionLoop( vlc_object_t *p_this ) ...@@ -570,12 +570,13 @@ static void* InteractionLoop( vlc_object_t *p_this )
vlc_object_unlock( p_this ); vlc_object_unlock( p_this );
/* Remove all dialogs - Interfaces must be able to clean up their data */ /* 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]; interaction_dialog_t * p_dialog = p_interaction->pp_dialogs[i];
DialogDestroy( p_dialog ); DialogDestroy( p_dialog );
REMOVE_ELEM( p_interaction->pp_dialogs, p_interaction->i_dialogs, i ); REMOVE_ELEM( p_interaction->pp_dialogs, p_interaction->i_dialogs, i );
} }
vlc_restorecancel (canc);
return NULL; return NULL;
} }
......
...@@ -198,6 +198,7 @@ static void* RunInterface( vlc_object_t *p_this ) ...@@ -198,6 +198,7 @@ static void* RunInterface( vlc_object_t *p_this )
intf_thread_t *p_intf = (intf_thread_t *)p_this; intf_thread_t *p_intf = (intf_thread_t *)p_this;
vlc_value_t val, text; vlc_value_t val, text;
char *psz_intf; char *psz_intf;
int canc = vlc_savecancel ();
/* Variable used for interface spawning */ /* Variable used for interface spawning */
var_Create( p_intf, "intf-add", VLC_VAR_STRING | var_Create( p_intf, "intf-add", VLC_VAR_STRING |
...@@ -258,6 +259,8 @@ static void* RunInterface( vlc_object_t *p_this ) ...@@ -258,6 +259,8 @@ static void* RunInterface( vlc_object_t *p_this )
p_intf->p_module = module_Need( p_intf, "interface", psz_intf, 0 ); p_intf->p_module = module_Need( p_intf, "interface", psz_intf, 0 );
} }
while( p_intf->p_module ); while( p_intf->p_module );
vlc_restorecancel (canc);
return NULL; return NULL;
} }
...@@ -269,6 +272,8 @@ static void * MonitorLibVLCDeath( vlc_object_t * p_this ) ...@@ -269,6 +272,8 @@ static void * MonitorLibVLCDeath( vlc_object_t * p_this )
{ {
intf_thread_t *p_intf = (intf_thread_t *)p_this; intf_thread_t *p_intf = (intf_thread_t *)p_this;
libvlc_int_t * p_libvlc = p_intf->p_libvlc; libvlc_int_t * p_libvlc = p_intf->p_libvlc;
int canc = vlc_savecancel ();
vlc_object_lock( p_libvlc ); vlc_object_lock( p_libvlc );
while(vlc_object_alive( p_libvlc ) ) while(vlc_object_alive( p_libvlc ) )
{ {
...@@ -292,6 +297,7 @@ static void * MonitorLibVLCDeath( vlc_object_t * p_this ) ...@@ -292,6 +297,7 @@ static void * MonitorLibVLCDeath( vlc_object_t * p_this )
vlc_object_kill( p_intf ); vlc_object_kill( p_intf );
} }
vlc_list_release( p_list ); vlc_list_release( p_list );
vlc_restorecancel (canc);
return NULL; return NULL;
} }
#endif #endif
......
...@@ -122,6 +122,7 @@ void system_End( libvlc_int_t *p_this ) ...@@ -122,6 +122,7 @@ void system_End( libvlc_int_t *p_this )
*****************************************************************************/ *****************************************************************************/
static void* AppThread( vlc_object_t * p_this ) static void* AppThread( vlc_object_t * p_this )
{ {
int canc = vlc_savecancel ();
VlcApplication * BeApp = VlcApplication * BeApp =
new VlcApplication("application/x-vnd.videolan-vlc"); new VlcApplication("application/x-vnd.videolan-vlc");
vlc_object_attach( p_this, p_this->p_libvlc ); vlc_object_attach( p_this, p_this->p_libvlc );
...@@ -129,6 +130,7 @@ static void* AppThread( vlc_object_t * p_this ) ...@@ -129,6 +130,7 @@ static void* AppThread( vlc_object_t * p_this )
BeApp->Run(); BeApp->Run();
vlc_object_detach( p_this ); vlc_object_detach( p_this );
delete BeApp; delete BeApp;
vlc_restorecancel (canc);
return NULL; return NULL;
} }
......
...@@ -1385,6 +1385,9 @@ void* update_CheckReal( vlc_object_t* p_this ) ...@@ -1385,6 +1385,9 @@ void* update_CheckReal( vlc_object_t* p_this )
{ {
update_check_thread_t *p_uct = (update_check_thread_t *)p_this; update_check_thread_t *p_uct = (update_check_thread_t *)p_this;
bool b_ret; bool b_ret;
int canc;
vlc_savecancel (&canc);
vlc_mutex_lock( &p_uct->p_update->lock ); vlc_mutex_lock( &p_uct->p_update->lock );
EmptyRelease( p_uct->p_update ); EmptyRelease( p_uct->p_update );
...@@ -1393,6 +1396,8 @@ void* update_CheckReal( vlc_object_t* p_this ) ...@@ -1393,6 +1396,8 @@ void* update_CheckReal( vlc_object_t* p_this )
if( p_uct->pf_callback ) if( p_uct->pf_callback )
(p_uct->pf_callback)( p_uct->p_data, b_ret ); (p_uct->pf_callback)( p_uct->p_data, b_ret );
vlc_restorecancel (canc);
return NULL; return NULL;
} }
...@@ -1504,11 +1509,13 @@ static void* update_DownloadReal( vlc_object_t *p_this ) ...@@ -1504,11 +1509,13 @@ static void* update_DownloadReal( vlc_object_t *p_this )
stream_t *p_stream = NULL; stream_t *p_stream = NULL;
void* p_buffer = NULL; void* p_buffer = NULL;
int i_read; int i_read;
int canc;
update_t *p_update = p_udt->p_update; update_t *p_update = p_udt->p_update;
char *psz_destdir = p_udt->psz_destdir; char *psz_destdir = p_udt->psz_destdir;
msg_Dbg( p_udt, "Opening Stream '%s'", p_update->release.psz_url ); msg_Dbg( p_udt, "Opening Stream '%s'", p_update->release.psz_url );
canc = vlc_savecancel ();
/* Open the stream */ /* Open the stream */
p_stream = stream_UrlNew( p_udt, p_update->release.psz_url ); p_stream = stream_UrlNew( p_udt, p_update->release.psz_url );
...@@ -1699,6 +1706,10 @@ end: ...@@ -1699,6 +1706,10 @@ end:
free( p_buffer ); free( p_buffer );
free( psz_size ); free( psz_size );
p_udt->p_update->p_download = NULL;
vlc_object_release( p_udt );
vlc_restorecancel (canc);
return NULL; return NULL;
} }
......
...@@ -2027,6 +2027,7 @@ static void* httpd_HostThread( vlc_object_t *p_this ) ...@@ -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 ); counter_t *p_active_counter = stats_CounterCreate( host, VLC_VAR_INTEGER, STATS_COUNTER );
int evfd; int evfd;
bool b_die; bool b_die;
int canc = vlc_savecancel ();
retry: retry:
vlc_object_lock( host ); vlc_object_lock( host );
...@@ -2568,6 +2569,7 @@ retry: ...@@ -2568,6 +2569,7 @@ retry:
stats_CounterClean( p_total_counter ); stats_CounterClean( p_total_counter );
if( p_active_counter ) if( p_active_counter )
stats_CounterClean( p_active_counter ); stats_CounterClean( p_active_counter );
vlc_restorecancel (canc);
return NULL; return NULL;
} }
......
...@@ -205,15 +205,18 @@ services_discovery_RemoveItem ( services_discovery_t * p_sd, input_item_t * p_it ...@@ -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 ) static void* RunSD( vlc_object_t *p_this )
{ {
services_discovery_t *p_sd = (services_discovery_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 ); vlc_event_send( &p_sd->event_manager, &event );
p_sd->pf_run( p_sd ); p_sd->pf_run( p_sd );
event.type = vlc_ServicesDiscoveryEnded; event.type = vlc_ServicesDiscoveryEnded;
vlc_event_send( &p_sd->event_manager, &event ); vlc_event_send( &p_sd->event_manager, &event );
vlc_restorecancel (canc);
return NULL; return NULL;
} }
......
...@@ -138,6 +138,7 @@ static void* RunControlThread ( vlc_object_t *p_this ) ...@@ -138,6 +138,7 @@ static void* RunControlThread ( vlc_object_t *p_this )
/* Tell above that we're ready */ /* Tell above that we're ready */
vlc_thread_ready( p_playlist ); vlc_thread_ready( p_playlist );
int canc = vlc_savecancel ();
vlc_object_lock( p_playlist ); vlc_object_lock( p_playlist );
while( vlc_object_alive( p_playlist ) ) while( vlc_object_alive( p_playlist ) )
{ {
...@@ -165,6 +166,7 @@ static void* RunControlThread ( vlc_object_t *p_this ) ...@@ -165,6 +166,7 @@ static void* RunControlThread ( vlc_object_t *p_this )
vlc_object_unlock( p_playlist ); vlc_object_unlock( p_playlist );
playlist_LastLoop( p_playlist ); playlist_LastLoop( p_playlist );
vlc_restorecancel (canc);
return NULL; return NULL;
} }
...@@ -174,9 +176,13 @@ static void* RunControlThread ( vlc_object_t *p_this ) ...@@ -174,9 +176,13 @@ static void* RunControlThread ( vlc_object_t *p_this )
static void* RunPreparse ( vlc_object_t *p_this ) static void* RunPreparse ( vlc_object_t *p_this )
{ {
playlist_preparse_t *p_obj = (playlist_preparse_t*)p_this; playlist_preparse_t *p_obj = (playlist_preparse_t*)p_this;
int canc;
/* Tell above that we're ready */ /* Tell above that we're ready */
vlc_thread_ready( p_obj ); vlc_thread_ready( p_obj );
canc = vlc_savecancel ();
playlist_PreparseLoop( p_obj ); playlist_PreparseLoop( p_obj );
vlc_restorecancel (canc);
return NULL; return NULL;
} }
...@@ -185,7 +191,9 @@ static void* RunFetcher( vlc_object_t *p_this ) ...@@ -185,7 +191,9 @@ static void* RunFetcher( vlc_object_t *p_this )
playlist_fetcher_t *p_obj = (playlist_fetcher_t *)p_this; playlist_fetcher_t *p_obj = (playlist_fetcher_t *)p_this;
/* Tell above that we're ready */ /* Tell above that we're ready */
vlc_thread_ready( p_obj ); vlc_thread_ready( p_obj );
int canc = vlc_savecancel ();
playlist_FetcherLoop( p_obj ); playlist_FetcherLoop( p_obj );
vlc_restorecancel (canc);
return NULL; return NULL;
} }
......
...@@ -192,6 +192,11 @@ static void * RunThread( vlc_object_t *p_this) ...@@ -192,6 +192,11 @@ static void * RunThread( vlc_object_t *p_this)
{ {
sap_handler_t *p_sap = (sap_handler_t*)p_this; sap_handler_t *p_sap = (sap_handler_t*)p_this;
sap_session_t *p_session; 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 ) while( !p_sap->b_die )
{ {
...@@ -236,6 +241,7 @@ static void * RunThread( vlc_object_t *p_this) ...@@ -236,6 +241,7 @@ static void * RunThread( vlc_object_t *p_this)
} }
vlc_object_unlock( p_sap ); vlc_object_unlock( p_sap );
} }
vlc_restorecancel (canc);
return NULL; return NULL;
} }
......
...@@ -717,6 +717,7 @@ static void* RunThread( vlc_object_t *p_this ) ...@@ -717,6 +717,7 @@ static void* RunThread( vlc_object_t *p_this )
bool b_drop_late; bool b_drop_late;
int i_displayed = 0, i_lost = 0, i_loops = 0; int i_displayed = 0, i_lost = 0, i_loops = 0;
int canc = vlc_savecancel ();
/* /*
* Initialize thread * Initialize thread
...@@ -735,6 +736,7 @@ static void* RunThread( vlc_object_t *p_this ) ...@@ -735,6 +736,7 @@ static void* RunThread( vlc_object_t *p_this )
{ {
EndThread( p_vout ); EndThread( p_vout );
vlc_mutex_unlock( &p_vout->change_lock ); vlc_mutex_unlock( &p_vout->change_lock );
vlc_restorecancel (canc);
return NULL; return NULL;
} }
...@@ -1121,6 +1123,7 @@ static void* RunThread( vlc_object_t *p_this ) ...@@ -1121,6 +1123,7 @@ static void* RunThread( vlc_object_t *p_this )
vlc_mutex_unlock( &p_vout->change_lock ); vlc_mutex_unlock( &p_vout->change_lock );
vlc_object_unlock( p_vout ); vlc_object_unlock( p_vout );
vlc_restorecancel (canc);
return NULL; return NULL;
} }
...@@ -1381,6 +1384,7 @@ typedef struct suxor_thread_t ...@@ -1381,6 +1384,7 @@ typedef struct suxor_thread_t
static void* SuxorRestartVideoES( vlc_object_t * p_vlc_t ) static void* SuxorRestartVideoES( vlc_object_t * p_vlc_t )
{ {
suxor_thread_t *p_this = (suxor_thread_t *) p_vlc_t; suxor_thread_t *p_this = (suxor_thread_t *) p_vlc_t;
int canc = vlc_savecancel ();
/* Now restart current video stream */ /* Now restart current video stream */
int val = var_GetInteger( p_this->p_input, "video-es" ); int val = var_GetInteger( p_this->p_input, "video-es" );
if( val >= 0 ) if( val >= 0 )
...@@ -1390,8 +1394,8 @@ static void* SuxorRestartVideoES( vlc_object_t * p_vlc_t ) ...@@ -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->p_input );
vlc_object_release( p_this ); vlc_object_release( p_this );
vlc_restorecancel (canc);
return NULL; return NULL;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment