]> git.sesse.net Git - vlc/commitdiff
libvlccore: push threads cancellation down vlc_thread_create
authorRémi Denis-Courmont <rdenis@simphalempin.com>
Tue, 5 Aug 2008 19:12:27 +0000 (22:12 +0300)
committerRémi Denis-Courmont <rdenis@simphalempin.com>
Wed, 27 Aug 2008 19:43:08 +0000 (22:43 +0300)
13 files changed:
src/input/decoder.c
src/input/demux.c
src/input/input.c
src/input/vlm.c
src/interface/interaction.c
src/interface/interface.c
src/misc/beos_specific.cpp
src/misc/update.c
src/network/httpd.c
src/playlist/services_discovery.c
src/playlist/thread.c
src/stream_output/sap.c
src/video_output/video_output.c

index 0544da0035ecc22e94446ac0aa2a30d332986e51..42756890fd16e1327a83af3ba14799a1e00ce517 100644 (file)
@@ -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;
 }
 
index aa9c89fd2e4e0a85928ad43f3d8d3fb89669edc5..f8d7cc7a07dfe1d0ae6e15805b0c14d55bb159d4 100644 (file)
@@ -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;
 }
index 933dbc748c6d1f2303de41d25326308610e5b43c..86acdd63847b3833defcb39af948f00b62de1947 100644 (file)
@@ -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;
 }
 
index c511c7c7edd2fb25173404c856869a761b4b6692..9397cb089fe2bcb708eefa3903e1a1934ad07386 100644 (file)
@@ -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;
 }
 
index 293dc330e11aa65b6e39467d7e6d1c1d1b5ce759..4b0f0b79e7ce58653900b9ee28792de4b0a7c718 100644 (file)
@@ -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;
 }
 
index 990335dff310cb7c01dc979027d6bce1ce1104ff..e268c7c8d0fb1764ff21bb7606bfca341c2d4ed7 100644 (file)
@@ -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
index 226725b42b39412db04807f50ea37d57e5a96db1..f1a14d08f75057600a04b9a8205771837e754609 100644 (file)
@@ -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;
 }
 
index ed3bc7e062ccae696fdca5bd0b1b62b7af2ea880..b05e4b2291ed9662a016472dec1ee2178d70e908 100644 (file)
@@ -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;
 }
 
index c98b51c22797faa21727b9ff2256a6661d1e7bde..65c5c69e2e72928489a73d1179acb96a6124d745 100644 (file)
@@ -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;
 }
 
index 13b01bb64acbb010df913a82fbbb04d76e310de0..35feabc6b954c16df35952a3a9196d3e59a53a6d 100644 (file)
@@ -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;
 }
 
index 4143494e2819f62a1c93c6fb579f1efd6c3b8718..d8821a7a3f02a58ad1342851632ef7b85384a537 100644 (file)
@@ -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;
 }
 
index b23e71dc79630606fca7a73812adb30a777826fe..0c4e3f9dc30bda7418b61d22ef343e7f0cca135d 100644 (file)
@@ -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;
 }
 
index d2d4719fe73f3e4b8b3ebe554bf0458586b664cf..bb76692a6161c31b8bf40defa1d2a13a4a09ac25 100644 (file)
@@ -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;
 }