[vlc-devel] commit: Use the "libvlc" variable to store a process wide mutex ( Rafaël Carré )

git version control git at videolan.org
Mon Aug 4 14:02:07 CEST 2008


vlc | branch: 0.8.6-bugfix | Rafaël Carré <rcarre at m2x.nl> | Mon Aug  4 14:03:40 2008 +0200| [807b4f653b522c090bd39fafd361f98e6ae9806c] | committer: Rafaël Carré 

Use the "libvlc" variable to store a process wide mutex

Previous code would destroy the mutex after using it, rendering it useless
Use this mutex to protect concurrent access to libvlc counting

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

 src/libvlc.c       |   13 +++++++++++--
 src/misc/modules.c |   11 -----------
 2 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/src/libvlc.c b/src/libvlc.c
index 904529f..e525e35 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -205,6 +205,7 @@ int VLC_Create( void )
     var_Create( p_libvlc, "libvlc", VLC_VAR_MUTEX );
     var_Get( p_libvlc, "libvlc", &lockval );
     vlc_mutex_lock( lockval.p_address );
+
     if( !libvlc.b_ready )
     {
         char *psz_env;
@@ -238,7 +239,6 @@ int VLC_Create( void )
 
     i_libvlc++;
     vlc_mutex_unlock( lockval.p_address );
-    var_Destroy( p_libvlc, "libvlc" );
 
     /* Allocate a vlc object */
     p_vlc = vlc_object_create( p_libvlc, VLC_OBJECT_VLC );
@@ -1031,9 +1031,18 @@ int VLC_Destroy( int i_object )
      * Nobody shall use msg_* afterward.
      */
     msg_Flush( p_vlc );
-    if( --i_libvlc == 0 )
+
+    vlc_value_t lockval;
+    var_Create( p_libvlc, "libvlc", VLC_VAR_MUTEX );
+    var_Get( p_libvlc, "libvlc", &lockval );
+    vlc_mutex_lock( lockval.p_address );
+    vlc_bool_t b_destroy = --i_libvlc == 0;
+    vlc_mutex_unlock( lockval.p_address );
+
+    if( b_destroy )
         msg_Destroy( p_libvlc );
 
+
     /* Destroy global iconv */
     LocaleDeinit();
 
diff --git a/src/misc/modules.c b/src/misc/modules.c
index a33a425..9dc6fec 100644
--- a/src/misc/modules.c
+++ b/src/misc/modules.c
@@ -181,11 +181,9 @@ void __module_InitBank( vlc_object_t *p_this )
     {
         p_this->p_libvlc->p_module_bank->i_usage++;
         vlc_mutex_unlock( lockval.p_address );
-        var_Destroy( p_this->p_libvlc, "libvlc" );
         return;
     }
     vlc_mutex_unlock( lockval.p_address );
-    var_Destroy( p_this->p_libvlc, "libvlc" );
 
     p_bank = vlc_object_create( p_this, sizeof(module_bank_t) );
     p_bank->psz_object_name = "module bank";
@@ -240,17 +238,14 @@ void __module_EndBank( vlc_object_t *p_this )
     if( !p_this->p_libvlc->p_module_bank )
     {
         vlc_mutex_unlock( lockval.p_address );
-        var_Destroy( p_this->p_libvlc, "libvlc" );
         return;
     }
     if( --p_this->p_libvlc->p_module_bank->i_usage )
     {
         vlc_mutex_unlock( lockval.p_address );
-        var_Destroy( p_this->p_libvlc, "libvlc" );
         return;
     }
     vlc_mutex_unlock( lockval.p_address );
-    var_Destroy( p_this->p_libvlc, "libvlc" );
 
     config_AutoSaveConfigFile( p_this );
 
@@ -317,12 +312,10 @@ void __module_LoadMain( vlc_object_t *p_this )
     if( p_this->p_libvlc->p_module_bank->b_main )
     {
         vlc_mutex_unlock( lockval.p_address );
-        var_Destroy( p_this->p_libvlc, "libvlc" );
         return;
     }
     p_this->p_libvlc->p_module_bank->b_main = VLC_TRUE;
     vlc_mutex_unlock( lockval.p_address );
-    var_Destroy( p_this->p_libvlc, "libvlc" );
 
     AllocateBuiltinModule( p_this, vlc_entry__main );
 }
@@ -342,12 +335,10 @@ void __module_LoadBuiltins( vlc_object_t * p_this )
     if( p_this->p_libvlc->p_module_bank->b_builtins )
     {
         vlc_mutex_unlock( lockval.p_address );
-        var_Destroy( p_this->p_libvlc, "libvlc" );
         return;
     }
     p_this->p_libvlc->p_module_bank->b_builtins = VLC_TRUE;
     vlc_mutex_unlock( lockval.p_address );
-    var_Destroy( p_this->p_libvlc, "libvlc" );
 
     msg_Dbg( p_this, "checking builtin modules" );
     ALLOCATE_ALL_BUILTINS();
@@ -369,12 +360,10 @@ void __module_LoadPlugins( vlc_object_t * p_this )
     if( p_this->p_libvlc->p_module_bank->b_plugins )
     {
         vlc_mutex_unlock( lockval.p_address );
-        var_Destroy( p_this->p_libvlc, "libvlc" );
         return;
     }
     p_this->p_libvlc->p_module_bank->b_plugins = VLC_TRUE;
     vlc_mutex_unlock( lockval.p_address );
-    var_Destroy( p_this->p_libvlc, "libvlc" );
 
     msg_Dbg( p_this, "checking plugin modules" );
 




More information about the vlc-devel mailing list