Commit 9f49f111 authored by Jean-Philippe André's avatar Jean-Philippe André

Extensions: fix extensions manager's locking scheme

parent dbd4f0cc
......@@ -48,6 +48,7 @@ struct extensions_manager_t
extensions_manager_sys_t *p_sys; /**< Reserved for the module */
DECL_ARRAY(extension_t*) extensions; /**< Array of extension descriptors */
vlc_mutex_t lock; /**< A lock for the extensions array */
/** Control, see extension_Control */
int ( *pf_control ) ( extensions_manager_t*, int, va_list );
......
......@@ -85,6 +85,7 @@ int Open_Extension( vlc_object_t *p_this )
p_mgr->p_sys = p_sys;
ARRAY_INIT( p_sys->activated_extensions );
ARRAY_INIT( p_mgr->extensions );
vlc_mutex_init( &p_mgr->lock );
vlc_mutex_init( &p_mgr->p_sys->lock );
/* Initialise Lua state structure */
......@@ -106,8 +107,6 @@ int Open_Extension( vlc_object_t *p_this )
lua_close( L );
p_sys->L = NULL;
vlc_mutex_init( &p_sys->lock );
// Create the dialog-event variable
var_Create( p_this, "dialog-event", VLC_VAR_ADDRESS );
var_AddCallback( p_this, "dialog-event",
......@@ -124,9 +123,11 @@ void Close_Extension( vlc_object_t *p_this )
extensions_manager_t *p_mgr = ( extensions_manager_t* ) p_this;
msg_Dbg( p_mgr, "Deactivating all loaded extensions" );
vlc_mutex_lock( &p_mgr->p_sys->lock );
vlc_mutex_lock( &p_mgr->lock );
p_mgr->p_sys->b_killed = true;
vlc_mutex_unlock( &p_mgr->p_sys->lock );
vlc_mutex_unlock( &p_mgr->lock );
var_Destroy( p_mgr, "dialog-event" );
extension_t *p_ext = NULL;
FOREACH_ARRAY( p_ext, p_mgr->p_sys->activated_extensions )
......@@ -143,6 +144,7 @@ void Close_Extension( vlc_object_t *p_this )
if( p_mgr->p_sys && p_mgr->p_sys->L )
lua_close( p_mgr->p_sys->L );
vlc_mutex_destroy( &p_mgr->lock );
vlc_mutex_destroy( &p_mgr->p_sys->lock );
free( p_mgr->p_sys );
p_mgr->p_sys = NULL;
......@@ -167,8 +169,6 @@ void Close_Extension( vlc_object_t *p_this )
FOREACH_END()
ARRAY_RESET( p_mgr->extensions );
var_Destroy( p_mgr, "dialog-event" );
}
/**
......@@ -205,13 +205,13 @@ int ScanLuaCallback( vlc_object_t *p_this, const char *psz_script,
msg_Dbg( p_mgr, "Scanning Lua script %s", psz_script );
vlc_mutex_lock( &p_mgr->p_sys->lock );
vlc_mutex_lock( &p_mgr->lock );
/* Create new script descriptor */
extension_t *p_ext = ( extension_t* ) calloc( 1, sizeof( extension_t ) );
if( !p_ext )
{
vlc_mutex_unlock( &p_mgr->p_sys->lock );
vlc_mutex_unlock( &p_mgr->lock );
return 0;
}
......@@ -222,7 +222,7 @@ int ScanLuaCallback( vlc_object_t *p_this, const char *psz_script,
free( p_ext->psz_name );
free( p_ext->p_sys );
free( p_ext );
vlc_mutex_unlock( &p_mgr->p_sys->lock );
vlc_mutex_unlock( &p_mgr->lock );
return 0;
}
p_ext->p_sys->p_mgr = p_mgr;
......@@ -350,7 +350,7 @@ exit:
ARRAY_APPEND( p_mgr->extensions, p_ext );
}
vlc_mutex_unlock( &p_mgr->p_sys->lock );
vlc_mutex_unlock( &p_mgr->lock );
/* Continue batch execution */
return pb_continue ? ( (* (bool*)pb_continue) ? -1 : 0 ) : -1;
}
......
......@@ -42,10 +42,13 @@ struct extensions_manager_sys_t
/* List of activated extensions */
DECL_ARRAY( extension_t* ) activated_extensions;
/* Lock for this list */
vlc_mutex_t lock;
/* Lua specific */
lua_State *L;
vlc_mutex_t lock;
/* Flag indicating that the module is about to be unloaded */
bool b_killed;
};
......
......@@ -60,7 +60,9 @@ int Activate( extensions_manager_t *p_mgr, extension_t *p_ext )
}
/* Add this script to the activated extensions list */
vlc_mutex_lock( &p_mgr->p_sys->lock );
ARRAY_APPEND( p_mgr->p_sys->activated_extensions, p_ext );
vlc_mutex_unlock( &p_mgr->p_sys->lock );
/* Prepare first command */
p_sys->command = calloc( 1, sizeof( struct command_t ) );
......
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