[vlc-devel] commit: Use var_AcquireMutex for the "libvlc" lock ( Rémi Denis-Courmont )

git version control git at videolan.org
Sun Mar 30 16:14:40 CEST 2008


vlc | branch: master | Rémi Denis-Courmont <rem at videolan.org> | Sun Mar 30 17:14:47 2008 +0300| [959c5560883360dff21958fbf79abce04baec84c]

Use var_AcquireMutex for the "libvlc" lock

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

 src/libvlc-common.c   |   15 +++++----------
 src/modules/modules.c |   36 ++++++++++++------------------------
 2 files changed, 17 insertions(+), 34 deletions(-)

diff --git a/src/libvlc-common.c b/src/libvlc-common.c
index 6ffa129..d2c06d5 100644
--- a/src/libvlc-common.c
+++ b/src/libvlc-common.c
@@ -151,7 +151,6 @@ libvlc_int_t * libvlc_InternalCreate( void )
 {
     int i_ret;
     libvlc_int_t * p_libvlc = NULL;
-    vlc_value_t lockval;
     char *psz_env = NULL;
 
     /* vlc_threads_init *must* be the first internal call! No other call is
@@ -160,10 +159,8 @@ libvlc_int_t * libvlc_InternalCreate( void )
     if( i_ret < 0 ) return NULL;
 
     /* Now that the thread system is initialized, we don't have much, but
-     * at least we have var_Create */
-    var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
-    var_Get( p_libvlc_global, "libvlc", &lockval );
-    vlc_mutex_lock( lockval.p_address );
+     * at least we have variables */
+    vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
 
     i_instances++;
 
@@ -176,7 +173,7 @@ libvlc_int_t * libvlc_InternalCreate( void )
 
         p_libvlc_global->b_ready = VLC_TRUE;
     }
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( lock );
 
     /* Allocate a libvlc instance object */
     p_libvlc = vlc_object_create( p_libvlc_global, VLC_OBJECT_LIBVLC );
@@ -1044,9 +1041,7 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, vlc_bool_t b_release )
                      p_libvlc->p_hotkeys );
     FREENULL( p_libvlc->p_hotkeys );
 
-    var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
-    var_Get( p_libvlc_global, "libvlc", &lockval );
-    vlc_mutex_lock( lockval.p_address );
+    vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
     i_instances--;
 
     if( i_instances == 0 )
@@ -1054,7 +1049,7 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, vlc_bool_t b_release )
         /* System specific cleaning code */
         system_End( p_libvlc );
     }
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( lock );
 
     msg_Flush( p_libvlc );
     msg_Destroy( p_libvlc );
diff --git a/src/modules/modules.c b/src/modules/modules.c
index 1aead7e..c751cd9 100644
--- a/src/modules/modules.c
+++ b/src/modules/modules.c
@@ -115,12 +115,9 @@ static void   UndupModule      ( module_t * );
 void __module_InitBank( vlc_object_t *p_this )
 {
     module_bank_t *p_bank = NULL;
-    vlc_value_t  lockval;
     libvlc_global_data_t *p_libvlc_global = vlc_global();
 
-    var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
-    var_Get( p_libvlc_global, "libvlc", &lockval );
-    vlc_mutex_lock( lockval.p_address );
+    vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
 
     if( p_libvlc_global->p_module_bank == NULL )
     {
@@ -146,7 +143,7 @@ void __module_InitBank( vlc_object_t *p_this )
     else
         p_libvlc_global->p_module_bank->i_usage++;
 
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( lock );
 }
 
 
@@ -161,23 +158,20 @@ void __module_InitBank( vlc_object_t *p_this )
 void __module_EndBank( vlc_object_t *p_this )
 {
     module_t * p_next = NULL;
-    vlc_value_t lockval;
     libvlc_global_data_t *p_libvlc_global = vlc_global();
 
-    var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
-    var_Get( p_libvlc_global, "libvlc", &lockval );
-    vlc_mutex_lock( lockval.p_address );
+    vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
     if( !p_libvlc_global->p_module_bank )
     {
-        vlc_mutex_unlock( lockval.p_address );
+        vlc_mutex_unlock( lock );
         return;
     }
     if( --p_libvlc_global->p_module_bank->i_usage )
     {
-        vlc_mutex_unlock( lockval.p_address );
+        vlc_mutex_unlock( lock );
         return;
     }
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( lock );
 
     /* Save the configuration */
     config_AutoSaveConfigFile( p_this );
@@ -247,19 +241,16 @@ void __module_EndBank( vlc_object_t *p_this )
  */
 void __module_LoadBuiltins( vlc_object_t * p_this )
 {
-    vlc_value_t lockval;
     libvlc_global_data_t *p_libvlc_global = vlc_global();
 
-    var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
-    var_Get( p_libvlc_global, "libvlc", &lockval );
-    vlc_mutex_lock( lockval.p_address );
+    vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
     if( p_libvlc_global->p_module_bank->b_builtins )
     {
-        vlc_mutex_unlock( lockval.p_address );
+        vlc_mutex_unlock( lock );
         return;
     }
     p_libvlc_global->p_module_bank->b_builtins = VLC_TRUE;
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( lock );
 
     msg_Dbg( p_this, "checking builtin modules" );
     ALLOCATE_ALL_BUILTINS();
@@ -276,19 +267,16 @@ void __module_LoadBuiltins( vlc_object_t * p_this )
 void __module_LoadPlugins( vlc_object_t * p_this )
 {
 #ifdef HAVE_DYNAMIC_PLUGINS
-    vlc_value_t lockval;
     libvlc_global_data_t *p_libvlc_global = vlc_global();
 
-    var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
-    var_Get( p_libvlc_global, "libvlc", &lockval );
-    vlc_mutex_lock( lockval.p_address );
+    vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
     if( p_libvlc_global->p_module_bank->b_plugins )
     {
-        vlc_mutex_unlock( lockval.p_address );
+        vlc_mutex_unlock( lock );
         return;
     }
     p_libvlc_global->p_module_bank->b_plugins = VLC_TRUE;
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( lock );
 
     msg_Dbg( p_this, "checking plugin modules" );
 




More information about the vlc-devel mailing list