[vlc-commits] skins2: use semaphore to simplify init
Rémi Denis-Courmont
git at videolan.org
Tue Feb 4 19:02:07 CET 2020
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Feb 3 22:31:09 2020 +0200| [fc0149364dd5238876f8c5fb2147aa4c5d9d4af8] | committer: Rémi Denis-Courmont
skins2: use semaphore to simplify init
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fc0149364dd5238876f8c5fb2147aa4c5d9d4af8
---
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);
More information about the vlc-commits
mailing list