]> git.sesse.net Git - vlc/blobdiff - src/stream_output/sap.c
libvlccore: push threads cancellation down vlc_thread_create
[vlc] / src / stream_output / sap.c
index 30479a7505d36f0bf6fe66a4dd790d827dac97a5..0c4e3f9dc30bda7418b61d22ef343e7f0cca135d 100644 (file)
@@ -94,7 +94,7 @@ struct sap_session_t {
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static void RunThread( vlc_object_t *p_this);
+static void RunThread( vlc_object_t *p_this);
 static int ComputeRate( sap_address_t *p_address );
 
 static int announce_SendSAPAnnounce( sap_handler_t *p_sap,
@@ -123,15 +123,10 @@ sap_handler_t *announce_SAPHandlerCreate( announce_handler_t *p_announce )
     p_sap = vlc_custom_create( VLC_OBJECT(p_announce), sizeof( sap_handler_t ),
                                VLC_OBJECT_ANNOUNCE, "announce" );
     if( !p_sap )
-    {
-        msg_Err( p_announce, "out of memory" );
         return NULL;
-    }
 
     p_sap->psz_object_name = strdup( "sap announcer" );
 
-    vlc_mutex_init( &p_sap->object_lock );
-
     p_sap->pf_add = announce_SAPAnnounceAdd;
     p_sap->pf_del = announce_SAPAnnounceDel;
 
@@ -193,15 +188,22 @@ static void announce_SAPHandlerDestructor( vlc_object_t * p_this )
  * \param p_this the SAP Handler object
  * \return nothing
  */
-static void RunThread( vlc_object_t *p_this)
+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 )
     {
         int i;
 
+        msleep( SAP_IDLE );
+
         /* If needed, get the rate info */
         if( p_sap->b_control == true )
         {
@@ -227,11 +229,9 @@ static void RunThread( vlc_object_t *p_this)
         else
         {
             vlc_object_unlock( p_sap );
-            msleep( SAP_IDLE );
             continue;
         }
         p_session = p_sap->pp_sessions[p_sap->i_current_session];
-        vlc_object_unlock( p_sap );
 
         /* And announce it */
         if( p_session->p_address->b_enabled == true &&
@@ -239,9 +239,10 @@ static void RunThread( vlc_object_t *p_this)
         {
             announce_SendSAPAnnounce( p_sap, p_session );
         }
-
-        msleep( SAP_IDLE );
+        vlc_object_unlock( p_sap );
     }
+    vlc_restorecancel (canc);
+    return NULL;
 }
 
 /* Add a SAP announce */