Commit 98628170 authored by Sébastien Escudier's avatar Sébastien Escudier Committed by Rémi Denis-Courmont

VLM : add a dedicated mutex for the manage thread. We must not del callback while mutex is locked.

Signed-off-by: default avatarRémi Denis-Courmont <remi@remlab.net>
parent b28c3623
...@@ -105,9 +105,10 @@ static int InputEvent( vlc_object_t *p_this, char const *psz_cmd, ...@@ -105,9 +105,10 @@ static int InputEvent( vlc_object_t *p_this, char const *psz_cmd,
} }
vlm_SendEventMediaInstanceState( p_vlm, p_media->cfg.id, p_media->cfg.psz_name, psz_instance_name, var_GetInteger( p_input, "state" ) ); vlm_SendEventMediaInstanceState( p_vlm, p_media->cfg.id, p_media->cfg.psz_name, psz_instance_name, var_GetInteger( p_input, "state" ) );
vlc_mutex_lock( &p_vlm->lock ); vlc_mutex_lock( &p_vlm->lock_manage );
vlc_cond_signal( &p_vlm->wait ); p_vlm->input_state_changed = true;
vlc_mutex_unlock( &p_vlm->lock ); vlc_cond_signal( &p_vlm->wait_manage );
vlc_mutex_unlock( &p_vlm->lock_manage );
} }
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -146,7 +147,9 @@ vlm_t *vlm_New ( vlc_object_t *p_this ) ...@@ -146,7 +147,9 @@ vlm_t *vlm_New ( vlc_object_t *p_this )
} }
vlc_mutex_init( &p_vlm->lock ); vlc_mutex_init( &p_vlm->lock );
vlc_cond_init_daytime( &p_vlm->wait ); vlc_mutex_init( &p_vlm->lock_manage );
vlc_cond_init_daytime( &p_vlm->wait_manage );
p_vlm->input_state_changed = false;
p_vlm->i_id = 1; p_vlm->i_id = 1;
TAB_INIT( p_vlm->i_media, p_vlm->media ); TAB_INIT( p_vlm->i_media, p_vlm->media );
TAB_INIT( p_vlm->i_schedule, p_vlm->schedule ); TAB_INIT( p_vlm->i_schedule, p_vlm->schedule );
...@@ -157,8 +160,9 @@ vlm_t *vlm_New ( vlc_object_t *p_this ) ...@@ -157,8 +160,9 @@ vlm_t *vlm_New ( vlc_object_t *p_this )
if( vlc_clone( &p_vlm->thread, Manage, p_vlm, VLC_THREAD_PRIORITY_LOW ) ) if( vlc_clone( &p_vlm->thread, Manage, p_vlm, VLC_THREAD_PRIORITY_LOW ) )
{ {
vlc_cond_destroy( &p_vlm->wait ); vlc_cond_destroy( &p_vlm->wait_manage );
vlc_mutex_destroy( &p_vlm->lock ); vlc_mutex_destroy( &p_vlm->lock );
vlc_mutex_destroy( &p_vlm->lock_manage );
vlc_object_release( p_vlm ); vlc_object_release( p_vlm );
vlc_mutex_unlock( &vlm_mutex ); vlc_mutex_unlock( &vlm_mutex );
return NULL; return NULL;
...@@ -210,23 +214,28 @@ void vlm_Delete( vlm_t *p_vlm ) ...@@ -210,23 +214,28 @@ void vlm_Delete( vlm_t *p_vlm )
*****************************************************************************/ *****************************************************************************/
static void vlm_Destructor( vlm_t *p_vlm ) static void vlm_Destructor( vlm_t *p_vlm )
{ {
vlc_mutex_lock( &p_vlm->lock );
vlm_ControlInternal( p_vlm, VLM_CLEAR_MEDIAS ); vlm_ControlInternal( p_vlm, VLM_CLEAR_MEDIAS );
TAB_CLEAN( p_vlm->i_media, p_vlm->media ); TAB_CLEAN( p_vlm->i_media, p_vlm->media );
vlm_ControlInternal( p_vlm, VLM_CLEAR_SCHEDULES ); vlm_ControlInternal( p_vlm, VLM_CLEAR_SCHEDULES );
TAB_CLEAN( p_vlm->schedule, p_vlm->schedule ); TAB_CLEAN( p_vlm->schedule, p_vlm->schedule );
vlc_mutex_lock( &p_vlm->lock );
vlc_cond_signal( &p_vlm->wait );
vlc_mutex_unlock( &p_vlm->lock ); vlc_mutex_unlock( &p_vlm->lock );
libvlc_priv(p_vlm->p_libvlc)->p_vlm = NULL; libvlc_priv(p_vlm->p_libvlc)->p_vlm = NULL;
vlc_object_kill( p_vlm ); vlc_object_kill( p_vlm );
vlc_mutex_lock( &p_vlm->lock_manage );
p_vlm->input_state_changed = true;
vlc_cond_signal( &p_vlm->wait_manage );
vlc_mutex_unlock( &p_vlm->lock_manage );
/*vlc_cancel( p_vlm->thread ); */ /*vlc_cancel( p_vlm->thread ); */
vlc_join( p_vlm->thread, NULL ); vlc_join( p_vlm->thread, NULL );
vlc_cond_destroy( &p_vlm->wait ); vlc_cond_destroy( &p_vlm->wait_manage );
vlc_mutex_destroy( &p_vlm->lock ); vlc_mutex_destroy( &p_vlm->lock );
vlc_mutex_destroy( &p_vlm->lock_manage );
} }
/***************************************************************************** /*****************************************************************************
...@@ -365,18 +374,24 @@ static void* Manage( void* p_object ) ...@@ -365,18 +374,24 @@ static void* Manage( void* p_object )
int canc = vlc_savecancel (); int canc = vlc_savecancel ();
i_lastcheck = vlm_Date(); i_lastcheck = vlm_Date();
vlc_mutex_lock( &vlm->lock );
while( !vlm->b_die ) while( !vlm->b_die )
{ {
char **ppsz_scheduled_commands = NULL; char **ppsz_scheduled_commands = NULL;
int i_scheduled_commands = 0; int i_scheduled_commands = 0;
bool scheduled_command = false;
vlc_mutex_lock( &vlm->lock_manage );
while( !vlm->input_state_changed && !scheduled_command )
{
if( i_nextschedule ) if( i_nextschedule )
vlc_cond_timedwait( &vlm->wait, &vlm->lock, i_nextschedule ); scheduled_command = vlc_cond_timedwait( &vlm->wait_manage, &vlm->lock_manage, i_nextschedule ) != 0;
else else
vlc_cond_wait( &vlm->wait, &vlm->lock ); vlc_cond_wait( &vlm->wait_manage, &vlm->lock_manage );
}
vlm->input_state_changed = false;
vlc_mutex_unlock( &vlm->lock_manage );
/* destroy the inputs that wants to die, and launch the next input */ /* destroy the inputs that wants to die, and launch the next input */
vlc_mutex_lock( &vlm->lock );
for( i = 0; i < vlm->i_media; i++ ) for( i = 0; i < vlm->i_media; i++ )
{ {
vlm_media_sys_t *p_media = vlm->media[i]; vlm_media_sys_t *p_media = vlm->media[i];
...@@ -473,9 +488,9 @@ static void* Manage( void* p_object ) ...@@ -473,9 +488,9 @@ static void* Manage( void* p_object )
} }
i_lastcheck = i_time; i_lastcheck = i_time;
vlc_mutex_unlock( &vlm->lock );
} }
vlc_mutex_unlock( &vlm->lock );
vlc_restorecancel (canc); vlc_restorecancel (canc);
return NULL; return NULL;
...@@ -850,14 +865,13 @@ static void vlm_MediaInstanceDelete( vlm_t *p_vlm, int64_t id, vlm_media_instanc ...@@ -850,14 +865,13 @@ static void vlm_MediaInstanceDelete( vlm_t *p_vlm, int64_t id, vlm_media_instanc
{ {
input_resource_t *p_resource; input_resource_t *p_resource;
var_DelCallback( p_instance->p_input, "intf-event", InputEvent, p_media );
input_Stop( p_input, true ); input_Stop( p_input, true );
vlc_thread_join( p_input ); vlc_thread_join( p_input );
p_resource = input_DetachResource( p_input ); p_resource = input_DetachResource( p_input );
input_resource_Delete( p_resource ); input_resource_Delete( p_resource );
var_DelCallback( p_instance->p_input, "intf-event", InputEvent, p_media );
vlc_object_release( p_input ); vlc_object_release( p_input );
vlm_SendEventMediaInstanceStopped( p_vlm, id, p_media->cfg.psz_name ); vlm_SendEventMediaInstanceStopped( p_vlm, id, p_media->cfg.psz_name );
...@@ -936,13 +950,13 @@ static int vlm_ControlMediaInstanceStart( vlm_t *p_vlm, int64_t id, const char * ...@@ -936,13 +950,13 @@ static int vlm_ControlMediaInstanceStart( vlm_t *p_vlm, int64_t id, const char *
return VLC_SUCCESS; return VLC_SUCCESS;
} }
var_DelCallback( p_instance->p_input, "intf-event", InputEvent, p_media );
input_Stop( p_input, true ); input_Stop( p_input, true );
vlc_thread_join( p_input ); vlc_thread_join( p_input );
p_instance->p_input_resource = input_DetachResource( p_input ); p_instance->p_input_resource = input_DetachResource( p_input );
var_DelCallback( p_instance->p_input, "intf-event", InputEvent, p_media );
vlc_object_release( p_input ); vlc_object_release( p_input );
if( !p_instance->b_sout_keep ) if( !p_instance->b_sout_keep )
......
...@@ -90,8 +90,10 @@ struct vlm_t ...@@ -90,8 +90,10 @@ struct vlm_t
vlc_mutex_t lock; vlc_mutex_t lock;
vlc_thread_t thread; vlc_thread_t thread;
vlc_cond_t wait; vlc_mutex_t lock_manage;
vlc_cond_t wait_manage;
/* tell vlm thread there is work to do */
bool input_state_changed;
/* */ /* */
int64_t i_id; int64_t i_id;
......
...@@ -665,9 +665,10 @@ static int ExecuteScheduleProperty( vlm_t *p_vlm, vlm_schedule_sys_t *p_schedule ...@@ -665,9 +665,10 @@ static int ExecuteScheduleProperty( vlm_t *p_vlm, vlm_schedule_sys_t *p_schedule
} }
*pp_status = vlm_MessageSimpleNew( psz_cmd ); *pp_status = vlm_MessageSimpleNew( psz_cmd );
vlc_mutex_lock( &p_vlm->lock ); vlc_mutex_lock( &p_vlm->lock_manage );
vlc_cond_signal( &p_vlm->wait ); p_vlm->input_state_changed = true;
vlc_mutex_unlock( &p_vlm->lock ); vlc_cond_signal( &p_vlm->wait_manage );
vlc_mutex_unlock( &p_vlm->lock_manage );
return VLC_SUCCESS; return VLC_SUCCESS;
......
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