From: RĂ©mi Denis-Courmont Date: Sun, 5 Oct 2008 08:28:32 +0000 (+0300) Subject: Use static mutexes X-Git-Tag: 1.0.0-pre1~2712 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=e39842845193a0a263ae548fd8e10fce631d2f09;p=vlc Use static mutexes --- diff --git a/include/vlc_gcrypt.h b/include/vlc_gcrypt.h index 8502910934..cd5ffd5457 100644 --- a/include/vlc_gcrypt.h +++ b/include/vlc_gcrypt.h @@ -88,7 +88,19 @@ static const struct gcry_thread_cbs gcry_threads_vlc = */ static inline void vlc_gcrypt_init (void) { - vlc_mutex_t *lock = var_AcquireMutex ("gcrypt_mutex"); - gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_vlc); - vlc_mutex_unlock (lock); + /* This would need a process-wide static mutex with all libraries linking + * to a given instance of libgcrypt. We cannot do this as we have different + * plugins linking with gcrypt, and some underlying libraries may use it + * behind our back. Only way is to always link gcrypt statically (ouch!) or + * have upstream gcrypt provide one shared object per threading system. */ + static vlc_mutex_t lock = VLC_STATIC_MUTEX; + static bool done = false; + + vlc_mutex_lock (&lock); + if (!done) + { + gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_vlc); + done = true; + } + vlc_mutex_unlock (&lock); } diff --git a/modules/codec/avcodec/audio.c b/modules/codec/avcodec/audio.c index 708e193f8f..92c6208025 100644 --- a/modules/codec/avcodec/audio.c +++ b/modules/codec/avcodec/audio.c @@ -180,23 +180,17 @@ int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context, } /* ***** Open the codec ***** */ - vlc_mutex_t *lock = var_AcquireMutex( "avcodec" ); - if( lock == NULL ) - { - free( p_sys->p_context->extradata ); - free( p_sys ); - return VLC_ENOMEM; - } + vlc_mutex_lock( &avcodec_lock ); if (avcodec_open( p_sys->p_context, p_sys->p_codec ) < 0) { - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &avcodec_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; } - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &avcodec_lock ); msg_Dbg( p_dec, "ffmpeg codec (%s) started", p_sys->psz_namecodec ); diff --git a/modules/codec/avcodec/avcodec.c b/modules/codec/avcodec/avcodec.c index 32ac223724..de1801d61a 100644 --- a/modules/codec/avcodec/avcodec.c +++ b/modules/codec/avcodec/avcodec.c @@ -202,6 +202,8 @@ vlc_module_begin(); vlc_module_end(); +vlc_mutex_t avcodec_lock = VLC_STATIC_MUTEX; + /***************************************************************************** * OpenDecoder: probe the decoder and return score *****************************************************************************/ @@ -319,9 +321,9 @@ static void CloseDecoder( vlc_object_t *p_this ) free( p_sys->p_context->extradata ); p_sys->p_context->extradata = NULL; - lock = var_AcquireMutex( "avcodec" ); + vlc_mutex_lock( &avcodec_lock ); avcodec_close( p_sys->p_context ); - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &avcodec_lock ); msg_Dbg( p_dec, "ffmpeg codec (%s) stopped", p_sys->psz_namecodec ); av_free( p_sys->p_context ); } @@ -331,8 +333,9 @@ static void CloseDecoder( vlc_object_t *p_this ) void InitLibavcodec( vlc_object_t *p_object ) { - static int b_ffmpeginit = 0; - vlc_mutex_t *lock = var_AcquireMutex( "avcodec" ); + static bool b_ffmpeginit = false; + + vlc_mutex_lock( &avcodec_lock ); /* *** init ffmpeg library (libavcodec) *** */ if( !b_ffmpeginit ) @@ -340,9 +343,9 @@ void InitLibavcodec( vlc_object_t *p_object ) avcodec_init(); avcodec_register_all(); av_log_set_callback( LibavutilCallback ); - b_ffmpeginit = 1; + b_ffmpeginit = true; - msg_Dbg( p_object, "libavcodec initialized (interface %d )", + msg_Dbg( p_object, "libavcodec initialized (interface 0x%x)", LIBAVCODEC_VERSION_INT ); } else @@ -350,5 +353,5 @@ void InitLibavcodec( vlc_object_t *p_object ) msg_Dbg( p_object, "libavcodec already initialized" ); } - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &avcodec_lock ); } diff --git a/modules/codec/avcodec/avcodec.h b/modules/codec/avcodec/avcodec.h index 591d1258db..2c467e8879 100644 --- a/modules/codec/avcodec/avcodec.h +++ b/modules/codec/avcodec/avcodec.h @@ -48,6 +48,9 @@ int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context, AVCodec *p_codec, int i_codec_id, const char *psz_namecodec ); void EndAudioDec( decoder_t *p_dec ); +/* Avcodec global lock */ +extern vlc_mutex_t avcodec_lock; + /***************************************************************************** * Module descriptor help strings *****************************************************************************/ diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c index 76c1733e68..d9b8285488 100644 --- a/modules/codec/avcodec/encoder.c +++ b/modules/codec/avcodec/encoder.c @@ -604,11 +604,11 @@ int OpenEncoder( vlc_object_t *p_this ) p_context->extradata = NULL; p_context->flags |= CODEC_FLAG_GLOBAL_HEADER; - vlc_mutex_t *lock = var_AcquireMutex( "avcodec" ); + vlc_mutex_lock( &avcodec_lock ); if( avcodec_open( p_context, p_codec ) ) { - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &avcodec_lock ); if( p_enc->fmt_in.i_cat == AUDIO_ES && (p_context->channels > 2 || i_codec_id == CODEC_ID_MP2 || i_codec_id == CODEC_ID_MP3) ) @@ -658,10 +658,10 @@ int OpenEncoder( vlc_object_t *p_this ) } p_context->codec = NULL; - vlc_mutex_lock( lock ); + vlc_mutex_lock( &avcodec_lock ); if( avcodec_open( p_context, p_codec ) ) { - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &avcodec_lock ); msg_Err( p_enc, "cannot open encoder" ); intf_UserFatal( p_enc, false, _("Streaming / Transcoding failed"), @@ -679,7 +679,7 @@ int OpenEncoder( vlc_object_t *p_this ) return VLC_EGENERIC; } } - vlc_mutex_unlock( lock); + vlc_mutex_unlock( &avcodec_lock ); p_enc->fmt_out.i_extra = p_context->extradata_size; if( p_enc->fmt_out.i_extra ) @@ -1111,9 +1111,9 @@ void CloseEncoder( vlc_object_t *p_this ) free( pp_contexts ); } - vlc_mutex_t *lock = var_AcquireMutex( "avcodec" ); + vlc_mutex_lock( &avcodec_lock ); avcodec_close( p_sys->p_context ); - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &avcodec_lock ); av_free( p_sys->p_context ); free( p_sys->p_buffer ); diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c index 638147bad7..7a534e2a05 100644 --- a/modules/codec/avcodec/video.c +++ b/modules/codec/avcodec/video.c @@ -383,23 +383,16 @@ int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context, } /* ***** Open the codec ***** */ - vlc_mutex_t *lock = var_AcquireMutex( "avcodec" ); - if( lock == NULL ) - { - free( p_sys->p_buffer_orig ); - free( p_sys ); - return VLC_ENOMEM; - } - + vlc_mutex_lock( &avcodec_lock ); if( avcodec_open( p_sys->p_context, p_sys->p_codec ) < 0 ) { - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &avcodec_lock ); msg_Err( p_dec, "cannot open codec (%s)", p_sys->psz_namecodec ); free( p_sys->p_buffer_orig ); free( p_sys ); return VLC_EGENERIC; } - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &avcodec_lock ); msg_Dbg( p_dec, "ffmpeg codec (%s) started", p_sys->psz_namecodec ); diff --git a/modules/codec/libass.c b/modules/codec/libass.c index e6b14da5b0..6efe21cfab 100644 --- a/modules/codec/libass.c +++ b/modules/codec/libass.c @@ -72,7 +72,6 @@ typedef struct { vlc_object_t *p_libvlc; - vlc_mutex_t *p_lock; int i_refcount; ass_library_t *p_library; ass_renderer_t *p_renderer; @@ -120,6 +119,8 @@ static int BuildRegions( spu_t *p_spu, rectangle_t *p_region, int i_max_region, static void SubpictureReleaseRegions( spu_t *p_spu, subpicture_t *p_subpic ); static void RegionDraw( subpicture_region_t *p_region, ass_image_t *p_img ); +static vlc_mutex_t libass_lock = VLC_STATIC_MUTEX; + //#define DEBUG_REGION /***************************************************************************** @@ -151,16 +152,16 @@ static int Create( vlc_object_t *p_this ) p_sys->i_refcount = 1; /* Add a track */ - vlc_mutex_lock( p_sys->p_ass->p_lock ); + vlc_mutex_lock( &libass_lock ); p_sys->p_track = p_track = ass_new_track( p_sys->p_ass->p_library ); if( !p_track ) { - vlc_mutex_unlock( p_sys->p_ass->p_lock ); + vlc_mutex_unlock( &libass_lock ); DecSysRelease( p_sys ); return VLC_EGENERIC; } ass_process_codec_private( p_track, p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra ); - vlc_mutex_unlock( p_sys->p_ass->p_lock ); + vlc_mutex_unlock( &libass_lock ); return VLC_SUCCESS; } @@ -194,10 +195,10 @@ static void DecSysRelease( decoder_sys_t *p_sys ) vlc_mutex_unlock( &p_sys->lock ); vlc_mutex_destroy( &p_sys->lock ); - vlc_mutex_lock( p_sys->p_ass->p_lock ); + vlc_mutex_lock( &libass_lock ); if( p_sys->p_track ) ass_free_track( p_sys->p_track ); - vlc_mutex_unlock( p_sys->p_ass->p_lock ); + vlc_mutex_unlock( &libass_lock ); AssHandleRelease( p_sys->p_ass ); free( p_sys ); @@ -264,13 +265,13 @@ static subpicture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) p_spu->b_ephemer = true; p_spu->b_absolute = true; - vlc_mutex_lock( p_sys->p_ass->p_lock ); + vlc_mutex_lock( &libass_lock ); if( p_sys->p_track ) { ass_process_chunk( p_sys->p_track, p_spu->p_sys->p_subs_data, p_spu->p_sys->i_subs_len, p_spu->i_start / 1000, (p_spu->i_stop-p_spu->i_start) / 1000 ); } - vlc_mutex_unlock( p_sys->p_ass->p_lock ); + vlc_mutex_unlock( &libass_lock ); p_spu->pf_pre_render = PreRender; p_spu->pf_update_regions = UpdateRegions; @@ -320,7 +321,7 @@ static void UpdateRegions( spu_t *p_spu, subpicture_t *p_subpic, return; } - vlc_mutex_lock( p_ass->p_lock ); + vlc_mutex_lock( &libass_lock ); /* */ fmt = *p_fmt; @@ -347,7 +348,7 @@ static void UpdateRegions( spu_t *p_spu, subpicture_t *p_subpic, if( !i_changed && !b_fmt_changed ) { - vlc_mutex_unlock( p_ass->p_lock ); + vlc_mutex_unlock( &libass_lock ); return; } @@ -368,7 +369,7 @@ static void UpdateRegions( spu_t *p_spu, subpicture_t *p_subpic, if( i_region <= 0 ) { - vlc_mutex_unlock( p_ass->p_lock ); + vlc_mutex_unlock( &libass_lock ); return; } @@ -402,7 +403,7 @@ static void UpdateRegions( spu_t *p_spu, subpicture_t *p_subpic, *pp_region_last = r; pp_region_last = &r->p_next; } - vlc_mutex_unlock( p_ass->p_lock ); + vlc_mutex_unlock( &libass_lock ); } static rectangle_t r_create( int x0, int y0, int x1, int y1 ) @@ -616,9 +617,7 @@ static void SubpictureReleaseRegions( spu_t *p_spu, subpicture_t *p_subpic ) /* */ static ass_handle_t *AssHandleHold( decoder_t *p_dec ) { - vlc_mutex_t *p_lock = var_AcquireMutex( "libass" ); - if( !p_lock ) - return NULL; + vlc_mutex_lock( &libass_lock ); ass_handle_t *p_ass = NULL; ass_library_t *p_library = NULL; @@ -635,7 +634,7 @@ static ass_handle_t *AssHandleHold( decoder_t *p_dec ) p_ass->i_refcount++; - vlc_mutex_unlock( p_lock ); + vlc_mutex_unlock( &libass_lock ); return p_ass; } @@ -646,7 +645,6 @@ static ass_handle_t *AssHandleHold( decoder_t *p_dec ) /* */ p_ass->p_libvlc = VLC_OBJECT(p_dec->p_libvlc); - p_ass->p_lock = p_lock; p_ass->i_refcount = 1; /* Create libass library */ @@ -713,7 +711,7 @@ static ass_handle_t *AssHandleHold( decoder_t *p_dec ) var_Set( p_dec->p_libvlc, "libass-handle", val ); /* */ - vlc_mutex_unlock( p_ass->p_lock ); + vlc_mutex_unlock( &libass_lock ); return p_ass; error: @@ -723,16 +721,16 @@ error: ass_library_done( p_library ); free( p_ass ); - vlc_mutex_unlock( p_lock ); + vlc_mutex_unlock( &libass_lock ); return NULL; } static void AssHandleRelease( ass_handle_t *p_ass ) { - vlc_mutex_lock( p_ass->p_lock ); + vlc_mutex_lock( &libass_lock ); p_ass->i_refcount--; if( p_ass->i_refcount > 0 ) { - vlc_mutex_unlock( p_ass->p_lock ); + vlc_mutex_unlock( &libass_lock ); return; } @@ -743,7 +741,7 @@ static void AssHandleRelease( ass_handle_t *p_ass ) val.p_address = NULL; var_Set( p_ass->p_libvlc, "libass-handle", val ); - vlc_mutex_unlock( p_ass->p_lock ); + vlc_mutex_unlock( &libass_lock ); free( p_ass ); } diff --git a/modules/codec/quicktime.c b/modules/codec/quicktime.c index 2776bc79de..b0f7321cf6 100644 --- a/modules/codec/quicktime.c +++ b/modules/codec/quicktime.c @@ -326,6 +326,8 @@ static int Open( vlc_object_t *p_this ) } } +static vlc_mutex_t qt_mutex = VLC_STATIC_MUTEX; + /***************************************************************************** * Close: *****************************************************************************/ @@ -333,10 +335,9 @@ 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_mutex_t *lock; /* get lock, avoid segfault */ - lock = var_AcquireMutex( "qt_mutex" ); + vlc_mutex_lock( &qt_mutex ); if( p_dec->fmt_out.i_cat == AUDIO_ES ) { @@ -375,7 +376,7 @@ static void Close( vlc_object_t *p_this ) #endif #endif - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &qt_mutex ); free( p_sys ); } @@ -394,9 +395,7 @@ static int OpenAudio( decoder_t *p_dec ) unsigned long OutputBufferSize = 0; /* get lock, avoid segfault */ - vlc_mutex_t *lock = var_AcquireMutex( "qt_mutex" ); - if( lock == NULL ) - return VLC_EGENERIC; + vlc_mutex_lock( &qt_mutex ); p_sys = calloc( sizeof( decoder_sys_t ), 1 ); p_dec->p_sys = p_sys; @@ -515,7 +514,7 @@ static int OpenAudio( decoder_t *p_dec ) p_sys->i_out = 0; p_sys->i_out_frames = 0; - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &qt_mutex ); return VLC_SUCCESS; exit_error: @@ -523,7 +522,7 @@ exit_error: #ifdef LOADER Restore_LDT_Keeper( p_sys->ldt_fs ); #endif - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &qt_mutex ); free( p_sys ); return VLC_EGENERIC; @@ -595,7 +594,7 @@ 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_AcquireMutex( "qt_mutex "); + vlc_mutex_lock( &qt_mutex ); i_error = p_sys->SoundConverterConvertBuffer( p_sys->myConverter, p_sys->p_buffer, @@ -603,7 +602,7 @@ static aout_buffer_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block ) p_sys->out_buffer, &i_out_frames, &i_out_bytes ); - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &qt_mutex ); /* msg_Dbg( p_dec, "decoded %d frames -> %ld frames (error=%d)", @@ -674,7 +673,6 @@ static int OpenVideo( decoder_t *p_dec ) return VLC_ENOMEM; #ifndef WIN32 - vlc_mutex_t *lock; long i_result; ComponentDescription desc; Component prev; @@ -703,7 +701,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_AcquireMutex( "qt_mutex" ); + vlc_mutex_lock( &qt_mutex ); #ifdef __APPLE__ EnterMovies(); @@ -845,14 +843,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( lock ); + vlc_mutex_unlock( &qt_mutex ); return VLC_SUCCESS; exit_error: #ifdef LOADER Restore_LDT_Keeper( p_sys->ldt_fs ); #endif - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &qt_mutex ); #endif /* !WIN32 */ @@ -866,7 +864,6 @@ exit_error: static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block ) { decoder_sys_t *p_sys = p_dec->p_sys; - vlc_mutex_t *lock; block_t *p_block; picture_t *p_pic; mtime_t i_pts; @@ -916,7 +913,7 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block ) return NULL; } - lock = var_AcquireMutex( "qt_mutex" ); + vlc_mutex_lock( &qt_mutex ); if( ( p_pic = p_dec->pf_vout_buffer_new( p_dec ) ) ) { @@ -940,7 +937,7 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block ) p_pic->date = i_pts; } - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &qt_mutex ); block_Release( p_block ); return p_pic; diff --git a/modules/codec/realvideo.c b/modules/codec/realvideo.c index 40d0542c72..cc907e2229 100644 --- a/modules/codec/realvideo.c +++ b/modules/codec/realvideo.c @@ -203,12 +203,13 @@ static void * load_syms_linux(decoder_t *p_dec, const char *path) } #endif +static vlc_mutex_t rm_mutex = VLC_STATIC_MUTEX; + static int InitVideo(decoder_t *p_dec) { int result; struct rv_init_t init_data; char fcc[4]; - vlc_mutex_t *lock; char *g_decode_path; int i_vide = p_dec->fmt_in.i_extra; @@ -309,9 +310,7 @@ static int InitVideo(decoder_t *p_dec) return VLC_EGENERIC; } - lock = var_AcquireMutex( "rm_mutex" ); - if ( lock == NULL ) - return VLC_EGENERIC; + vlc_mutex_lock( &rm_mutex ); p_sys->handle=NULL; #ifdef WIN32 @@ -358,7 +357,7 @@ static int InitVideo(decoder_t *p_dec) p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR * p_dec->fmt_in.video.i_width / p_dec->fmt_in.video.i_height; p_sys->inited = 0; - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &rm_mutex ); return VLC_SUCCESS; } @@ -397,10 +396,9 @@ 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_mutex_t *lock; /* get lock, avoid segfault */ - lock = var_AcquireMutex( "rm_mutex" ); + vlc_mutex_lock( &rm_mutex ); #ifdef WIN32 if (dll_type == 1) @@ -435,8 +433,7 @@ static void Close( vlc_object_t *p_this ) #endif p_sys->inited = 0; - if ( lock ) - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &rm_mutex ); if ( p_sys ) free( p_sys ); @@ -448,7 +445,6 @@ static void Close( vlc_object_t *p_this ) static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block ) { decoder_sys_t *p_sys = p_dec->p_sys; - vlc_mutex_t *lock; block_t *p_block; picture_t *p_pic; mtime_t i_pts; @@ -465,9 +461,7 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block ) i_pts = p_block->i_pts ? p_block->i_pts : p_block->i_dts; - lock = var_AcquireMutex( "rm_mutex" ); - if ( lock == NULL ) - return NULL; + vlc_mutex_lock( &rm_mutex ); p_pic = p_dec->pf_vout_buffer_new( p_dec ); @@ -559,7 +553,7 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block ) p_pic->b_force = 1; } - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &rm_mutex ); block_Release( p_block ); return p_pic; diff --git a/modules/misc/freetype.c b/modules/misc/freetype.c index d63830dcf9..e65baeffac 100644 --- a/modules/misc/freetype.c +++ b/modules/misc/freetype.c @@ -233,7 +233,7 @@ static void FreeLines( line_desc_t * ); static void FreeLine( line_desc_t * ); #ifdef HAVE_FONTCONFIG -static vlc_object_t *FontBuilderAttach( filter_t *p_filter, vlc_mutex_t **pp_lock ); +static vlc_object_t *FontBuilderAttach( filter_t *p_filter ); static void FontBuilderDetach( filter_t *p_filter, vlc_object_t *p_fontbuilder ); static void* FontBuilderThread( vlc_object_t *p_this); static void FontBuilderDestructor( vlc_object_t *p_this ); @@ -261,7 +261,6 @@ struct filter_sys_t int i_default_font_size; int i_display_height; #ifdef HAVE_FONTCONFIG - vlc_mutex_t *p_fontconfig_lock; bool b_fontconfig_ok; FcConfig *p_fontconfig; #endif @@ -367,7 +366,7 @@ static int Create( vlc_object_t *p_this ) #ifdef HAVE_FONTCONFIG p_sys->b_fontconfig_ok = false; p_sys->p_fontconfig = NULL; - p_sys->p_fontbuilder = FontBuilderAttach( p_filter, &p_sys->p_fontconfig_lock ); + p_sys->p_fontbuilder = FontBuilderAttach( p_filter ); #endif p_sys->i_use_kerning = FT_HAS_KERNING( p_sys->p_face ); @@ -434,10 +433,12 @@ static void Destroy( vlc_object_t *p_this ) } #ifdef HAVE_FONTCONFIG -static vlc_object_t *FontBuilderAttach( filter_t *p_filter, vlc_mutex_t **pp_lock ) +static vlc_mutex_t fb_lock = VLC_STATIC_MUTEX; + +static vlc_object_t *FontBuilderAttach( filter_t *p_filter ) { /* Check for an existing Fontbuilder thread */ - vlc_mutex_t *p_lock = var_AcquireMutex( "fontbuilder" ); + vlc_mutex_lock( &fb_lock ); vlc_object_t *p_fontbuilder = vlc_object_find_name( p_filter->p_libvlc, "fontlist builder", FIND_CHILD ); @@ -482,13 +483,12 @@ static vlc_object_t *FontBuilderAttach( filter_t *p_filter, vlc_mutex_t **pp_loc var_AddCallback( p_fontbuilder, "build-done", FontBuilderDone, p_filter ); FontBuilderGetFcConfig( p_filter, p_fontbuilder ); } - vlc_mutex_unlock( p_lock ); - *pp_lock = p_lock; + vlc_mutex_unlock( &fb_lock ); return p_fontbuilder; } static void FontBuilderDetach( filter_t *p_filter, vlc_object_t *p_fontbuilder ) { - vlc_mutex_t *lock = var_AcquireMutex( "fontbuilder" ); + vlc_mutex_lock( &fb_lock ); if( p_fontbuilder ) { const bool b_alive = vlc_object_alive( p_fontbuilder ); @@ -499,18 +499,18 @@ static void FontBuilderDetach( filter_t *p_filter, vlc_object_t *p_fontbuilder ) if( b_alive ) { vlc_object_kill( p_fontbuilder ); - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &fb_lock ); /* We need to unlock otherwise we may not join (the thread waiting * for the lock). It is safe to unlock as no one else will try a * join and we have a reference on the object) */ vlc_thread_join( p_fontbuilder ); - vlc_mutex_lock( lock ); + vlc_mutex_lock( &fb_lock ); } vlc_object_release( p_fontbuilder ); } - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &fb_lock ); } static void* FontBuilderThread( vlc_object_t *p_this ) { @@ -540,9 +540,9 @@ static void* FontBuilderThread( vlc_object_t *p_this ) msg_Dbg( p_this, "Finished building font database." ); msg_Dbg( p_this, "Took %ld seconds", (long)((t2 - t1)/1000000) ); - vlc_mutex_t *p_lock = var_AcquireMutex( "fontbuilder" ); + vlc_mutex_lock( &fb_lock ); p_this->p_private = p_fontconfig; - vlc_mutex_unlock( p_lock ); + vlc_mutex_unlock( &fb_lock ); var_SetBool( p_this, "build-done", true ); vlc_restorecancel (canc); @@ -570,11 +570,11 @@ static int FontBuilderDone( vlc_object_t *p_this, const char *psz_var, if( newval.b_bool ) { - vlc_mutex_t *p_lock = var_AcquireMutex( "fontbuilder" ); + vlc_mutex_lock( &fb_lock ); FontBuilderGetFcConfig( p_filter, p_this ); - vlc_mutex_unlock( p_lock ); + vlc_mutex_unlock( &fb_lock ); } VLC_UNUSED(psz_var); @@ -2019,7 +2019,7 @@ static int ProcessLines( filter_t *p_filter, { char *psz_fontfile = NULL; - vlc_mutex_lock( p_sys->p_fontconfig_lock ); + vlc_mutex_lock( &fb_lock ); if( p_sys->b_fontconfig_ok ) { /* FIXME Is there really a race condition between FontConfig_Select with default fontconfig(NULL) @@ -2030,7 +2030,7 @@ static int ProcessLines( filter_t *p_filter, p_style->b_italic, &i_idx ); } - vlc_mutex_unlock( p_sys->p_fontconfig_lock ); + vlc_mutex_unlock( &fb_lock ); if( psz_fontfile && ! *psz_fontfile ) { diff --git a/modules/misc/gnutls.c b/modules/misc/gnutls.c index 622807bdfd..c208b2cbf5 100644 --- a/modules/misc/gnutls.c +++ b/modules/misc/gnutls.c @@ -110,6 +110,8 @@ vlc_module_begin(); CACHE_SIZE_LONGTEXT, true ); vlc_module_end(); +static vlc_mutex_t gnutls_mutex = VLC_STATIC_MUTEX; + /** * Initializes GnuTLS with proper locking. * @return VLC_SUCCESS on success, a VLC error code otherwise. @@ -120,7 +122,7 @@ static int gnutls_Init (vlc_object_t *p_this) vlc_gcrypt_init (); /* GnuTLS depends on gcrypt */ - vlc_mutex_t *lock = var_AcquireMutex ("gnutls_mutex"); + vlc_mutex_lock (&gnutls_mutex); if (gnutls_global_init ()) { msg_Err (p_this, "cannot initialize GnuTLS"); @@ -139,7 +141,7 @@ static int gnutls_Init (vlc_object_t *p_this) ret = VLC_SUCCESS; error: - vlc_mutex_unlock (lock); + vlc_mutex_unlock (&gnutls_mutex); return ret; } @@ -149,11 +151,11 @@ error: */ static void gnutls_Deinit (vlc_object_t *p_this) { - vlc_mutex_t *lock = var_AcquireMutex( "gnutls_mutex" ); + vlc_mutex_lock (&gnutls_mutex); gnutls_global_deinit (); msg_Dbg (p_this, "GnuTLS deinitialized"); - vlc_mutex_unlock (lock); + vlc_mutex_unlock (&gnutls_mutex); } diff --git a/modules/misc/gtk_main.c b/modules/misc/gtk_main.c index 68a9c2848d..cfbfa4d1f2 100644 --- a/modules/misc/gtk_main.c +++ b/modules/misc/gtk_main.c @@ -82,14 +82,14 @@ vlc_module_begin(); linked_with_a_crap_library_which_uses_atexit(); vlc_module_end(); +static vlc_mutex_t gtk_lock = VLC_STATIC_MUTEX; + /***************************************************************************** * Open: initialize and create window *****************************************************************************/ static int Open( vlc_object_t *p_this ) { - vlc_mutex_t *lock; - - lock = var_AcquireMutex( "gtk" ); + vlc_mutex_lock( >k_lock ); if( i_refcount > 0 ) { @@ -119,7 +119,7 @@ static int Open( vlc_object_t *p_this ) } i_refcount++; - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( >k_lock ); return VLC_SUCCESS; } @@ -129,25 +129,19 @@ static int Open( vlc_object_t *p_this ) *****************************************************************************/ static void Close( vlc_object_t *p_this ) { - vlc_mutex_t *lock; - - lock = var_AcquireMutex( "gtk" ); + vlc_mutex_lock( >k_lock ); i_refcount--; - if( i_refcount > 0 ) + if( --i_refcount == 0 ) { - vlc_mutex_unlock( lock ); - return; - } - - gtk_main_quit(); - vlc_thread_join( p_gtk_main ); - - vlc_object_release( p_gtk_main ); - p_gtk_main = NULL; + gtk_main_quit(); + vlc_thread_join( p_gtk_main ); - vlc_mutex_unlock( lock ); + vlc_object_release( p_gtk_main ); + p_gtk_main = NULL; + } + vlc_mutex_unlock( >k_lock ); } static gint foo( gpointer bar ) { return TRUE; } diff --git a/modules/misc/qte_main.cpp b/modules/misc/qte_main.cpp index f97082252a..550eaf30f8 100644 --- a/modules/misc/qte_main.cpp +++ b/modules/misc/qte_main.cpp @@ -82,19 +82,19 @@ vlc_module_end(); } /* extern "C" */ +static vlc_mutex_t qte_lock = VLC_STATIC_MUTEX; + /***************************************************************************** * Open: initialize and create window *****************************************************************************/ static int Open( vlc_object_t *p_this ) { - vlc_mutex_t *lock; - - lock = var_AcquireMutex( "qte" ); + vlc_mutex_lock( &qte_lock ); if( i_refcount > 0 ) { i_refcount++; - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &qte_lock ); return VLC_SUCCESS; } @@ -113,7 +113,7 @@ static int Open( vlc_object_t *p_this ) } i_refcount++; - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &qte_lock ); vlc_object_attach( p_qte_main, p_this ); msg_Dbg( p_this, "qte_main running" ); @@ -126,9 +126,7 @@ static int Open( vlc_object_t *p_this ) *****************************************************************************/ static void Close( vlc_object_t *p_this ) { - vlc_mutex_t *lock; - - lock = var_AcquireMutex( "qte" ); + vlc_mutex_lock( &qte_lock ); i_refcount--; @@ -149,7 +147,7 @@ static void Close( vlc_object_t *p_this ) vlc_object_release( p_qte_main ); p_qte_main = NULL; - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &qte_lock ); } /***************************************************************************** diff --git a/modules/video_output/sdl.c b/modules/video_output/sdl.c index cd21e8b28e..7fcba44785 100644 --- a/modules/video_output/sdl.c +++ b/modules/video_output/sdl.c @@ -135,6 +135,8 @@ vlc_module_begin(); #endif vlc_module_end(); +static vlc_mutex_t sdl_lock = VLC_STATIC_MUTEX; + /***************************************************************************** * OpenVideo: allocate SDL video thread output method ***************************************************************************** @@ -146,7 +148,7 @@ 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_AcquireMutex( "sdl" ); + vlc_mutex_lock( &sdl_lock ); #ifdef HAVE_SETENV char *psz_method; @@ -158,7 +160,7 @@ static int Open ( vlc_object_t *p_this ) p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( p_vout->p_sys == NULL ) { - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &sdl_lock ); return VLC_ENOMEM; } @@ -167,7 +169,7 @@ static int Open ( vlc_object_t *p_this ) /* Check if SDL video module has been initialized */ if( SDL_WasInit( SDL_INIT_VIDEO ) != 0 ) { - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &sdl_lock ); free( p_vout->p_sys ); return VLC_EGENERIC; } @@ -212,11 +214,11 @@ static int Open ( vlc_object_t *p_this ) { msg_Err( p_vout, "cannot initialize SDL (%s)", SDL_GetError() ); free( p_vout->p_sys ); - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &sdl_lock ); return VLC_EGENERIC; } - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &sdl_lock ); /* Translate keys into unicode */ SDL_EnableUNICODE(1); diff --git a/src/libvlc.c b/src/libvlc.c index 00bcf0b611..6e3bcd6896 100644 --- a/src/libvlc.c +++ b/src/libvlc.c @@ -228,6 +228,8 @@ static int VerboseCallback( vlc_object_t *, char const *, static void InitDeviceValues( libvlc_int_t * ); +vlc_mutex_t global_lock = VLC_STATIC_MUTEX; + /** * Allocate a libvlc instance, initialize global data if needed * It also initializes the threading system @@ -240,7 +242,7 @@ libvlc_int_t * libvlc_InternalCreate( void ) /* Now that the thread system is initialized, we don't have much, but * at least we have variables */ - vlc_mutex_t *lock = var_AcquireMutex( "libvlc" ); + vlc_mutex_lock( &global_lock ); if( i_instances == 0 ) { /* Guess what CPU we have */ @@ -254,7 +256,7 @@ libvlc_int_t * libvlc_InternalCreate( void ) VLC_OBJECT_GENERIC, "libvlc" ); if( p_libvlc != NULL ) i_instances++; - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &global_lock ); if( p_libvlc == NULL ) return NULL; @@ -1136,7 +1138,7 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc ) p_libvlc->p_hotkeys ); FREENULL( p_libvlc->p_hotkeys ); - vlc_mutex_t *lock = var_AcquireMutex( "libvlc" ); + vlc_mutex_lock( &global_lock ); i_instances--; if( i_instances == 0 ) @@ -1144,7 +1146,7 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc ) /* System specific cleaning code */ system_End( p_libvlc ); } - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &global_lock ); msg_Flush( p_libvlc ); msg_Destroy( p_libvlc ); diff --git a/src/libvlc.h b/src/libvlc.h index c531a4d9c3..f312073572 100644 --- a/src/libvlc.h +++ b/src/libvlc.h @@ -45,6 +45,7 @@ void system_End ( libvlc_int_t * ); /* * Threads subsystem */ +vlc_mutex_t global_lock; /* TODO: remove this crap */ /* Hopefully, no need to export this. There is a new thread API instead. */ void vlc_thread_cancel (vlc_object_t *); diff --git a/src/misc/messages.c b/src/misc/messages.c index ed866dc7df..468e665cd6 100644 --- a/src/misc/messages.c +++ b/src/misc/messages.c @@ -87,6 +87,8 @@ static void QueueMsg ( vlc_object_t *, int, const char *, static void FlushMsg ( msg_queue_t * ); static void PrintMsg ( vlc_object_t *, msg_item_t * ); +static vlc_mutex_t msg_stack_lock = VLC_STATIC_MUTEX; + /** * Initialize messages queues * This function initializes all message queues @@ -113,10 +115,10 @@ void msg_Create (libvlc_int_t *p_libvlc) SetFilePointer( QUEUE.logfile, 0, NULL, FILE_END ); #endif - vlc_mutex_t *lock = var_AcquireMutex( "msg-stack" ); + vlc_mutex_lock( &msg_stack_lock ); if( banks++ == 0 ) vlc_threadvar_create( &msg_context, NULL ); - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &msg_stack_lock ); } /** @@ -175,10 +177,10 @@ void msg_Destroy (libvlc_int_t *p_libvlc) FlushMsg( &QUEUE ); - vlc_mutex_t *lock = var_AcquireMutex( "msg-stack" ); + vlc_mutex_lock( &msg_stack_lock ); if( --banks == 0 ) vlc_threadvar_delete( &msg_context ); - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &msg_stack_lock ); #ifdef UNDER_CE CloseHandle( QUEUE.logfile ); diff --git a/src/modules/modules.c b/src/modules/modules.c index ee036e3131..5e6d6aff2b 100644 --- a/src/modules/modules.c +++ b/src/modules/modules.c @@ -120,7 +120,7 @@ void __module_InitBank( vlc_object_t *p_this ) { module_bank_t *p_bank = NULL; - vlc_mutex_t *lock = var_AcquireMutex( "libvlc" ); + vlc_mutex_lock( &global_lock ); if( p_module_bank == NULL ) { @@ -145,7 +145,7 @@ void __module_InitBank( vlc_object_t *p_this ) else p_module_bank->i_usage++; - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &global_lock ); } @@ -161,17 +161,17 @@ void __module_EndBank( vlc_object_t *p_this ) { module_bank_t *p_bank; - vlc_mutex_t *lock = var_AcquireMutex( "libvlc" ); + vlc_mutex_lock( &global_lock ); p_bank = p_module_bank; assert (p_bank != NULL); if( --p_bank->i_usage > 0 ) { - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &global_lock ); return; } /*FIXME: For thread safety, we need to: p_module_bank = NULL; - immediately, but that will crash the cache */ - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &global_lock ); /* Save the configuration */ config_AutoSaveConfigFile( p_this ); @@ -223,14 +223,14 @@ void __module_EndBank( vlc_object_t *p_this ) */ void __module_LoadBuiltins( vlc_object_t * p_this ) { - vlc_mutex_t *lock = var_AcquireMutex( "libvlc" ); + vlc_mutex_lock( &global_lock ); if( p_module_bank->b_builtins ) { - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &global_lock ); return; } p_module_bank->b_builtins = true; - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &global_lock ); msg_Dbg( p_this, "checking builtin modules" ); ALLOCATE_ALL_BUILTINS(); @@ -247,14 +247,14 @@ void __module_LoadBuiltins( vlc_object_t * p_this ) void __module_LoadPlugins( vlc_object_t * p_this ) { #ifdef HAVE_DYNAMIC_PLUGINS - vlc_mutex_t *lock = var_AcquireMutex( "libvlc" ); + vlc_mutex_lock( &global_lock ); if( p_module_bank->b_plugins ) { - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &global_lock ); return; } p_module_bank->b_plugins = true; - vlc_mutex_unlock( lock ); + vlc_mutex_unlock( &global_lock ); msg_Dbg( p_this, "checking plugin modules" );