Commit 8b7d91f2 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Use var_GetGlobalMutex

Also never destroys global mutex, otherwise we get a race condition
(which is pretty contradictory to the point for mutexes)
parent c553d1eb
......@@ -221,10 +221,10 @@ static int QTVideoInit( decoder_t * );
static int Open( vlc_object_t *p_this )
{
decoder_t *p_dec = (decoder_t*)p_this;
if( var_GetGlobalMutex( "qt_mutex" ) == NULL )
return VLC_EGENERIC;
/* create a mutex */
var_Create( p_this->p_libvlc_global, "qt_mutex", VLC_VAR_MUTEX );
switch( p_dec->fmt_in.i_codec )
{
case VLC_FOURCC('S','V','Q','3'): /* Sorenson v3 */
......@@ -284,11 +284,11 @@ static void Close( vlc_object_t *p_this )
{
decoder_t *p_dec = (decoder_t*)p_this;
decoder_sys_t *p_sys = p_dec->p_sys;
vlc_value_t lockval;
vlc_mutex_t *lock;
/* get lock, avoid segfault */
var_Get( p_dec->p_libvlc_global, "qt_mutex", &lockval );
vlc_mutex_lock( lockval.p_address );
lock = var_GetGlobalMutex( "qt_mutex" );
vlc_mutex_lock( lock );
if( p_dec->fmt_out.i_cat == AUDIO_ES )
{
......@@ -304,11 +304,11 @@ static void Close( vlc_object_t *p_this )
i_error = p_sys->SoundConverterClose( p_sys->myConverter );
msg_Dbg( p_dec, "SoundConverterClose => %d", i_error );
if( p_sys->p_buffer ) free( p_sys->p_buffer );
free( p_sys->p_buffer );
}
else if( p_dec->fmt_out.i_cat == VIDEO_ES )
{
if( p_sys->plane) free( p_sys->plane );
free( p_sys->plane );
}
#ifndef __APPLE__
......@@ -327,8 +327,7 @@ static void Close( vlc_object_t *p_this )
#endif
#endif
vlc_mutex_unlock( lockval.p_address );
var_Destroy( p_dec->p_libvlc_global, "qt_mutex" );
vlc_mutex_unlock( lock );
if( p_sys ) free( p_sys );
}
......@@ -338,25 +337,26 @@ static void Close( vlc_object_t *p_this )
*****************************************************************************/
static int OpenAudio( decoder_t *p_dec )
{
decoder_sys_t *p_sys = malloc( sizeof( decoder_sys_t ) );
decoder_sys_t *p_sys;
vlc_mutex_t *lock = var_GetGlobalMutex( "qt_mutex" );
vlc_value_t lockval;
int i_error;
char fcc[4];
unsigned long WantedBufferSize;
unsigned long InputBufferSize = 0;
unsigned long OutputBufferSize = 0;
memset( p_sys, 0, sizeof( decoder_sys_t ) );
if( lock == NULL )
return VLC_EGENERIC;
p_sys = calloc( sizeof( decoder_sys_t ), 1 );
p_dec->p_sys = p_sys;
p_dec->pf_decode_audio = DecodeAudio;
memcpy( fcc, &p_dec->fmt_in.i_codec, 4 );
/* get lock, avoid segfault */
var_Get( p_dec->p_libvlc_global, "qt_mutex", &lockval );
vlc_mutex_lock( lockval.p_address );
vlc_mutex_lock( lock );
#ifdef __APPLE__
EnterMovies();
......@@ -467,7 +467,7 @@ static int OpenAudio( decoder_t *p_dec )
p_sys->i_out = 0;
p_sys->i_out_frames = 0;
vlc_mutex_unlock( lockval.p_address );
vlc_mutex_unlock( lock );
return VLC_SUCCESS;
exit_error:
......@@ -475,7 +475,7 @@ exit_error:
#ifdef LOADER
Restore_LDT_Keeper( p_sys->ldt_fs );
#endif
vlc_mutex_unlock( lockval.p_address );
vlc_mutex_unlock( lock );
free( p_sys );
return VLC_EGENERIC;
......@@ -488,7 +488,6 @@ static aout_buffer_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block )
{
decoder_sys_t *p_sys = p_dec->p_sys;
vlc_value_t lockval;
block_t *p_block;
int i_error;
......@@ -547,16 +546,16 @@ static aout_buffer_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block )
{
int i_frames = p_sys->i_buffer / p_sys->InFrameSize;
unsigned long i_out_frames, i_out_bytes;
vlc_mutex_t *lock = var_GetGlobalMutex( "qt_mutex ");
var_Get( p_dec->p_libvlc_global, "qt_mutex", &lockval );
vlc_mutex_lock( lockval.p_address );
vlc_mutex_lock( lock );
i_error = p_sys->SoundConverterConvertBuffer( p_sys->myConverter,
p_sys->p_buffer,
i_frames,
p_sys->out_buffer,
&i_out_frames,
&i_out_bytes );
vlc_mutex_unlock( lockval.p_address );
vlc_mutex_unlock( lock );
/*
msg_Dbg( p_dec, "decoded %d frames -> %ld frames (error=%d)",
......@@ -625,7 +624,7 @@ static int OpenVideo( decoder_t *p_dec )
decoder_sys_t *p_sys = malloc( sizeof( decoder_sys_t ) );
#ifndef WIN32
vlc_value_t lockval;
vlc_mutex_t *lock;
long i_result;
ComponentDescription desc;
Component prev;
......@@ -654,8 +653,8 @@ static int OpenVideo( decoder_t *p_dec )
fcc, p_dec->fmt_in.video.i_width, p_dec->fmt_in.video.i_height );
/* get lock, avoid segfault */
var_Get( p_dec->p_libvlc_global, "qt_mutex", &lockval );
vlc_mutex_lock( lockval.p_address );
lock = var_GetGlobalMutex( "qt_mutex" );
vlc_mutex_lock( lock );
#ifdef __APPLE__
EnterMovies();
......@@ -792,14 +791,14 @@ static int OpenVideo( decoder_t *p_dec )
p_dec->fmt_out.video.i_height= p_dec->fmt_in.video.i_height;
p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR * p_dec->fmt_in.video.i_width / p_dec->fmt_in.video.i_height;
vlc_mutex_unlock( lockval.p_address );
vlc_mutex_unlock( lock );
return VLC_SUCCESS;
exit_error:
#ifdef LOADER
Restore_LDT_Keeper( p_sys->ldt_fs );
#endif
vlc_mutex_unlock( lockval.p_address );
vlc_mutex_unlock( lock );
#endif /* !WIN32 */
......@@ -813,7 +812,7 @@ exit_error:
static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
{
decoder_sys_t *p_sys = p_dec->p_sys;
vlc_value_t lockval;
vlc_mutex_t *lock;
block_t *p_block;
picture_t *p_pic;
mtime_t i_pts;
......@@ -861,8 +860,8 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
return NULL;
}
var_Get( p_dec->p_libvlc_global, "qt_mutex", &lockval );
vlc_mutex_lock( lockval.p_address );
lock = var_GetGlobalMutex( "qt_mutex" );
vlc_mutex_lock( lock );
if( ( p_pic = p_dec->pf_vout_buffer_new( p_dec ) ) )
{
......@@ -886,7 +885,7 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
p_pic->date = i_pts;
}
vlc_mutex_unlock( lockval.p_address );
vlc_mutex_unlock( lock );
block_Release( p_block );
return p_pic;
......
......@@ -1214,22 +1214,19 @@ static struct gcry_thread_cbs gcry_threads_vlc =
/*****************************************************************************
* Module initialization
*****************************************************************************/
static unsigned refs = 0;
static int
Open( vlc_object_t *p_this )
{
tls_t *p_tls = (tls_t *)p_this;
vlc_mutex_t *lock;
vlc_value_t lock, count;
var_Create( p_this->p_libvlc_global, "gnutls_mutex", VLC_VAR_MUTEX );
var_Get( p_this->p_libvlc_global, "gnutls_mutex", &lock );
vlc_mutex_lock( lock.p_address );
lock = var_GetGlobalMutex( "gnutls_mutex" );
vlc_mutex_lock( lock );
/* Initialize GnuTLS only once */
var_Create( p_this->p_libvlc_global, "gnutls_count", VLC_VAR_INTEGER );
var_Get( p_this->p_libvlc_global, "gnutls_count", &count);
if( count.i_int == 0)
if( refs == 0 )
{
#ifdef NEED_THREAD_CONTEXT
__p_gcry_data = VLC_OBJECT( p_this->p_libvlc );
......@@ -1239,7 +1236,7 @@ Open( vlc_object_t *p_this )
if( gnutls_global_init( ) )
{
msg_Warn( p_this, "cannot initialize GnuTLS" );
vlc_mutex_unlock( lock.p_address );
vlc_mutex_unlock( lock );
return VLC_EGENERIC;
}
......@@ -1247,16 +1244,15 @@ Open( vlc_object_t *p_this )
if( psz_version == NULL )
{
gnutls_global_deinit( );
vlc_mutex_unlock( lock.p_address );
vlc_mutex_unlock( lock );
msg_Err( p_this, "unsupported GnuTLS version" );
return VLC_EGENERIC;
}
msg_Dbg( p_this, "GnuTLS v%s initialized", psz_version );
}
count.i_int++;
var_Set( p_this->p_libvlc_global, "gnutls_count", count);
vlc_mutex_unlock( lock.p_address );
refs++;
vlc_mutex_unlock( lock );
p_tls->pf_server_create = gnutls_ServerCreate;
p_tls->pf_client_create = gnutls_ClientCreate;
......@@ -1273,22 +1269,16 @@ Close( vlc_object_t *p_this )
/*tls_t *p_tls = (tls_t *)p_this;
tls_sys_t *p_sys = (tls_sys_t *)(p_this->p_sys);*/
vlc_value_t lock, count;
var_Create( p_this->p_libvlc_global, "gnutls_mutex", VLC_VAR_MUTEX );
var_Get( p_this->p_libvlc_global, "gnutls_mutex", &lock );
vlc_mutex_lock( lock.p_address );
vlc_mutex_t *lock;
var_Create( p_this->p_libvlc_global, "gnutls_count", VLC_VAR_INTEGER );
var_Get( p_this->p_libvlc_global, "gnutls_count", &count);
count.i_int--;
var_Set( p_this->p_libvlc_global, "gnutls_count", count);
lock = var_GetGlobalMutex( "gnutls_mutex" );
vlc_mutex_lock( lock );
if( count.i_int == 0 )
if( --refs == 0 )
{
gnutls_global_deinit( );
msg_Dbg( p_this, "GnuTLS deinitialized" );
}
vlc_mutex_unlock( lock.p_address );
vlc_mutex_unlock( lock );
}
......@@ -83,18 +83,16 @@ vlc_module_end();
*****************************************************************************/
static int Open( vlc_object_t *p_this )
{
vlc_value_t lockval;
vlc_mutex_t *lock;
/* FIXME: put this in the module (de)initialization ASAP */
var_Create( p_this->p_libvlc_global, "gtk", VLC_VAR_MUTEX );
var_Get( p_this->p_libvlc_global, "gtk", &lockval );
vlc_mutex_lock( lockval.p_address );
lock = var_GetGlobalCreate( "gtk" );
vlc_mutex_lock( lock );
if( i_refcount > 0 )
{
i_refcount++;
vlc_mutex_unlock( lockval.p_address );
vlc_mutex_unlock( lock );
return VLC_SUCCESS;
}
......@@ -114,13 +112,12 @@ static int Open( vlc_object_t *p_this )
{
vlc_object_destroy( p_gtk_main );
i_refcount--;
vlc_mutex_unlock( lockval.p_address );
var_Destroy( p_this->p_libvlc_global, "gtk" );
vlc_mutex_unlock( lock );
return VLC_ETHREAD;
}
i_refcount++;
vlc_mutex_unlock( lockval.p_address );
vlc_mutex_unlock( lock );
return VLC_SUCCESS;
}
......@@ -130,17 +127,16 @@ static int Open( vlc_object_t *p_this )
*****************************************************************************/
static void Close( vlc_object_t *p_this )
{
vlc_value_t lockval;
vlc_mutex_t *lock;
var_Get( p_this->p_libvlc_global, "gtk", &lockval );
vlc_mutex_lock( lockval.p_address );
lock = var_GetGlobalMutex( "gtk" );
vlc_mutex_lock( lock );
i_refcount--;
if( i_refcount > 0 )
{
vlc_mutex_unlock( lockval.p_address );
var_Destroy( p_this->p_libvlc_global, "gtk" );
vlc_mutex_unlock( lock );
return;
}
......@@ -150,8 +146,7 @@ static void Close( vlc_object_t *p_this )
vlc_object_destroy( p_gtk_main );
p_gtk_main = NULL;
vlc_mutex_unlock( lockval.p_address );
var_Destroy( p_this->p_libvlc_global, "gtk" );
vlc_mutex_unlock( lock );
}
static gint foo( gpointer bar ) { return TRUE; }
......
......@@ -83,18 +83,15 @@ vlc_module_end();
*****************************************************************************/
static int Open( vlc_object_t *p_this )
{
vlc_value_t lockval;
vlc_mutex_t *lock;
/* FIXME: put this in the module (de)initialization ASAP */
var_Create( p_this->p_libvlc_global, "qte", VLC_VAR_MUTEX );
var_Get( p_this->p_libvlc_global, "qte", &lockval );
vlc_mutex_lock( (vlc_mutex_t *) lockval.p_address );
lock = var_GetGlobalMutex( "qte" );
vlc_mutex_lock( lockval );
if( i_refcount > 0 )
{
i_refcount++;
vlc_mutex_unlock( (vlc_mutex_t *) lockval.p_address );
vlc_mutex_unlock( lock );
return VLC_SUCCESS;
}
......@@ -108,13 +105,12 @@ static int Open( vlc_object_t *p_this )
{
vlc_object_destroy( p_qte_main );
i_refcount--;
vlc_mutex_unlock( (vlc_mutex_t *) lockval.p_address );
var_Destroy( p_this->p_libvlc_global, "qte" );
vlc_mutex_unlock( lock );
return VLC_ETHREAD;
}
i_refcount++;
vlc_mutex_unlock( (vlc_mutex_t *) lockval.p_address );
vlc_mutex_unlock( lock );
vlc_object_attach( p_qte_main, p_this );
msg_Dbg( p_this, "qte_main running" );
......@@ -127,17 +123,16 @@ static int Open( vlc_object_t *p_this )
*****************************************************************************/
static void Close( vlc_object_t *p_this )
{
vlc_value_t lockval;
vlc_mutex_t *lock;
var_Get( p_this->p_libvlc_global, "qte", &lockval );
vlc_mutex_lock( (vlc_mutex_t *) lockval.p_address );
lock = var_GetGlobalMutex( "qte" );
vlc_mutex_lock( lock );
i_refcount--;
if( i_refcount > 0 )
{
vlc_mutex_unlock( (vlc_mutex_t *) lockval.p_address );
var_Destroy( p_this->p_libvlc_global, "qte" );
vlc_mutex_unlock( lock );
return;
}
p_qte_main->p_qte_application->quit();
......@@ -152,8 +147,7 @@ static void Close( vlc_object_t *p_this )
vlc_object_destroy( p_qte_main );
p_qte_main = NULL;
vlc_mutex_unlock( (vlc_mutex_t *) lockval.p_address );
var_Destroy( p_this->p_libvlc_global, "qte" );
vlc_mutex_unlock( lock );
}
/*****************************************************************************
......
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