Commit 4a4dc6df authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Merge intf_Create() and intf_RunThread()

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().
parent 94324e9f
...@@ -98,9 +98,8 @@ struct intf_dialog_args_t ...@@ -98,9 +98,8 @@ struct intf_dialog_args_t
/***************************************************************************** /*****************************************************************************
* Prototypes * Prototypes
*****************************************************************************/ *****************************************************************************/
#define intf_Create(a,b) __intf_Create(VLC_OBJECT(a),b) VLC_EXPORT( int, intf_Create, ( vlc_object_t *, const char * ) );
VLC_EXPORT( intf_thread_t *, __intf_Create, ( vlc_object_t *, const char * ) ); #define intf_Create(a,b) intf_Create(VLC_OBJECT(a),b)
VLC_EXPORT( int, intf_RunThread, ( intf_thread_t * ) );
VLC_EXPORT( void, intf_StopThread, ( intf_thread_t * ) ); VLC_EXPORT( void, intf_StopThread, ( intf_thread_t * ) );
#define intf_Eject(a,b) __intf_Eject(VLC_OBJECT(a),b) #define intf_Eject(a,b) __intf_Eject(VLC_OBJECT(a),b)
......
...@@ -967,10 +967,6 @@ VCDOpen ( vlc_object_t *p_this ) ...@@ -967,10 +967,6 @@ VCDOpen ( vlc_object_t *p_this )
#endif #endif
p_vcdplayer->p_access = p_access; p_vcdplayer->p_access = p_access;
#ifdef FIXED
intf_RunThread( p_vcdplayer->p_intf );
#endif
free( psz_source ); free( psz_source );
return VLC_SUCCESS; return VLC_SUCCESS;
......
...@@ -309,26 +309,14 @@ static void WINAPI ServiceDispatch( DWORD numArgs, char **args ) ...@@ -309,26 +309,14 @@ static void WINAPI ServiceDispatch( DWORD numArgs, char **args )
if( asprintf( &psz_temp, "%s,none", psz_module ) != -1 ) if( asprintf( &psz_temp, "%s,none", psz_module ) != -1 )
{ {
intf_thread_t *p_new_intf;
/* Try to create the interface */ /* Try to create the interface */
p_new_intf = intf_Create( p_intf, psz_temp ); if( intf_Create( p_intf, psz_temp ) )
if( p_new_intf == NULL )
{ {
msg_Err( p_intf, "interface \"%s\" initialization failed", msg_Err( p_intf, "interface \"%s\" initialization failed",
psz_temp ); psz_temp );
free( psz_temp ); free( psz_temp );
continue; 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 ); free( psz_temp );
} }
} }
......
...@@ -1525,19 +1525,8 @@ static int Intf( vlc_object_t *p_this, char const *psz_cmd, ...@@ -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_value_t oldval, vlc_value_t newval, void *p_data )
{ {
VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(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 ); return 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;
} }
static int Volume( vlc_object_t *p_this, char const *psz_cmd, static int Volume( vlc_object_t *p_this, char const *psz_cmd,
......
...@@ -72,22 +72,26 @@ static void intf_Destroy( vlc_object_t *obj ) ...@@ -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 * Create and start an interface.
* and creates specific interfaces. Sends its own error messages.
* *
* @param p_this the calling vlc_object_t * @param p_this the calling vlc_object_t
* @param psz_module a preferred interface module * @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; intf_thread_t * p_intf;
/* Allocate structure */ /* Allocate structure */
p_intf = vlc_object_create( p_this, VLC_OBJECT_INTF ); p_intf = vlc_object_create( p_this, VLC_OBJECT_INTF );
if( !p_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 ) #if defined( __APPLE__ ) || defined( WIN32 )
p_intf->b_should_run_on_first_thread = false; p_intf->b_should_run_on_first_thread = false;
#endif #endif
...@@ -102,31 +106,13 @@ intf_thread_t* __intf_Create( vlc_object_t *p_this, const char *psz_module ) ...@@ -102,31 +106,13 @@ intf_thread_t* __intf_Create( vlc_object_t *p_this, const char *psz_module )
free( psz_tmp ); free( psz_tmp );
free( psz_parser ); free( psz_parser );
p_intf->p_module = module_need( p_intf, "interface", p_intf->psz_intf, true ); p_intf->p_module = module_need( p_intf, "interface", p_intf->psz_intf, true );
if( p_intf->p_module == NULL ) if( p_intf->p_module == NULL )
{ {
msg_Err( p_intf, "no suitable interface module" ); msg_Err( p_intf, "no suitable interface module" );
free( p_intf->psz_intf );
vlc_object_release( p_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 ) #if defined( __APPLE__ ) || defined( WIN32 )
/* Hack to get Mac OS X Cocoa runtime running /* Hack to get Mac OS X Cocoa runtime running
* (it needs access to the main thread) */ * (it needs access to the main thread) */
...@@ -136,7 +122,8 @@ int intf_RunThread( intf_thread_t *p_intf ) ...@@ -136,7 +122,8 @@ int intf_RunThread( intf_thread_t *p_intf )
VLC_THREAD_PRIORITY_LOW ) ) VLC_THREAD_PRIORITY_LOW ) )
{ {
msg_Err( p_intf, "cannot spawn libvlc death monitoring thread" ); 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) ); RunInterface( VLC_OBJECT(p_intf) );
...@@ -156,6 +143,7 @@ int intf_RunThread( intf_thread_t *p_intf ) ...@@ -156,6 +143,7 @@ int intf_RunThread( intf_thread_t *p_intf )
VLC_THREAD_PRIORITY_LOW ) ) VLC_THREAD_PRIORITY_LOW ) )
{ {
msg_Err( p_intf, "cannot spawn interface thread" ); msg_Err( p_intf, "cannot spawn interface thread" );
vlc_object_release( p_intf );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -250,30 +238,16 @@ static int AddIntfCallback( vlc_object_t *p_this, char const *psz_cmd, ...@@ -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 ) vlc_value_t oldval, vlc_value_t newval, void *p_data )
{ {
(void)psz_cmd; (void)oldval; (void)p_data; (void)psz_cmd; (void)oldval; (void)p_data;
intf_thread_t *p_intf;
char* psz_intf; char* psz_intf;
/* Try to create the interface */ /* Try to create the interface */
if( asprintf( &psz_intf, "%s,none", newval.psz_string ) == -1 ) if( asprintf( &psz_intf, "%s,none", newval.psz_string ) == -1 )
return VLC_ENOMEM; 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 ); free( psz_intf );
if( p_intf == NULL ) if( ret )
{
msg_Err( p_this, "interface \"%s\" initialization failed", msg_Err( p_this, "interface \"%s\" initialization failed",
newval.psz_string ); newval.psz_string );
return VLC_EGENERIC; return ret;
}
/* 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;
} }
...@@ -1138,7 +1138,6 @@ void libvlc_InternalDestroy( libvlc_int_t *p_libvlc ) ...@@ -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 libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, char const *psz_module )
{ {
int i_err;
intf_thread_t *p_intf = NULL; intf_thread_t *p_intf = NULL;
if( !p_libvlc ) if( !p_libvlc )
...@@ -1164,25 +1163,14 @@ int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, char const *psz_module ) ...@@ -1164,25 +1163,14 @@ int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, char const *psz_module )
} }
/* Try to create the interface */ /* Try to create the interface */
p_intf = intf_Create( p_libvlc, psz_module ? psz_module : "$intf" ); if( intf_Create( p_libvlc, psz_module ? psz_module : "$intf" ) )
if( p_intf == NULL )
{ {
msg_Err( p_libvlc, "interface \"%s\" initialization failed", msg_Err( p_libvlc, "interface \"%s\" initialization failed",
psz_module ); psz_module );
return VLC_EGENERIC; 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; return VLC_SUCCESS;
}; }
static vlc_mutex_t exit_lock = VLC_STATIC_MUTEX; static vlc_mutex_t exit_lock = VLC_STATIC_MUTEX;
......
...@@ -203,9 +203,8 @@ input_SplitMRL ...@@ -203,9 +203,8 @@ input_SplitMRL
input_Start input_Start
input_Stop input_Stop
input_vaControl input_vaControl
__intf_Create intf_Create
__intf_Eject __intf_Eject
intf_RunThread
intf_StopThread intf_StopThread
IsUTF8 IsUTF8
libvlc_InternalAddIntf libvlc_InternalAddIntf
......
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