Commit 97dcb939 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Rename var_GetGlobalMutex to var_AcquireMutex and make it lock the mutex automatically

parent 736981af
......@@ -126,7 +126,7 @@ VLC_EXPORT( void, __var_OptionParse, ( vlc_object_t *, const char * ) );
#define var_Command(a,b,c,d,e) __var_Command( VLC_OBJECT( a ), b, c, d, e )
VLC_EXPORT( int, __var_Command, ( vlc_object_t *, const char *, const char *, const char *, char ** ) );
VLC_EXPORT( vlc_mutex_t *, var_GetGlobalMutex, ( const char * ) );
VLC_EXPORT( vlc_mutex_t *, var_AcquireMutex, ( const char * ) );
/**
* __var_Create() with automatic casting.
......
......@@ -89,10 +89,6 @@ int E_(InitAudioDec)( decoder_t *p_dec, AVCodecContext *p_context,
AVCodec *p_codec, int i_codec_id, const char *psz_namecodec )
{
decoder_sys_t *p_sys;
vlc_mutex_t *lock = var_GetGlobalMutex( "avcodec" );
if( lock == NULL )
return VLC_EGENERIC;
/* Allocate the memory needed to store the decoder's structure */
if( ( p_dec->p_sys = p_sys =
......@@ -132,13 +128,23 @@ int E_(InitAudioDec)( decoder_t *p_dec, AVCodecContext *p_context,
p_sys->p_context->extradata_size, 0,
FF_INPUT_BUFFER_PADDING_SIZE );
}
else
p_sys->p_context->extradata = NULL;
/* ***** Open the codec ***** */
vlc_mutex_lock( lock );
vlc_mutex_t *lock = var_AcquireMutex( "avcodec" );
if( lock == NULL )
{
free( p_sys->p_context->extradata );
free( p_sys );
return VLC_ENOMEM;
}
if (avcodec_open( p_sys->p_context, p_sys->p_codec ) < 0)
{
vlc_mutex_unlock( lock );
msg_Err( p_dec, "cannot open codec (%s)", p_sys->psz_namecodec );
free( p_sys->p_context->extradata );
free( p_sys );
return VLC_EGENERIC;
}
......
......@@ -195,7 +195,6 @@ int E_(OpenEncoder)( vlc_object_t *p_this )
int i_codec_id, i_cat;
const char *psz_namecodec;
vlc_value_t val;
vlc_mutex_t *lock = var_GetGlobalMutex( "avcodec" );
if( !E_(GetFfmpegCodec)( p_enc->fmt_out.i_codec, &i_cat, &i_codec_id,
&psz_namecodec ) )
......@@ -530,7 +529,8 @@ int E_(OpenEncoder)( vlc_object_t *p_this )
p_context->extradata = NULL;
p_context->flags |= CODEC_FLAG_GLOBAL_HEADER;
vlc_mutex_lock( lock );
vlc_mutex_t *lock = var_AcquireMutex( "avcodec" );
if( avcodec_open( p_context, p_codec ) )
{
vlc_mutex_unlock( lock );
......@@ -1003,7 +1003,6 @@ void E_(CloseEncoder)( vlc_object_t *p_this )
{
encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys = p_enc->p_sys;
vlc_mutex_t *lock = var_GetGlobalMutex( "avcodec" );
if ( p_sys->b_inited && p_enc->i_threads >= 1 )
{
......@@ -1023,7 +1022,7 @@ void E_(CloseEncoder)( vlc_object_t *p_this )
free( pp_contexts );
}
vlc_mutex_lock( lock );
vlc_mutex_t *lock = var_AcquireMutex( "avcodec" );
avcodec_close( p_sys->p_context );
vlc_mutex_unlock( lock );
av_free( p_sys->p_context );
......
......@@ -341,7 +341,6 @@ static void CloseDecoder( vlc_object_t *p_this )
{
decoder_t *p_dec = (decoder_t *)p_this;
decoder_sys_t *p_sys = p_dec->p_sys;
vlc_mutex_t *lock = var_GetGlobalMutex( "avcodec" );
switch( p_sys->i_cat )
{
......@@ -355,10 +354,13 @@ static void CloseDecoder( vlc_object_t *p_this )
if( p_sys->p_context )
{
vlc_mutex_t *lock;
if( p_sys->p_context->extradata )
free( p_sys->p_context->extradata );
p_sys->p_context->extradata = NULL;
vlc_mutex_lock( lock );
lock = var_AcquireMutex( "avcodec" );
avcodec_close( p_sys->p_context );
vlc_mutex_unlock( lock );
msg_Dbg( p_dec, "ffmpeg codec (%s) stopped", p_sys->psz_namecodec );
......@@ -428,9 +430,7 @@ void E_(LibavcodecCallback)( void *p_opaque, int i_level,
void E_(InitLibavcodec)( vlc_object_t *p_object )
{
static int b_ffmpeginit = 0;
vlc_mutex_t *lock = var_GetGlobalMutex( "avcodec" );
vlc_mutex_lock( lock );
vlc_mutex_t *lock = var_AcquireMutex( "avcodec" );
/* *** init ffmpeg library (libavcodec) *** */
if( !b_ffmpeginit )
......
......@@ -215,12 +215,8 @@ int E_(InitVideoDec)( decoder_t *p_dec, AVCodecContext *p_context,
AVCodec *p_codec, int i_codec_id, const char *psz_namecodec )
{
decoder_sys_t *p_sys;
vlc_mutex_t *lock = var_GetGlobalMutex( "avcodec" );
vlc_value_t val;
if( lock == NULL )
return VLC_EGENERIC;
/* Allocate the memory needed to store the decoder's structure */
if( ( p_dec->p_sys = p_sys =
(decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
......@@ -382,7 +378,13 @@ int E_(InitVideoDec)( decoder_t *p_dec, AVCodecContext *p_context,
p_sys->p_context->palctrl = &palette_control;
/* ***** Open the codec ***** */
vlc_mutex_lock( lock );
vlc_mutex_t *lock = var_GetAcquireMutex( "avcodec" );
if( lock == NULL )
{
free( p_sys );
return VLC_ENOMEM;
}
if( avcodec_open( p_sys->p_context, p_sys->p_codec ) < 0 )
{
vlc_mutex_unlock( lock );
......
......@@ -221,10 +221,7 @@ 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 */
switch( p_dec->fmt_in.i_codec )
{
case VLC_FOURCC('S','V','Q','3'): /* Sorenson v3 */
......@@ -287,8 +284,7 @@ static void Close( vlc_object_t *p_this )
vlc_mutex_t *lock;
/* get lock, avoid segfault */
lock = var_GetGlobalMutex( "qt_mutex" );
vlc_mutex_lock( lock );
lock = var_AcquireMutex( "qt_mutex" );
if( p_dec->fmt_out.i_cat == AUDIO_ES )
{
......@@ -338,7 +334,6 @@ static void Close( vlc_object_t *p_this )
static int OpenAudio( decoder_t *p_dec )
{
decoder_sys_t *p_sys;
vlc_mutex_t *lock = var_GetGlobalMutex( "qt_mutex" );
int i_error;
char fcc[4];
......@@ -346,6 +341,8 @@ static int OpenAudio( decoder_t *p_dec )
unsigned long InputBufferSize = 0;
unsigned long OutputBufferSize = 0;
/* get lock, avoid segfault */
vlc_mutex_t *lock = var_AcquireMutex( "qt_mutex" );
if( lock == NULL )
return VLC_EGENERIC;
......@@ -355,9 +352,6 @@ static int OpenAudio( decoder_t *p_dec )
memcpy( fcc, &p_dec->fmt_in.i_codec, 4 );
/* get lock, avoid segfault */
vlc_mutex_lock( lock );
#ifdef __APPLE__
EnterMovies();
#endif
......@@ -546,9 +540,8 @@ 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 ");
vlc_mutex_t *lock = var_AcquireMutex( "qt_mutex ");
vlc_mutex_lock( lock );
i_error = p_sys->SoundConverterConvertBuffer( p_sys->myConverter,
p_sys->p_buffer,
i_frames,
......@@ -653,8 +646,7 @@ 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 */
lock = var_GetGlobalMutex( "qt_mutex" );
vlc_mutex_lock( lock );
lock = var_AcquireMutex( "qt_mutex" );
#ifdef __APPLE__
EnterMovies();
......@@ -860,8 +852,7 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
return NULL;
}
lock = var_GetGlobalMutex( "qt_mutex" );
vlc_mutex_lock( lock );
lock = var_AcquireMutex( "qt_mutex" );
if( ( p_pic = p_dec->pf_vout_buffer_new( p_dec ) ) )
{
......
......@@ -172,8 +172,7 @@ static int gnutls_Init (vlc_object_t *p_this)
{
int ret = VLC_EGENERIC;
vlc_mutex_t *lock = var_GetGlobalMutex ("gnutls_mutex");
vlc_mutex_lock (lock);
vlc_mutex_t *lock = var_AcquireMutex ("gnutls_mutex");
/* This should probably be removed/fixed. It will screw up with multiple
* LibVLC instances. */
......@@ -210,8 +209,7 @@ error:
*/
static void gnutls_Deinit (vlc_object_t *p_this)
{
vlc_mutex_t *lock = var_GetGlobalMutex( "gnutls_mutex" );
vlc_mutex_lock (lock);
vlc_mutex_t *lock = var_AcquireMutex( "gnutls_mutex" );
gnutls_global_deinit ();
msg_Dbg (p_this, "GnuTLS deinitialized");
......
......@@ -84,9 +84,7 @@ static int Open( vlc_object_t *p_this )
{
vlc_mutex_t *lock;
/* FIXME: put this in the module (de)initialization ASAP */
lock = var_GetGlobalCreate( "gtk" );
vlc_mutex_lock( lock );
lock = var_AcquireMutex( "gtk" );
if( i_refcount > 0 )
{
......@@ -128,8 +126,7 @@ static void Close( vlc_object_t *p_this )
{
vlc_mutex_t *lock;
lock = var_GetGlobalMutex( "gtk" );
vlc_mutex_lock( lock );
lock = var_AcquireMutex( "gtk" );
i_refcount--;
......
......@@ -84,8 +84,7 @@ static int Open( vlc_object_t *p_this )
{
vlc_mutex_t *lock;
lock = var_GetGlobalMutex( "qte" );
vlc_mutex_lock( lockval );
lock = var_AcquireMutex( "qte" );
if( i_refcount > 0 )
{
......@@ -124,8 +123,7 @@ static void Close( vlc_object_t *p_this )
{
vlc_mutex_t *lock;
lock = var_GetGlobalMutex( "qte" );
vlc_mutex_lock( lock );
lock = var_AcquireMutex( "qte" );
i_refcount--;
......
......@@ -130,12 +130,15 @@ static int Open ( vlc_object_t *p_this )
{
vout_thread_t * p_vout = (vout_thread_t *)p_this;
/* XXX: check for conflicts with the SDL audio output */
vlc_mutex_t *lock = var_GetGlobalMutex( "sdl" );
vlc_mutex_t *lock = var_AcquireMutex( "sdl" );
#ifdef HAVE_SETENV
char *psz_method;
#endif
if( lock == NULL )
return VLC_ENOMEM;
p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
if( p_vout->p_sys == NULL )
{
......@@ -143,8 +146,6 @@ static int Open ( vlc_object_t *p_this )
return VLC_ENOMEM;
}
vlc_mutex_lock( lock );
if( SDL_WasInit( SDL_INIT_VIDEO ) != 0 )
{
vlc_mutex_unlock( lock );
......
......@@ -341,7 +341,7 @@ __var_Create
__var_DelCallback
__var_Destroy
__var_Get
var_GetGlobalMutex
var_AcquireMutex
__var_OptionParse
__var_Set
__var_Type
......
......@@ -834,9 +834,10 @@ int __var_Get( vlc_object_t *p_this, const char *psz_name, vlc_value_t *p_val )
/**
* Gets a process-wide mutex, creates it if needed.
* Finds a process-wide mutex, creates it if needed, and locks it.
* Unlock with vlc_mutex_unlock().
*/
vlc_mutex_t *var_GetGlobalMutex( const char *name )
vlc_mutex_t *var_AcquireMutex( const char *name )
{
libvlc_global_data_t *p_global = vlc_global();
vlc_value_t val;
......@@ -845,6 +846,7 @@ vlc_mutex_t *var_GetGlobalMutex( const char *name )
return NULL;
var_Get( p_global, name, &val );
vlc_mutex_lock( &val.p_address );
return val.p_address;
}
......
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