[vlc-commits] resource: simplify & reduce aout locking
Rémi Denis-Courmont
git at videolan.org
Mon Mar 10 18:19:12 CET 2014
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Mar 10 18:31:54 2014 +0200| [bf62d22f2ae05b41b62c603da72f3e680e5ec4d7] | committer: Rémi Denis-Courmont
resource: simplify & reduce aout locking
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=bf62d22f2ae05b41b62c603da72f3e680e5ec4d7
---
src/input/resource.c | 41 ++++++++++++++++++-----------------------
1 file changed, 18 insertions(+), 23 deletions(-)
diff --git a/src/input/resource.c b/src/input/resource.c
index 17e7099..aee2f68 100644
--- a/src/input/resource.c
+++ b/src/input/resource.c
@@ -330,33 +330,31 @@ audio_output_t *input_resource_GetAout( input_resource_t *p_resource )
{
audio_output_t *p_aout;
- vlc_mutex_lock( &p_resource->lock );
- if( p_resource->b_aout_busy )
- {
- vlc_mutex_unlock( &p_resource->lock );
- msg_Dbg( p_resource->p_parent, "creating extra audio output" );
- return aout_New( p_resource->p_parent );
- }
-
+ vlc_mutex_lock( &p_resource->lock_hold );
p_aout = p_resource->p_aout;
- if( p_aout == NULL )
+
+ 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 );
+
p_aout = aout_New( p_resource->p_parent );
+ if( p_aout == NULL )
+ return NULL; /* failed */
+
+ vlc_mutex_lock( &p_resource->lock_hold );
+ if( p_resource->p_aout == NULL )
+ p_resource->p_aout = p_aout;
}
else
msg_Dbg( p_resource->p_parent, "reusing audio output" );
- if( p_aout != NULL )
+ if( p_resource->p_aout == p_aout )
{
- vlc_mutex_lock( &p_resource->lock_hold );
- p_resource->p_aout = p_aout;
- vlc_mutex_unlock( &p_resource->lock_hold );
-
+ assert( !p_resource->b_aout_busy );
p_resource->b_aout_busy = true;
- vlc_object_hold( p_aout );
}
- vlc_mutex_unlock( &p_resource->lock );
+ vlc_mutex_unlock( &p_resource->lock_hold );
return p_aout;
}
@@ -365,18 +363,17 @@ void input_resource_PutAout( input_resource_t *p_resource,
{
assert( p_aout != NULL );
- vlc_mutex_lock( &p_resource->lock );
+ vlc_mutex_lock( &p_resource->lock_hold );
if( p_aout == p_resource->p_aout )
{
assert( p_resource->b_aout_busy );
p_resource->b_aout_busy = false;
msg_Dbg( p_resource->p_parent, "keeping audio output" );
- vlc_object_release( p_aout );
p_aout = NULL;
}
else
msg_Dbg( p_resource->p_parent, "destroying extra audio output" );
- vlc_mutex_unlock( &p_resource->lock );
+ vlc_mutex_unlock( &p_resource->lock_hold );
if( p_aout != NULL )
aout_Destroy( p_aout );
@@ -388,7 +385,7 @@ audio_output_t *input_resource_HoldAout( input_resource_t *p_resource )
vlc_mutex_lock( &p_resource->lock_hold );
p_aout = p_resource->p_aout;
- if( p_aout )
+ if( p_aout != NULL )
vlc_object_hold( p_aout );
vlc_mutex_unlock( &p_resource->lock_hold );
@@ -399,13 +396,11 @@ static void input_resource_TerminateAout( input_resource_t *p_resource )
{
audio_output_t *p_aout;
- vlc_mutex_lock( &p_resource->lock );
vlc_mutex_lock( &p_resource->lock_hold );
p_aout = p_resource->p_aout;
p_resource->p_aout = NULL;
- vlc_mutex_unlock( &p_resource->lock_hold );
p_resource->b_aout_busy = false;
- vlc_mutex_unlock( &p_resource->lock );
+ vlc_mutex_unlock( &p_resource->lock_hold );
if( p_aout != NULL )
aout_Destroy( p_aout );
More information about the vlc-commits
mailing list