[vlc-commits] lua: Cleanup lua state once the thread has joined

Hugo Beauzée-Luyssen git at videolan.org
Thu Mar 30 13:56:32 CEST 2017


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Wed Mar 29 14:00:07 2017 +0200| [451b18c4a308135b1eab33da0c3077f761c5939e] | committer: Hugo Beauzée-Luyssen

lua: Cleanup lua state once the thread has joined

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=451b18c4a308135b1eab33da0c3077f761c5939e
---

 modules/lua/extension.c        | 21 +++++++++++----------
 modules/lua/extension.h        |  2 ++
 modules/lua/extension_thread.c |  2 ++
 3 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/modules/lua/extension.c b/modules/lua/extension.c
index c8b335e..bc9f76d 100644
--- a/modules/lua/extension.c
+++ b/modules/lua/extension.c
@@ -160,9 +160,16 @@ void Close_Extension( vlc_object_t *p_this )
     {
         if( !p_ext )
             break;
-        vlc_join( p_ext->p_sys->thread, NULL );
+        if( p_ext->p_sys->b_thread_running == true )
+            vlc_join( p_ext->p_sys->thread, NULL );
+
+        /* Clear Lua State */
         if( p_ext->p_sys->L )
+        {
             lua_close( p_ext->p_sys->L );
+            vlclua_fd_cleanup( &p_ext->p_sys->dtable );
+        }
+
         free( p_ext->psz_name );
         free( p_ext->psz_title );
         free( p_ext->psz_author );
@@ -644,7 +651,8 @@ int lua_ExtensionDeactivate( extensions_manager_t *p_mgr, extension_t *p_ext )
 {
     assert( p_mgr != NULL && p_ext != NULL );
 
-    if( !p_ext->p_sys->L )
+    // b_exiting will be set to true once the entire tear down has been completed
+    if( p_ext->p_sys->b_exiting == true )
         return VLC_SUCCESS;
 
     vlclua_fd_interrupt( &p_ext->p_sys->dtable );
@@ -662,14 +670,7 @@ int lua_ExtensionDeactivate( extensions_manager_t *p_mgr, extension_t *p_ext )
         p_ext->p_sys->p_input = NULL;
     }
 
-    int i_ret = lua_ExecuteFunction( p_mgr, p_ext, "deactivate", LUA_END );
-
-    /* Clear Lua State */
-    vlclua_fd_cleanup( &p_ext->p_sys->dtable );
-    lua_close( p_ext->p_sys->L );
-    p_ext->p_sys->L = NULL;
-
-    return i_ret;
+    return lua_ExecuteFunction( p_mgr, p_ext, "deactivate", LUA_END );
 }
 
 int lua_ExtensionWidgetClick( extensions_manager_t *p_mgr,
diff --git a/modules/lua/extension.h b/modules/lua/extension.h
index e9fa0e5..beaed15 100644
--- a/modules/lua/extension.h
+++ b/modules/lua/extension.h
@@ -97,6 +97,8 @@ struct extension_sys_t
     vlc_timer_t timer; ///< This timer makes sure Lua never gets stuck >5s
 
     bool b_exiting;
+
+    bool b_thread_running; //< Only accessed out of the extension thread.
 };
 
 /* Extensions: manager functions */
diff --git a/modules/lua/extension_thread.c b/modules/lua/extension_thread.c
index 751070c..c9fd60d 100644
--- a/modules/lua/extension_thread.c
+++ b/modules/lua/extension_thread.c
@@ -74,11 +74,13 @@ int Activate( extensions_manager_t *p_mgr, extension_t *p_ext )
 
     /* Start thread */
     p_sys->b_exiting = false;
+    p_sys->b_thread_running = true;
 
     if( vlc_clone( &p_sys->thread, Run, p_ext, VLC_THREAD_PRIORITY_LOW )
         != VLC_SUCCESS )
     {
         p_sys->b_exiting = true;
+        p_sys->b_thread_running = false;
         // Note: Automatically deactivating the extension...
         Deactivate( p_mgr, p_ext );
         return VLC_ENOMEM;



More information about the vlc-commits mailing list