]> git.sesse.net Git - vlc/commitdiff
dbus: do not use pf_run
authorRémi Denis-Courmont <remi@remlab.net>
Tue, 27 Nov 2012 18:06:49 +0000 (20:06 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Tue, 27 Nov 2012 18:06:49 +0000 (20:06 +0200)
modules/control/dbus/dbus.c
modules/control/dbus/dbus_common.h

index 405ebb0505a84fb45012f54957b1011c27828346..735975e196bb5f713a8376e9e8182cc3f74c07f1 100644 (file)
@@ -104,7 +104,7 @@ enum
 
 static int  Open    ( vlc_object_t * );
 static void Close   ( vlc_object_t * );
-static void Run     ( intf_thread_t * );
+static void *Run    ( void * );
 
 static int TrackChange( intf_thread_t * );
 static int AllCallback( vlc_object_t*, const char*, vlc_value_t, vlc_value_t, void* );
@@ -157,6 +157,7 @@ vlc_module_end ()
 static int Open( vlc_object_t *p_this )
 {
     intf_thread_t   *p_intf = (intf_thread_t*)p_this;
+#warning Leaks on error paths!
 
     /* initialisation of the connection */
     if( !dbus_threads_init_default() )
@@ -230,7 +231,7 @@ static int Open( vlc_object_t *p_this )
 
     dbus_connection_flush( p_conn );
 
-    p_intf->pf_run = Run;
+    p_intf->pf_run = NULL;
     p_intf->p_sys = p_sys;
     p_sys->p_conn = p_conn;
     p_sys->p_events = vlc_array_new();
@@ -257,28 +258,27 @@ static int Open( vlc_object_t *p_this )
                                                 remove_timeout,
                                                 timeout_toggled,
                                                 p_intf, NULL ) )
-    {
-        dbus_connection_unref( p_conn );
-        free( p_sys );
-        return VLC_ENOMEM;
-    }
+        goto error;
 
     if( !dbus_connection_set_watch_functions( p_conn,
                                               add_watch,
                                               remove_watch,
                                               watch_toggled,
                                               p_intf, NULL ) )
-    {
-        dbus_connection_unref( p_conn );
-        free( p_sys );
-        return VLC_ENOMEM;
-    }
+        goto error;
 
 /*     dbus_connection_set_wakeup_main_function( p_conn,
                                               wakeup_main_loop,
                                               p_intf, NULL); */
 
+    if( vlc_clone( &p_sys->thread, Run, p_intf, VLC_THREAD_PRIORITY_LOW ) )
+        goto error;
+
     return VLC_SUCCESS;
+error:
+    dbus_connection_unref( p_conn );
+    free( p_sys );
+    return VLC_ENOMEM;
 }
 
 /*****************************************************************************
@@ -291,6 +291,9 @@ static void Close   ( vlc_object_t *p_this )
     intf_sys_t      *p_sys      = p_intf->p_sys;
     playlist_t      *p_playlist = p_sys->p_playlist;
 
+    vlc_cancel( p_sys->thread );
+    vlc_join( p_sys->thread, NULL );
+
     var_DelCallback( p_playlist, "activity", AllCallback, p_intf );
     var_DelCallback( p_playlist, "intf-change", AllCallback, p_intf );
     var_DelCallback( p_playlist, "volume", AllCallback, p_intf );
@@ -771,8 +774,9 @@ MPRISEntryPoint ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this )
  * Run: main loop
  *****************************************************************************/
 
-static void Run          ( intf_thread_t *p_intf )
+static void *Run( void *data )
 {
+    intf_thread_t *p_intf = data;
     intf_sys_t    *p_sys = p_intf->p_sys;
     mtime_t        i_last_run = mdate();
 
@@ -862,6 +866,7 @@ static void Run          ( intf_thread_t *p_intf )
 
         vlc_restorecancel( canc );
     }
+    assert(0);
 }
 
 static void   wakeup_main_loop( void *p_data )
index fcb84d535cad4c51072a0b945d9d191fe59fb682..2e1c5b9d497b9aa0e6b7b5e8b0ec6350ed429551 100644 (file)
@@ -100,6 +100,7 @@ struct intf_sys_t
     vlc_array_t    *p_watches;
     int             p_pipe_fds[2];
     vlc_mutex_t     lock;
+    vlc_thread_t    thread;
     input_thread_t *p_input;
 
     mtime_t         i_last_input_pos; /* Only access from input thread */