[vlc-devel] [PATCH V2 03/17] resource: merge both locks
Thomas Guillem
thomas at gllm.fr
Tue Apr 16 16:25:13 CEST 2019
I don't think this is needed anymore. Indeed,vout_Create() is non blocking and
it is a fast call, vout_Request() will be called unlocked (cf. next patch).
---
src/input/resource.c | 48 +++++++++++++++-----------------------------
1 file changed, 16 insertions(+), 32 deletions(-)
diff --git a/src/input/resource.c b/src/input/resource.c
index 13b4b97d07..6751950ef3 100644
--- a/src/input/resource.c
+++ b/src/input/resource.c
@@ -49,8 +49,7 @@ struct input_resource_t
vlc_object_t *p_parent;
- /* This lock is used to serialize request and protect
- * our variables */
+ /* This lock is used to serialize request and protect our variables */
vlc_mutex_t lock;
/* */
@@ -59,14 +58,7 @@ struct input_resource_t
sout_instance_t *p_sout;
vout_thread_t *p_vout_free;
- /* This lock is used to protect vout resources access (for hold)
- * It is a special case because of embed video (possible deadlock
- * between vout window request and vout holds in some(qt) interface)
- */
- vlc_mutex_t lock_hold;
-
- /* You need lock+lock_hold to write to the following variables and
- * only lock or lock_hold to read them */
+ /* You need lock to read/write to the following variables */
vout_thread_t **pp_vout;
int i_vout;
@@ -199,19 +191,19 @@ audio_output_t *input_resource_GetAout( input_resource_t *p_resource )
{
audio_output_t *p_aout;
- vlc_mutex_lock( &p_resource->lock_hold );
+ vlc_mutex_lock( &p_resource->lock );
p_aout = p_resource->p_aout;
if( p_aout == NULL || p_resource->b_aout_busy )
{
msg_Dbg( p_resource->p_parent, "creating audio output" );
- vlc_mutex_unlock( &p_resource->lock_hold );
+ vlc_mutex_unlock( &p_resource->lock );
p_aout = aout_New( p_resource->p_parent );
if( p_aout == NULL )
return NULL; /* failed */
- vlc_mutex_lock( &p_resource->lock_hold );
+ vlc_mutex_lock( &p_resource->lock );
if( p_resource->p_aout == NULL )
p_resource->p_aout = p_aout;
}
@@ -223,7 +215,7 @@ audio_output_t *input_resource_GetAout( input_resource_t *p_resource )
assert( !p_resource->b_aout_busy );
p_resource->b_aout_busy = true;
}
- vlc_mutex_unlock( &p_resource->lock_hold );
+ vlc_mutex_unlock( &p_resource->lock );
return p_aout;
}
@@ -232,7 +224,7 @@ void input_resource_PutAout( input_resource_t *p_resource,
{
assert( p_aout != NULL );
- vlc_mutex_lock( &p_resource->lock_hold );
+ vlc_mutex_lock( &p_resource->lock );
if( p_aout == p_resource->p_aout )
{
assert( p_resource->b_aout_busy );
@@ -242,7 +234,7 @@ void input_resource_PutAout( input_resource_t *p_resource,
}
else
msg_Dbg( p_resource->p_parent, "destroying extra audio output" );
- vlc_mutex_unlock( &p_resource->lock_hold );
+ vlc_mutex_unlock( &p_resource->lock );
if( p_aout != NULL )
aout_Destroy( p_aout );
@@ -252,11 +244,11 @@ audio_output_t *input_resource_HoldAout( input_resource_t *p_resource )
{
audio_output_t *p_aout;
- vlc_mutex_lock( &p_resource->lock_hold );
+ vlc_mutex_lock( &p_resource->lock );
p_aout = p_resource->p_aout;
if( p_aout != NULL )
aout_Hold(p_aout);
- vlc_mutex_unlock( &p_resource->lock_hold );
+ vlc_mutex_unlock( &p_resource->lock );
return p_aout;
}
@@ -265,13 +257,13 @@ void input_resource_ResetAout( input_resource_t *p_resource )
{
audio_output_t *p_aout = NULL;
- vlc_mutex_lock( &p_resource->lock_hold );
+ vlc_mutex_lock( &p_resource->lock );
if( !p_resource->b_aout_busy )
p_aout = p_resource->p_aout;
p_resource->p_aout = NULL;
p_resource->b_aout_busy = false;
- vlc_mutex_unlock( &p_resource->lock_hold );
+ vlc_mutex_unlock( &p_resource->lock );
if( p_aout != NULL )
aout_Destroy( p_aout );
@@ -287,7 +279,6 @@ input_resource_t *input_resource_New( vlc_object_t *p_parent )
vlc_atomic_rc_init( &p_resource->rc );
p_resource->p_parent = p_parent;
vlc_mutex_init( &p_resource->lock );
- vlc_mutex_init( &p_resource->lock_hold );
return p_resource;
}
@@ -301,7 +292,6 @@ void input_resource_Release( input_resource_t *p_resource )
if( p_resource->p_aout != NULL )
aout_Destroy( p_resource->p_aout );
- vlc_mutex_destroy( &p_resource->lock_hold );
vlc_mutex_destroy( &p_resource->lock );
free( p_resource );
}
@@ -350,9 +340,7 @@ vout_thread_t *input_resource_GetVout(input_resource_t *p_resource,
} else if (cfg->vout != NULL) {
assert(cfg->vout != p_resource->p_vout_free);
- vlc_mutex_lock(&p_resource->lock_hold);
TAB_REMOVE(p_resource->i_vout, p_resource->pp_vout, cfg->vout);
- vlc_mutex_unlock(&p_resource->lock_hold);
}
if (vout_Request(cfg, p_resource->p_input)) {
@@ -369,9 +357,7 @@ vout_thread_t *input_resource_GetVout(input_resource_t *p_resource,
input_Control(p_resource->p_input, INPUT_SET_INITIAL_VIEWPOINT,
&cfg->fmt->pose);
- vlc_mutex_lock(&p_resource->lock_hold);
TAB_APPEND(p_resource->i_vout, p_resource->pp_vout, vout);
- vlc_mutex_unlock(&p_resource->lock_hold);
out:
vlc_mutex_unlock( &p_resource->lock );
@@ -384,11 +370,9 @@ void input_resource_PutVout(input_resource_t *p_resource,
assert(vout != NULL);
vlc_mutex_lock( &p_resource->lock );
- vlc_mutex_lock(&p_resource->lock_hold);
TAB_REMOVE(p_resource->i_vout, p_resource->pp_vout, vout);
const int active_vouts = p_resource->i_vout;
- vlc_mutex_unlock(&p_resource->lock_hold);
if (p_resource->p_vout_free != NULL || active_vouts > 0) {
msg_Dbg(p_resource->p_parent, "destroying vout (already one saved or active)");
@@ -403,13 +387,13 @@ void input_resource_PutVout(input_resource_t *p_resource,
vout_thread_t *input_resource_HoldVout( input_resource_t *p_resource )
{
/* TODO FIXME: p_resource->pp_vout order is NOT stable */
- vlc_mutex_lock( &p_resource->lock_hold );
+ vlc_mutex_lock( &p_resource->lock );
vout_thread_t *p_vout = p_resource->i_vout > 0 ? p_resource->pp_vout[0] : NULL;
if( p_vout )
vout_Hold(p_vout);
- vlc_mutex_unlock( &p_resource->lock_hold );
+ vlc_mutex_unlock( &p_resource->lock );
return p_vout;
}
@@ -422,7 +406,7 @@ void input_resource_HoldVouts( input_resource_t *p_resource, vout_thread_t ***pp
*pi_vout = 0;
*ppp_vout = NULL;
- vlc_mutex_lock( &p_resource->lock_hold );
+ vlc_mutex_lock( &p_resource->lock );
if( p_resource->i_vout <= 0 )
goto exit;
@@ -441,7 +425,7 @@ void input_resource_HoldVouts( input_resource_t *p_resource, vout_thread_t ***pp
}
exit:
- vlc_mutex_unlock( &p_resource->lock_hold );
+ vlc_mutex_unlock( &p_resource->lock );
}
void input_resource_TerminateVout( input_resource_t *p_resource )
--
2.20.1
More information about the vlc-devel
mailing list