Commit 959c5560 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Use var_AcquireMutex for the "libvlc" lock

parent e4e91829
...@@ -151,7 +151,6 @@ libvlc_int_t * libvlc_InternalCreate( void ) ...@@ -151,7 +151,6 @@ libvlc_int_t * libvlc_InternalCreate( void )
{ {
int i_ret; int i_ret;
libvlc_int_t * p_libvlc = NULL; libvlc_int_t * p_libvlc = NULL;
vlc_value_t lockval;
char *psz_env = NULL; char *psz_env = NULL;
/* vlc_threads_init *must* be the first internal call! No other call is /* vlc_threads_init *must* be the first internal call! No other call is
...@@ -160,10 +159,8 @@ libvlc_int_t * libvlc_InternalCreate( void ) ...@@ -160,10 +159,8 @@ libvlc_int_t * libvlc_InternalCreate( void )
if( i_ret < 0 ) return NULL; if( i_ret < 0 ) return NULL;
/* Now that the thread system is initialized, we don't have much, but /* Now that the thread system is initialized, we don't have much, but
* at least we have var_Create */ * at least we have variables */
var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX ); vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
var_Get( p_libvlc_global, "libvlc", &lockval );
vlc_mutex_lock( lockval.p_address );
i_instances++; i_instances++;
...@@ -176,7 +173,7 @@ libvlc_int_t * libvlc_InternalCreate( void ) ...@@ -176,7 +173,7 @@ libvlc_int_t * libvlc_InternalCreate( void )
p_libvlc_global->b_ready = VLC_TRUE; p_libvlc_global->b_ready = VLC_TRUE;
} }
vlc_mutex_unlock( lockval.p_address ); vlc_mutex_unlock( lock );
/* Allocate a libvlc instance object */ /* Allocate a libvlc instance object */
p_libvlc = vlc_object_create( p_libvlc_global, VLC_OBJECT_LIBVLC ); 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 ) ...@@ -1044,9 +1041,7 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, vlc_bool_t b_release )
p_libvlc->p_hotkeys ); p_libvlc->p_hotkeys );
FREENULL( p_libvlc->p_hotkeys ); FREENULL( p_libvlc->p_hotkeys );
var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX ); vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
var_Get( p_libvlc_global, "libvlc", &lockval );
vlc_mutex_lock( lockval.p_address );
i_instances--; i_instances--;
if( i_instances == 0 ) if( i_instances == 0 )
...@@ -1054,7 +1049,7 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, vlc_bool_t b_release ) ...@@ -1054,7 +1049,7 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, vlc_bool_t b_release )
/* System specific cleaning code */ /* System specific cleaning code */
system_End( p_libvlc ); system_End( p_libvlc );
} }
vlc_mutex_unlock( lockval.p_address ); vlc_mutex_unlock( lock );
msg_Flush( p_libvlc ); msg_Flush( p_libvlc );
msg_Destroy( p_libvlc ); msg_Destroy( p_libvlc );
......
...@@ -115,12 +115,9 @@ static void UndupModule ( module_t * ); ...@@ -115,12 +115,9 @@ static void UndupModule ( module_t * );
void __module_InitBank( vlc_object_t *p_this ) void __module_InitBank( vlc_object_t *p_this )
{ {
module_bank_t *p_bank = NULL; module_bank_t *p_bank = NULL;
vlc_value_t lockval;
libvlc_global_data_t *p_libvlc_global = vlc_global(); libvlc_global_data_t *p_libvlc_global = vlc_global();
var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX ); vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
var_Get( p_libvlc_global, "libvlc", &lockval );
vlc_mutex_lock( lockval.p_address );
if( p_libvlc_global->p_module_bank == NULL ) if( p_libvlc_global->p_module_bank == NULL )
{ {
...@@ -146,7 +143,7 @@ void __module_InitBank( vlc_object_t *p_this ) ...@@ -146,7 +143,7 @@ void __module_InitBank( vlc_object_t *p_this )
else else
p_libvlc_global->p_module_bank->i_usage++; 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 ) ...@@ -161,23 +158,20 @@ void __module_InitBank( vlc_object_t *p_this )
void __module_EndBank( vlc_object_t *p_this ) void __module_EndBank( vlc_object_t *p_this )
{ {
module_t * p_next = NULL; module_t * p_next = NULL;
vlc_value_t lockval;
libvlc_global_data_t *p_libvlc_global = vlc_global(); libvlc_global_data_t *p_libvlc_global = vlc_global();
var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX ); vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
var_Get( p_libvlc_global, "libvlc", &lockval );
vlc_mutex_lock( lockval.p_address );
if( !p_libvlc_global->p_module_bank ) if( !p_libvlc_global->p_module_bank )
{ {
vlc_mutex_unlock( lockval.p_address ); vlc_mutex_unlock( lock );
return; return;
} }
if( --p_libvlc_global->p_module_bank->i_usage ) if( --p_libvlc_global->p_module_bank->i_usage )
{ {
vlc_mutex_unlock( lockval.p_address ); vlc_mutex_unlock( lock );
return; return;
} }
vlc_mutex_unlock( lockval.p_address ); vlc_mutex_unlock( lock );
/* Save the configuration */ /* Save the configuration */
config_AutoSaveConfigFile( p_this ); config_AutoSaveConfigFile( p_this );
...@@ -247,19 +241,16 @@ void __module_EndBank( vlc_object_t *p_this ) ...@@ -247,19 +241,16 @@ void __module_EndBank( vlc_object_t *p_this )
*/ */
void __module_LoadBuiltins( 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(); libvlc_global_data_t *p_libvlc_global = vlc_global();
var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX ); vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
var_Get( p_libvlc_global, "libvlc", &lockval );
vlc_mutex_lock( lockval.p_address );
if( p_libvlc_global->p_module_bank->b_builtins ) if( p_libvlc_global->p_module_bank->b_builtins )
{ {
vlc_mutex_unlock( lockval.p_address ); vlc_mutex_unlock( lock );
return; return;
} }
p_libvlc_global->p_module_bank->b_builtins = VLC_TRUE; 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" ); msg_Dbg( p_this, "checking builtin modules" );
ALLOCATE_ALL_BUILTINS(); ALLOCATE_ALL_BUILTINS();
...@@ -276,19 +267,16 @@ void __module_LoadBuiltins( vlc_object_t * p_this ) ...@@ -276,19 +267,16 @@ void __module_LoadBuiltins( vlc_object_t * p_this )
void __module_LoadPlugins( vlc_object_t * p_this ) void __module_LoadPlugins( vlc_object_t * p_this )
{ {
#ifdef HAVE_DYNAMIC_PLUGINS #ifdef HAVE_DYNAMIC_PLUGINS
vlc_value_t lockval;
libvlc_global_data_t *p_libvlc_global = vlc_global(); libvlc_global_data_t *p_libvlc_global = vlc_global();
var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX ); vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
var_Get( p_libvlc_global, "libvlc", &lockval );
vlc_mutex_lock( lockval.p_address );
if( p_libvlc_global->p_module_bank->b_plugins ) if( p_libvlc_global->p_module_bank->b_plugins )
{ {
vlc_mutex_unlock( lockval.p_address ); vlc_mutex_unlock( lock );
return; return;
} }
p_libvlc_global->p_module_bank->b_plugins = VLC_TRUE; 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" ); msg_Dbg( p_this, "checking plugin modules" );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment