[vlc-devel] [PATCH 1/7] skins2: use semaphore to simplify init

Thomas Guillem thomas at gllm.fr
Tue Feb 4 10:10:52 CET 2020


LGTM

On Mon, Feb 3, 2020, at 22:13, RĂ©mi Denis-Courmont wrote:
> ---
>  modules/gui/skins2/src/skin_common.hpp |  4 +---
>  modules/gui/skins2/src/skin_main.cpp   | 32 +++++---------------------
>  2 files changed, 7 insertions(+), 29 deletions(-)
> 
> diff --git a/modules/gui/skins2/src/skin_common.hpp 
> b/modules/gui/skins2/src/skin_common.hpp
> index 43f4186215..20ce3bbe1e 100644
> --- a/modules/gui/skins2/src/skin_common.hpp
> +++ b/modules/gui/skins2/src/skin_common.hpp
> @@ -115,10 +115,8 @@ struct intf_sys_t
>  
>      /// synchronisation at start of interface
>      vlc_thread_t thread;
> -    vlc_mutex_t  init_lock;
> -    vlc_cond_t   init_wait;
> +    vlc_sem_t    init_wait;
>      bool         b_error;
> -    bool         b_ready;
>  };
>  
>  
> diff --git a/modules/gui/skins2/src/skin_main.cpp 
> b/modules/gui/skins2/src/skin_main.cpp
> index d52e904d8d..0f3ba6aacf 100644
> --- a/modules/gui/skins2/src/skin_main.cpp
> +++ b/modules/gui/skins2/src/skin_main.cpp
> @@ -94,35 +94,24 @@ static int Open( vlc_object_t *p_this )
>      // No theme yet
>      p_intf->p_sys->p_theme = NULL;
>  
> -    vlc_mutex_init( &p_intf->p_sys->init_lock );
> -    vlc_cond_init( &p_intf->p_sys->init_wait );
> -
> -    vlc_mutex_lock( &p_intf->p_sys->init_lock );
> +    vlc_sem_init( &p_intf->p_sys->init_wait, 0 );
>      p_intf->p_sys->b_error = false;
> -    p_intf->p_sys->b_ready = false;
>  
>      if( vlc_clone( &p_intf->p_sys->thread, Run, p_intf,
>                                 VLC_THREAD_PRIORITY_LOW ) )
>      {
> -        vlc_mutex_unlock( &p_intf->p_sys->init_lock );
> -
> -        vlc_cond_destroy( &p_intf->p_sys->init_wait );
> -        vlc_mutex_destroy( &p_intf->p_sys->init_lock );
> +        vlc_sem_destroy( &p_intf->p_sys->init_wait );
>          free( p_intf->p_sys );
>          return VLC_EGENERIC;
>      }
>  
> -    while( !p_intf->p_sys->b_ready )
> -        vlc_cond_wait( &p_intf->p_sys->init_wait, &p_intf->p_sys->init_lock );
> -    vlc_mutex_unlock( &p_intf->p_sys->init_lock );
> +    vlc_sem_wait( &p_intf->p_sys->init_wait );
> +    vlc_sem_destroy( &p_intf->p_sys->init_wait );
>  
>      if( p_intf->p_sys->b_error )
>      {
>          vlc_join( p_intf->p_sys->thread, NULL );
>  
> -        vlc_mutex_destroy( &p_intf->p_sys->init_lock );
> -        vlc_cond_destroy( &p_intf->p_sys->init_wait );
> -
>          free( p_intf->p_sys );
>          return VLC_EGENERIC;
>      }
> @@ -167,9 +156,6 @@ static void Close( vlc_object_t *p_this )
>  
>      vlc_join( p_intf->p_sys->thread, NULL );
>  
> -    vlc_mutex_destroy( &p_intf->p_sys->init_lock );
> -    vlc_cond_destroy( &p_intf->p_sys->init_wait );
> -
>      // Destroy structure
>      free( p_intf->p_sys );
>  }
> @@ -189,8 +175,6 @@ static void *Run( void * p_obj )
>      ThemeLoader *pLoader = NULL;
>      OSLoop *loop = NULL;
>  
> -    vlc_mutex_lock( &p_intf->p_sys->init_lock );
> -
>      // Initialize singletons
>      if( OSFactory::instance( p_intf ) == NULL )
>      {
> @@ -268,9 +252,7 @@ static void *Run( void * p_obj )
>  
>      // Signal the main thread this thread is now ready
>      p_intf->p_sys->b_error = false;
> -    p_intf->p_sys->b_ready = true;
> -    vlc_cond_signal( &p_intf->p_sys->init_wait );
> -    vlc_mutex_unlock( &p_intf->p_sys->init_lock );
> +    vlc_sem_post( &p_intf->p_sys->init_wait );
>  
>      // Enter the main event loop
>      loop->run();
> @@ -307,9 +289,7 @@ end:
>      if( b_error )
>      {
>          p_intf->p_sys->b_error = true;
> -        p_intf->p_sys->b_ready = true;
> -        vlc_cond_signal( &p_intf->p_sys->init_wait );
> -        vlc_mutex_unlock( &p_intf->p_sys->init_lock );
> +        vlc_sem_post( &p_intf->p_sys->init_wait );
>      }
>  
>      vlc_restorecancel(canc);
> -- 
> 2.25.0
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list