vlc | branch: master | Hugo Beauzée-Luyssen <[email protected]> | Thu Mar 30 11:14:27 2017 +0200| [6e17f399bb7e642e5f9f8eaffe0f14be59b708df] | committer: Hugo Beauzée-Luyssen
lua: Remove dubious LockExtension/UnlockExtension > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6e17f399bb7e642e5f9f8eaffe0f14be59b708df --- modules/lua/extension.c | 53 +++++----------- modules/lua/extension.h | 2 - modules/lua/extension_thread.c | 139 ++++++++++++++++++++--------------------- 3 files changed, 84 insertions(+), 110 deletions(-) diff --git a/modules/lua/extension.c b/modules/lua/extension.c index a3616ad..36bfcdb 100644 --- a/modules/lua/extension.c +++ b/modules/lua/extension.c @@ -565,8 +565,17 @@ static int Control( extensions_manager_t *p_mgr, int i_control, va_list args ) p_ext = ( extension_t* ) va_arg( args, extension_t* ); input_thread_t *p_input = va_arg( args, struct input_thread_t * ); - if( !LockExtension( p_ext ) ) + if( p_ext == NULL ) + return VLC_EGENERIC; + vlc_mutex_lock( &p_ext->p_sys->command_lock ); + if ( p_ext->p_sys->b_exiting == true ) + { + vlc_mutex_unlock( &p_ext->p_sys->command_lock ); return VLC_EGENERIC; + } + vlc_mutex_unlock( &p_ext->p_sys->command_lock ); + + vlc_mutex_lock( &p_ext->p_sys->running_lock ); // Change input input_thread_t *old = p_ext->p_sys->p_input; @@ -607,7 +616,7 @@ static int Control( extensions_manager_t *p_mgr, int i_control, va_list args ) p_ext ); } - UnlockExtension( p_ext ); + vlc_mutex_unlock( &p_ext->p_sys->running_lock ); break; } case EXTENSION_PLAYING_CHANGED: @@ -700,19 +709,15 @@ static int GetMenuEntries( extensions_manager_t *p_mgr, extension_t *p_ext, assert( *ppi_ids == NULL ); vlc_mutex_lock( &p_ext->p_sys->command_lock ); - if( p_ext->p_sys->b_activated == false ) + if( p_ext->p_sys->b_activated == false || p_ext->p_sys->b_exiting == true ) { vlc_mutex_unlock( &p_ext->p_sys->command_lock ); - msg_Dbg( p_mgr, "Can't get menu before activating the extension!" ); + msg_Dbg( p_mgr, "Can't get menu of an unactivated/dying extension!" ); return VLC_EGENERIC; } vlc_mutex_unlock( &p_ext->p_sys->command_lock ); - if( !LockExtension( p_ext ) ) - { - /* Dying extension, fail. */ - return VLC_EGENERIC; - } + vlc_mutex_lock( &p_ext->p_sys->running_lock ); int i_ret = VLC_EGENERIC; lua_State *L = GetLuaState( p_mgr, p_ext ); @@ -783,7 +788,7 @@ static int GetMenuEntries( extensions_manager_t *p_mgr, extension_t *p_ext, i_ret = VLC_SUCCESS; exit: - UnlockExtension( p_ext ); + vlc_mutex_unlock( &p_ext->p_sys->running_lock ); if( i_ret != VLC_SUCCESS ) { msg_Dbg( p_mgr, "Something went wrong in %s (%s:%d)", @@ -1141,34 +1146,6 @@ static void inputItemMetaChanged( const vlc_event_t *p_event, PushCommandUnique( p_ext, CMD_UPDATE_META ); } -/** Lock this extension. Can fail. */ -bool LockExtension( extension_t *p_ext ) -{ - vlc_mutex_lock( &p_ext->p_sys->command_lock ); - if( p_ext->p_sys->b_exiting ) - { - vlc_mutex_unlock( &p_ext->p_sys->command_lock ); - return false; - } - - vlc_mutex_lock( &p_ext->p_sys->running_lock ); - if( p_ext->p_sys->b_exiting ) - { - vlc_mutex_unlock( &p_ext->p_sys->running_lock ); - vlc_mutex_unlock( &p_ext->p_sys->command_lock ); - return false; - } - - vlc_mutex_unlock( &p_ext->p_sys->command_lock ); - return true; -} - -/** Unlock this extension. */ -void UnlockExtension( extension_t *p_ext ) -{ - vlc_mutex_unlock( &p_ext->p_sys->running_lock ); -} - /** Watch timer callback * The timer expired, Lua may be stuck, ask the user what to do now **/ diff --git a/modules/lua/extension.h b/modules/lua/extension.h index a6ab6a6..2897991 100644 --- a/modules/lua/extension.h +++ b/modules/lua/extension.h @@ -112,8 +112,6 @@ static inline int PushCommandUnique( extension_t *ext, int cmd, ... ) va_end( args ); return i_ret; } -bool LockExtension( extension_t *p_ext ); -void UnlockExtension( extension_t *p_ext ); /* Lua specific functions */ void vlclua_extension_set( lua_State *L, extension_t * ); diff --git a/modules/lua/extension_thread.c b/modules/lua/extension_thread.c index 99b87c3..03c3d64 100644 --- a/modules/lua/extension_thread.c +++ b/modules/lua/extension_thread.c @@ -288,97 +288,96 @@ static void* Run( void *data ) vlc_mutex_unlock( &p_ext->p_sys->command_lock ); /* Run command */ - if( LockExtension( p_ext ) ) + vlc_mutex_lock( &p_ext->p_sys->running_lock ); + switch( cmd->i_command ) { - switch( cmd->i_command ) + case CMD_ACTIVATE: { - case CMD_ACTIVATE: + if( lua_ExecuteFunction( p_mgr, p_ext, "activate", LUA_END ) < 0 ) { - if( lua_ExecuteFunction( p_mgr, p_ext, "activate", LUA_END ) < 0 ) - { - msg_Err( p_mgr, "Could not activate extension!" ); - vlc_mutex_lock( &p_ext->p_sys->command_lock ); - QueueDeactivateCommand( p_ext ); - vlc_mutex_unlock( &p_ext->p_sys->command_lock ); - break; - } + msg_Err( p_mgr, "Could not activate extension!" ); vlc_mutex_lock( &p_ext->p_sys->command_lock ); - p_ext->p_sys->b_activated = true; + QueueDeactivateCommand( p_ext ); vlc_mutex_unlock( &p_ext->p_sys->command_lock ); 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; + } - case CMD_DEACTIVATE: + case CMD_DEACTIVATE: + { + msg_Dbg( p_mgr, "Deactivating '%s'", p_ext->psz_title ); + if( lua_ExtensionDeactivate( p_mgr, p_ext ) < 0 ) { - msg_Dbg( p_mgr, "Deactivating '%s'", p_ext->psz_title ); - if( lua_ExtensionDeactivate( p_mgr, p_ext ) < 0 ) - { - 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_activated = false; - vlc_mutex_unlock( &p_ext->p_sys->command_lock ); - break; + 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_activated = false; + vlc_mutex_unlock( &p_ext->p_sys->command_lock ); + break; + } - case CMD_CLOSE: - { - lua_ExecuteFunction( p_mgr, p_ext, "close", LUA_END ); - break; - } + case CMD_CLOSE: + { + lua_ExecuteFunction( p_mgr, p_ext, "close", LUA_END ); + break; + } - case CMD_CLICK: + case CMD_CLICK: + { + extension_widget_t *p_widget = cmd->data[0]; + assert( p_widget ); + msg_Dbg( p_mgr, "Clicking '%s': '%s'", + p_ext->psz_name, p_widget->psz_text ); + if( lua_ExtensionWidgetClick( p_mgr, p_ext, p_widget ) < 0 ) { - extension_widget_t *p_widget = cmd->data[0]; - assert( p_widget ); - msg_Dbg( p_mgr, "Clicking '%s': '%s'", - p_ext->psz_name, p_widget->psz_text ); - if( lua_ExtensionWidgetClick( p_mgr, p_ext, p_widget ) < 0 ) - { - msg_Warn( p_mgr, "Could not translate click" ); - } - break; + msg_Warn( p_mgr, "Could not translate click" ); } + break; + } - case CMD_TRIGGERMENU: - { - int *pi_id = cmd->data[0]; - assert( pi_id ); - msg_Dbg( p_mgr, "Trigger menu %d of '%s'", - *pi_id, p_ext->psz_name ); - lua_ExtensionTriggerMenu( p_mgr, p_ext, *pi_id ); - break; - } + case CMD_TRIGGERMENU: + { + int *pi_id = cmd->data[0]; + assert( pi_id ); + msg_Dbg( p_mgr, "Trigger menu %d of '%s'", + *pi_id, p_ext->psz_name ); + lua_ExtensionTriggerMenu( p_mgr, p_ext, *pi_id ); + break; + } - case CMD_SET_INPUT: - { - lua_ExecuteFunction( p_mgr, p_ext, "input_changed", LUA_END ); - break; - } + case CMD_SET_INPUT: + { + lua_ExecuteFunction( p_mgr, p_ext, "input_changed", LUA_END ); + break; + } - case CMD_UPDATE_META: - { - lua_ExecuteFunction( p_mgr, p_ext, "meta_changed", LUA_END ); - break; - } + case CMD_UPDATE_META: + { + lua_ExecuteFunction( p_mgr, p_ext, "meta_changed", LUA_END ); + break; + } - case CMD_PLAYING_CHANGED: - { - lua_ExecuteFunction( p_mgr, p_ext, "playing_changed", - LUA_NUM, *((int *)cmd->data[0]), LUA_END ); - break; - } + case CMD_PLAYING_CHANGED: + { + lua_ExecuteFunction( p_mgr, p_ext, "playing_changed", + LUA_NUM, *((int *)cmd->data[0]), LUA_END ); + break; + } - default: - { - msg_Dbg( p_mgr, "Unknown command in extension command queue: %d", - cmd->i_command ); - break; - } + default: + { + msg_Dbg( p_mgr, "Unknown command in extension command queue: %d", + cmd->i_command ); + break; } - UnlockExtension( p_ext ); } + vlc_mutex_unlock( &p_ext->p_sys->running_lock ); + FreeCommands( cmd ); vlc_mutex_lock( &p_ext->p_sys->command_lock ); _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
