[VDPAU] [PATCH 2/4] vdpau_wrapper: make the fixes initialization thread-safe

Aaron Plattner aplattner at nvidia.com
Tue Nov 4 15:57:46 PST 2014


On 10/29/2014 05:47 AM, Rémi Denis-Courmont wrote:
> From: Rémi Denis-Courmont <remid at nvidia.com>

This kind of seems like overkill if the very next patch adds a mutex, 
but it doesn't hurt.

Reviewed-by: Aaron Plattner <aplattner at nvidia.com>

> ---
>   src/Makefile.am     |  1 +
>   src/vdpau_wrapper.c | 10 +++-------
>   2 files changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/src/Makefile.am b/src/Makefile.am
> index 2e8e868..0ce8460 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -21,6 +21,7 @@ endif
>
>   libvdpau_la_LIBADD = \
>       $(DLOPEN_LIBS) \
> +    $(PTHREAD_LIBS) \
>       $(XEXT_LIBS)
>
>   libvdpau_la_LDFLAGS = -version-info 1:0:0 -no-undefined
> diff --git a/src/vdpau_wrapper.c b/src/vdpau_wrapper.c
> index c6ab2ca..0360d4d 100644
> --- a/src/vdpau_wrapper.c
> +++ b/src/vdpau_wrapper.c
> @@ -27,6 +27,7 @@
>
>   #include <dlfcn.h>
>   #include <limits.h>
> +#include <pthread.h>
>   #include <stdio.h>
>   #include <stdlib.h>
>   #include <string.h>
> @@ -240,7 +241,6 @@ static VdpVideoSurfacePutBitsYCbCr * _imp_vid_put_bits_y_cb_cr;
>   static VdpDecoderQueryCapabilities * _imp_decoder_query_capabilities;
>   static VdpDecoderCreate * _imp_decoder_create;
>   static VdpPresentationQueueSetBackgroundColor * _imp_pq_set_bg_color;
> -static int _inited_fixes;
>   static int _running_under_flash;
>   static int _enable_flash_uv_swap = 1;
>   static int _disable_flash_pq_bg_color = 1;
> @@ -512,11 +512,6 @@ static void init_config(void)
>
>   static void init_fixes(void)
>   {
> -    if (_inited_fixes) {
> -        return;
> -    }
> -    _inited_fixes = 1;
> -
>       init_running_under_flash();
>       init_config();
>   }
> @@ -529,9 +524,10 @@ VdpStatus vdp_device_create_x11(
>       VdpGetProcAddress * * get_proc_address
>   )
>   {
> +    static pthread_once_t once = PTHREAD_ONCE_INIT;
>       VdpStatus status;
>
> -    init_fixes();
> +    pthread_once(&once, init_fixes);
>
>       if (!_vdp_imp_device_create_x11_proc) {
>           status = _vdp_open_driver(display, screen);
>


-- 
Aaron


More information about the VDPAU mailing list