]> git.sesse.net Git - vlc/commitdiff
Merge intf_Create() and intf_RunThread()
authorRémi Denis-Courmont <remi@remlab.net>
Sat, 23 May 2009 17:18:29 +0000 (20:18 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Sat, 23 May 2009 17:18:29 +0000 (20:18 +0300)
Interfaces do not have an event handler that would justify the
separation. Indeed, no caller did anything in-between.

Also, the "primary" reference to the interface object belongs to the
main thread because of the libvlc cleanup procedure. Therefore, the
interface thread pointer really should not be returned to the creator.
Note that this does not really fix the small race condition but it
conceals it within intf_Create() and libvlc_InternalCleanup().

include/vlc_interface.h
modules/access/vcdx/access.c
modules/control/ntservice.c
modules/control/rc.c
src/interface/interface.c
src/libvlc.c
src/libvlccore.sym

index b59bd9da1e6f793129b14945c521a7b758307bec..e368d0bad9aea2aeb64bc3843952f7d62ce6099f 100644 (file)
@@ -98,9 +98,8 @@ struct intf_dialog_args_t
 /*****************************************************************************
  * Prototypes
  *****************************************************************************/
-#define intf_Create(a,b) __intf_Create(VLC_OBJECT(a),b)
-VLC_EXPORT( intf_thread_t *, __intf_Create,     ( vlc_object_t *, const char * ) );
-VLC_EXPORT( int,               intf_RunThread,  ( intf_thread_t * ) );
+VLC_EXPORT( int, intf_Create, ( vlc_object_t *, const char * ) );
+#define intf_Create(a,b) intf_Create(VLC_OBJECT(a),b)
 VLC_EXPORT( void,              intf_StopThread, ( intf_thread_t * ) );
 
 #define intf_Eject(a,b) __intf_Eject(VLC_OBJECT(a),b)
index fa3c4270936e82360aeb09d63d28154f34eedf43..e0eb969905501c05958fc1e42557d4f2d130fcea 100644 (file)
@@ -967,10 +967,6 @@ VCDOpen ( vlc_object_t *p_this )
 #endif
     p_vcdplayer->p_access = p_access;
 
-#ifdef FIXED
-    intf_RunThread( p_vcdplayer->p_intf );
-#endif
-
     free( psz_source );
 
     return VLC_SUCCESS;
index 62b097b23337b246ee82f957e4b1df7a00a02af4..e7104cba01783daab98a72069a058e3c8cfd88f5 100644 (file)
@@ -309,26 +309,14 @@ static void WINAPI ServiceDispatch( DWORD numArgs, char **args )
 
         if( asprintf( &psz_temp, "%s,none", psz_module ) != -1 )
         {
-            intf_thread_t *p_new_intf;
-
             /* Try to create the interface */
-            p_new_intf = intf_Create( p_intf, psz_temp );
-            if( p_new_intf == NULL )
+            if( intf_Create( p_intf, psz_temp ) )
             {
                 msg_Err( p_intf, "interface \"%s\" initialization failed",
                          psz_temp );
                 free( psz_temp );
                 continue;
             }
-
-            /* Try to run the interface */
-            if( intf_RunThread( p_new_intf ) )
-            {
-                vlc_object_detach( p_new_intf );
-                vlc_object_release( p_new_intf );
-                msg_Err( p_intf, "interface \"%s\" cannot run", psz_temp );
-            }
-
             free( psz_temp );
         }
     }
index c1602eab17c38255dc86ce9f0b17842e0fbba848..843096d043dd0923b0fffdfc177f9571a45d421e 100644 (file)
@@ -1525,19 +1525,8 @@ static int Intf( vlc_object_t *p_this, char const *psz_cmd,
                  vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
     VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
-    intf_thread_t *p_newintf = NULL;
 
-    p_newintf = intf_Create( p_this->p_libvlc, newval.psz_string );
-    if( p_newintf )
-    {
-        if( intf_RunThread( p_newintf ) )
-        {
-            vlc_object_detach( p_newintf );
-            vlc_object_release( p_newintf );
-        }
-    }
-
-    return VLC_SUCCESS;
+    return intf_Create( p_this->p_libvlc, newval.psz_string );
 }
 
 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
index c48986a1f65880de085d95872e4b2939a5d94a12..105783ccb0e26ec59ba60151e45700c721e38be4 100644 (file)
@@ -72,22 +72,26 @@ static void intf_Destroy( vlc_object_t *obj )
 }
 
 
+#undef intf_Create
 /**
- * Create the interface, and prepare it for main loop. It opens ouput device
- * and creates specific interfaces. Sends its own error messages.
+ * Create and start an interface.
  *
  * @param p_this the calling vlc_object_t
  * @param psz_module a preferred interface module
- * @return a pointer to the created interface thread, NULL on error
+ * @return VLC_SUCCESS or an error code
  */
-intf_thread_t* __intf_Create( vlc_object_t *p_this, const char *psz_module )
+int intf_Create( vlc_object_t *p_this, const char *psz_module )
 {
     intf_thread_t * p_intf;
 
     /* Allocate structure */
     p_intf = vlc_object_create( p_this, VLC_OBJECT_INTF );
     if( !p_intf )
-        return NULL;
+        return VLC_ENOMEM;
+
+    /* Attach interface to its parent object */
+    vlc_object_attach( p_intf, p_this );
+    vlc_object_set_destructor( p_intf, intf_Destroy );
 #if defined( __APPLE__ ) || defined( WIN32 )
     p_intf->b_should_run_on_first_thread = false;
 #endif
@@ -102,31 +106,13 @@ intf_thread_t* __intf_Create( vlc_object_t *p_this, const char *psz_module )
     free( psz_tmp );
     free( psz_parser );
     p_intf->p_module = module_need( p_intf, "interface", p_intf->psz_intf, true );
-
     if( p_intf->p_module == NULL )
     {
         msg_Err( p_intf, "no suitable interface module" );
-        free( p_intf->psz_intf );
         vlc_object_release( p_intf );
-        return NULL;
+        return VLC_EGENERIC;
     }
 
-    /* Attach interface to its parent object */
-    vlc_object_attach( p_intf, p_this );
-    vlc_object_set_destructor( p_intf, intf_Destroy );
-
-    return p_intf;
-}
-
-
-/**
- * Starts and runs the interface thread.
- *
- * @param p_intf the interface thread
- * @return VLC_SUCCESS on success, an error number else
- */
-int intf_RunThread( intf_thread_t *p_intf )
-{
 #if defined( __APPLE__ ) || defined( WIN32 )
     /* Hack to get Mac OS X Cocoa runtime running
      * (it needs access to the main thread) */
@@ -136,7 +122,8 @@ int intf_RunThread( intf_thread_t *p_intf )
                                VLC_THREAD_PRIORITY_LOW ) )
         {
             msg_Err( p_intf, "cannot spawn libvlc death monitoring thread" );
-            return VLC_EGENERIC;
+            vlc_object_release( p_intf );
+            return VLC_ENOMEM;
         }
         RunInterface( VLC_OBJECT(p_intf) );
 
@@ -156,6 +143,7 @@ int intf_RunThread( intf_thread_t *p_intf )
                            VLC_THREAD_PRIORITY_LOW ) )
     {
         msg_Err( p_intf, "cannot spawn interface thread" );
+        vlc_object_release( p_intf );
         return VLC_EGENERIC;
     }
 
@@ -250,30 +238,16 @@ static int AddIntfCallback( vlc_object_t *p_this, char const *psz_cmd,
                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
     (void)psz_cmd; (void)oldval; (void)p_data;
-    intf_thread_t *p_intf;
     char* psz_intf;
 
     /* Try to create the interface */
     if( asprintf( &psz_intf, "%s,none", newval.psz_string ) == -1 )
         return VLC_ENOMEM;
 
-    p_intf = intf_Create( p_this->p_libvlc, psz_intf );
+    int ret = intf_Create( p_this->p_libvlc, psz_intf );
     free( psz_intf );
-    if( p_intf == NULL )
-    {
+    if( ret )
         msg_Err( p_this, "interface \"%s\" initialization failed",
                  newval.psz_string );
-        return VLC_EGENERIC;
-    }
-
-    /* Try to run the interface */
-    if( intf_RunThread( p_intf ) != VLC_SUCCESS )
-    {
-        vlc_object_detach( p_intf );
-        vlc_object_release( p_intf );
-        return VLC_EGENERIC;
-    }
-
-    return VLC_SUCCESS;
+    return ret;
 }
-
index 0fb54b02469b35346f7f80fbfa0fd2207009d535..e9e0b0435e034e3450a466dbad33584d71d420f0 100644 (file)
@@ -1138,7 +1138,6 @@ void libvlc_InternalDestroy( libvlc_int_t *p_libvlc )
  */
 int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, char const *psz_module )
 {
-    int i_err;
     intf_thread_t *p_intf = NULL;
 
     if( !p_libvlc )
@@ -1164,25 +1163,14 @@ int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, char const *psz_module )
     }
 
     /* Try to create the interface */
-    p_intf = intf_Create( p_libvlc, psz_module ? psz_module : "$intf" );
-    if( p_intf == NULL )
+    if( intf_Create( p_libvlc, psz_module ? psz_module : "$intf" ) )
     {
         msg_Err( p_libvlc, "interface \"%s\" initialization failed",
                  psz_module );
         return VLC_EGENERIC;
     }
-
-    /* Try to run the interface */
-    i_err = intf_RunThread( p_intf );
-    if( i_err )
-    {
-        vlc_object_detach( p_intf );
-        vlc_object_release( p_intf );
-        return i_err;
-    }
-
     return VLC_SUCCESS;
-};
+}
 
 static vlc_mutex_t exit_lock = VLC_STATIC_MUTEX;
 
index 3f1df055f87f2f0ed98a7f44123aabe4bb6064f0..01742744046c7c15641a79bf1013230611c8345d 100644 (file)
@@ -203,9 +203,8 @@ input_SplitMRL
 input_Start
 input_Stop
 input_vaControl
-__intf_Create
+intf_Create
 __intf_Eject
-intf_RunThread
 intf_StopThread
 IsUTF8
 libvlc_InternalAddIntf