[vlc-devel] commit: Extensions: fix extensions manager's locking scheme ( Jean-Philippe André )
git version control
git at videolan.org
Thu Jan 28 16:22:14 CET 2010
vlc | branch: master | Jean-Philippe André <jpeg at videolan.org> | Thu Jan 28 12:07:15 2010 +0100| [9f49f1112e688ca366b6881172eedb604851f416] | committer: Jean-Philippe André
Extensions: fix extensions manager's locking scheme
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9f49f1112e688ca366b6881172eedb604851f416
---
include/vlc_extensions.h | 1 +
modules/misc/lua/extension.c | 20 ++++++++++----------
modules/misc/lua/extension.h | 5 ++++-
modules/misc/lua/extension_thread.c | 2 ++
4 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/include/vlc_extensions.h b/include/vlc_extensions.h
index c86098f..7f294fc 100644
--- a/include/vlc_extensions.h
+++ b/include/vlc_extensions.h
@@ -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 );
diff --git a/modules/misc/lua/extension.c b/modules/misc/lua/extension.c
index 04931c9..2e69f4c 100644
--- a/modules/misc/lua/extension.c
+++ b/modules/misc/lua/extension.c
@@ -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;
}
diff --git a/modules/misc/lua/extension.h b/modules/misc/lua/extension.h
index 99b850a..bf15b70 100644
--- a/modules/misc/lua/extension.h
+++ b/modules/misc/lua/extension.h
@@ -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;
};
diff --git a/modules/misc/lua/extension_thread.c b/modules/misc/lua/extension_thread.c
index 5661211..1d569e9 100644
--- a/modules/misc/lua/extension_thread.c
+++ b/modules/misc/lua/extension_thread.c
@@ -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 ) );
More information about the vlc-devel
mailing list