vlc | branch: master | Hugo Beauzée-Luyssen <[email protected]> | Wed Mar 29 16:27:39 2017 +0200| [04da2f7345a60b2f061f8b3868a42b976476aa2d] | committer: Hugo Beauzée-Luyssen
lua: Simplify activated extension detection > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=04da2f7345a60b2f061f8b3868a42b976476aa2d --- modules/lua/extension.c | 47 +++++++++-------------- modules/lua/extension.h | 14 +------ modules/lua/extension_thread.c | 87 ++++++------------------------------------ 3 files changed, 29 insertions(+), 119 deletions(-) diff --git a/modules/lua/extension.c b/modules/lua/extension.c index bc9f76d..e6612e9 100644 --- a/modules/lua/extension.c +++ b/modules/lua/extension.c @@ -102,15 +102,8 @@ int Open_Extension( vlc_object_t *p_this ) p_mgr->pf_control = Control; - extensions_manager_sys_t *p_sys = ( extensions_manager_sys_t* ) - calloc( 1, sizeof( extensions_manager_sys_t ) ); - if( !p_sys ) return VLC_ENOMEM; - - p_mgr->p_sys = p_sys; - ARRAY_INIT( p_sys->activated_extensions ); - ARRAY_INIT( p_mgr->extensions ); + p_mgr->p_sys = NULL; vlc_mutex_init( &p_mgr->lock ); - vlc_mutex_init( &p_mgr->p_sys->lock ); /* Scan available Lua Extensions */ if( ScanExtensions( p_mgr ) != VLC_SUCCESS ) @@ -133,33 +126,26 @@ int Open_Extension( vlc_object_t *p_this ) 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->lock ); - p_mgr->p_sys->b_killed = true; - vlc_mutex_unlock( &p_mgr->lock ); var_DelCallback( p_this, "dialog-event", vlclua_extension_dialog_callback, NULL ); var_Destroy( p_mgr, "dialog-event" ); extension_t *p_ext = NULL; - FOREACH_ARRAY( p_ext, p_mgr->p_sys->activated_extensions ) - { - if( !p_ext ) break; - msg_Dbg( p_mgr, "Deactivating '%s'", p_ext->psz_title ); - Deactivate( p_mgr, p_ext ); - } - FOREACH_END() - - msg_Dbg( p_mgr, "All extensions are now deactivated" ); - ARRAY_RESET( p_mgr->p_sys->activated_extensions ); /* Free extensions' memory */ FOREACH_ARRAY( p_ext, p_mgr->extensions ) { if( !p_ext ) break; + + vlc_mutex_lock( &p_ext->p_sys->command_lock ); + bool b_activated = p_ext->p_sys->b_activated; + vlc_mutex_unlock( &p_ext->p_sys->command_lock ); + + if( b_activated == true ) + Deactivate( p_mgr, p_ext ); + if( p_ext->p_sys->b_thread_running == true ) vlc_join( p_ext->p_sys->thread, NULL ); @@ -190,9 +176,6 @@ void Close_Extension( vlc_object_t *p_this ) FOREACH_END() vlc_mutex_destroy( &p_mgr->lock ); - vlc_mutex_destroy( &p_mgr->p_sys->lock ); - free( p_mgr->p_sys ); - p_mgr->p_sys = NULL; ARRAY_RESET( p_mgr->extensions ); } @@ -532,7 +515,9 @@ static int Control( extensions_manager_t *p_mgr, int i_control, va_list args ) case EXTENSION_IS_ACTIVATED: p_ext = ( extension_t* ) va_arg( args, extension_t* ); pb = ( bool* ) va_arg( args, bool* ); - *pb = IsActivated( p_mgr, p_ext ); + vlc_mutex_lock( &p_ext->p_sys->command_lock ); + *pb = p_ext->p_sys->b_activated; + vlc_mutex_unlock( &p_ext->p_sys->command_lock ); break; case EXTENSION_HAS_MENU: @@ -651,8 +636,7 @@ int lua_ExtensionDeactivate( extensions_manager_t *p_mgr, extension_t *p_ext ) { assert( p_mgr != NULL && p_ext != NULL ); - // b_exiting will be set to true once the entire tear down has been completed - if( p_ext->p_sys->b_exiting == true ) + if( p_ext->p_sys->b_activated == false ) return VLC_SUCCESS; vlclua_fd_interrupt( &p_ext->p_sys->dtable ); @@ -703,11 +687,14 @@ static int GetMenuEntries( extensions_manager_t *p_mgr, extension_t *p_ext, assert( *pppsz_titles == NULL ); assert( *ppi_ids == NULL ); - if( !IsActivated( p_mgr, p_ext ) ) + vlc_mutex_lock( &p_ext->p_sys->command_lock ); + if( p_ext->p_sys->b_activated == false ) { + vlc_mutex_unlock( &p_ext->p_sys->command_lock ); msg_Dbg( p_mgr, "Can't get menu before activating the extension!" ); return VLC_EGENERIC; } + vlc_mutex_unlock( &p_ext->p_sys->command_lock ); if( !LockExtension( p_ext ) ) { diff --git a/modules/lua/extension.h b/modules/lua/extension.h index beaed15..5971ea7 100644 --- a/modules/lua/extension.h +++ b/modules/lua/extension.h @@ -51,18 +51,6 @@ typedef enum LUA_TEXT } lua_datatype_e; -struct extensions_manager_sys_t -{ - /* List of activated extensions */ - DECL_ARRAY( extension_t* ) activated_extensions; - - /* Lock for this list */ - vlc_mutex_t lock; - - /* Flag indicating that the module is about to be unloaded */ - bool b_killed; -}; - struct extension_sys_t { /* Extension general */ @@ -99,11 +87,11 @@ struct extension_sys_t bool b_exiting; bool b_thread_running; //< Only accessed out of the extension thread. + bool b_activated; ///< Protected by the command lock }; /* Extensions: manager functions */ int Activate( extensions_manager_t *p_mgr, extension_t * ); -bool IsActivated( extensions_manager_t *p_mgr, extension_t * ); int Deactivate( extensions_manager_t *p_mgr, extension_t * ); void KillExtension( extensions_manager_t *p_mgr, extension_t *p_ext ); int PushCommand__( extension_t *ext, bool unique, command_type_e cmd, va_list options ); diff --git a/modules/lua/extension_thread.c b/modules/lua/extension_thread.c index 13b4221..ef66edc 100644 --- a/modules/lua/extension_thread.c +++ b/modules/lua/extension_thread.c @@ -38,7 +38,6 @@ struct thread_sys_t /** Thread Run */ static void* Run( void *data ); static void FreeCommands( struct command_t *command ); -static int RemoveActivated( extensions_manager_t *p_mgr, extension_t *p_ext ); /** * Activate an extension @@ -55,16 +54,8 @@ int Activate( extensions_manager_t *p_mgr, extension_t *p_ext ) msg_Dbg( p_mgr, "Activating extension '%s'", p_ext->psz_title ); - if( IsActivated( p_mgr, p_ext ) ) - { - msg_Warn( p_mgr, "Extension is already activated!" ); - return VLC_EGENERIC; - } - - /* 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 ); + if (p_sys->b_thread_running == true) + return VLC_SUCCESS; /* Prepare first command */ p_sys->command = calloc( 1, sizeof( struct command_t ) ); @@ -87,32 +78,6 @@ int Activate( extensions_manager_t *p_mgr, extension_t *p_ext ) return VLC_SUCCESS; } -/** Look for an extension in the activated extensions list - * @todo FIXME Should be entered with the lock held - **/ -bool IsActivated( extensions_manager_t *p_mgr, extension_t *p_ext ) -{ - assert( p_ext != NULL ); - vlc_mutex_lock( &p_mgr->p_sys->lock ); - - extension_t *p_iter; - FOREACH_ARRAY( p_iter, p_mgr->p_sys->activated_extensions ) - { - if( !p_iter ) - break; - assert( p_iter->psz_name != NULL ); - if( !strcmp( p_iter->psz_name, p_ext->psz_name ) ) - { - vlc_mutex_unlock( &p_mgr->p_sys->lock ); - return true; - } - } - FOREACH_END() - - vlc_mutex_unlock( &p_mgr->p_sys->lock ); - return false; -} - /** Recursively drop and free commands starting from "command" */ static void FreeCommands( struct command_t *command ) { @@ -176,52 +141,16 @@ int Deactivate( extensions_manager_t *p_mgr, extension_t *p_ext ) return VLC_SUCCESS; } -/** Remove an extension from the activated list */ -static int RemoveActivated( extensions_manager_t *p_mgr, extension_t *p_ext ) -{ - if( p_mgr->p_sys->b_killed ) - return VLC_SUCCESS; - vlc_mutex_lock( &p_mgr->p_sys->lock ); - - int i_idx = -1; - extension_t *p_iter; - FOREACH_ARRAY( p_iter, p_mgr->p_sys->activated_extensions ) - { - i_idx++; - if( !p_iter ) - { - i_idx = -1; - break; - } - assert( p_iter->psz_name != NULL ); - if( !strcmp( p_iter->psz_name, p_ext->psz_name ) ) - break; - } - FOREACH_END() - - if( i_idx >= 0 ) - { - ARRAY_REMOVE( p_mgr->p_sys->activated_extensions, i_idx ); - } - else - { - msg_Dbg( p_mgr, "Can't find extension '%s' in the activated list", - p_ext->psz_title ); - } - - vlc_mutex_unlock( &p_mgr->p_sys->lock ); - return (i_idx >= 0) ? VLC_SUCCESS : VLC_EGENERIC; -} - void KillExtension( extensions_manager_t *p_mgr, extension_t *p_ext ) { msg_Dbg( p_mgr, "Killing extension now" ); lua_ExtensionDeactivate( p_mgr, p_ext ); + vlc_mutex_lock( &p_ext->p_sys->command_lock ); + p_ext->p_sys->b_activated = false; p_ext->p_sys->b_exiting = true; vlc_cond_signal( &p_ext->p_sys->wait ); vlc_mutex_unlock( &p_ext->p_sys->command_lock ); - RemoveActivated( p_mgr, p_ext ); } /** Push a UI command */ @@ -347,7 +276,11 @@ static void* Run( void *data ) { msg_Err( p_mgr, "Could not activate extension!" ); Deactivate( p_mgr, p_ext ); + break; } + vlc_mutex_lock( &p_ext->p_sys->command_lock ); + p_ext->p_sys->b_activated = true; + vlc_mutex_unlock( &p_ext->p_sys->command_lock ); break; } @@ -359,8 +292,10 @@ static void* Run( void *data ) msg_Warn( p_mgr, "Extension '%s' did not deactivate properly", p_ext->psz_title ); } + vlc_mutex_lock( &p_ext->p_sys->command_lock ); p_ext->p_sys->b_exiting = true; - RemoveActivated( p_mgr, p_ext ); + p_ext->p_sys->b_activated = false; + vlc_mutex_unlock( &p_ext->p_sys->command_lock ); break; } _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
