[vlc-devel] [PATCH] decoder: move the owner lock closer to the variable use

Steve Lhomme robux4 at ycbcr.xyz
Tue Sep 3 11:31:19 CEST 2019


Similar to how it's done in DecoderProcessFlush().

It makes it clearer when variables are accessed under lock. It also avoids
locking in some cases if not needed.
---
 src/input/decoder.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/input/decoder.c b/src/input/decoder.c
index f66b708b4d..5bd59fc6b0 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -1465,12 +1465,16 @@ static void OutputChangePause( struct decoder_owner *p_owner, bool paused, vlc_t
     switch( p_dec->fmt_out.i_cat )
     {
         case VIDEO_ES:
+            vlc_mutex_lock( &p_owner->lock );
             if( p_owner->p_vout != NULL )
                 vout_ChangePause( p_owner->p_vout, paused, date );
+            vlc_mutex_unlock( &p_owner->lock );
             break;
         case AUDIO_ES:
+            vlc_mutex_lock( &p_owner->lock );
             if( p_owner->p_aout != NULL )
                 aout_DecChangePause( p_owner->p_aout, paused, date );
+            vlc_mutex_unlock( &p_owner->lock );
             break;
         case SPU_ES:
             break;
@@ -1484,6 +1488,7 @@ static void OutputChangeRate( struct decoder_owner *p_owner, float rate )
     decoder_t *p_dec = &p_owner->dec;
 
     msg_Dbg( p_dec, "changing rate: %f", rate );
+    vlc_mutex_lock( &p_owner->lock );
     switch( p_dec->fmt_out.i_cat )
     {
         case VIDEO_ES:
@@ -1506,6 +1511,7 @@ static void OutputChangeRate( struct decoder_owner *p_owner, float rate )
             vlc_assert_unreachable();
     }
     p_owner->output_rate = rate;
+    vlc_mutex_unlock( &p_owner->lock );
 }
 
 static void OutputChangeDelay( struct decoder_owner *p_owner, vlc_tick_t delay )
@@ -1517,20 +1523,26 @@ static void OutputChangeDelay( struct decoder_owner *p_owner, vlc_tick_t delay )
     switch( p_dec->fmt_out.i_cat )
     {
         case VIDEO_ES:
+            vlc_mutex_lock( &p_owner->lock );
             if( p_owner->p_vout != NULL )
                 vout_ChangeDelay( p_owner->p_vout, delay );
+            vlc_mutex_unlock( &p_owner->lock );
             break;
         case AUDIO_ES:
+            vlc_mutex_lock( &p_owner->lock );
             if( p_owner->p_aout != NULL )
                 aout_DecChangeDelay( p_owner->p_aout, delay );
+            vlc_mutex_unlock( &p_owner->lock );
             break;
         case SPU_ES:
+            vlc_mutex_lock( &p_owner->lock );
             if( p_owner->p_vout != NULL )
             {
                 assert(p_owner->i_spu_channel != VOUT_SPU_CHANNEL_INVALID);
                 vout_ChangeSpuDelay(p_owner->p_vout, p_owner->i_spu_channel,
                                     delay);
             }
+            vlc_mutex_unlock( &p_owner->lock );
             break;
         default:
             vlc_assert_unreachable();
@@ -1595,9 +1607,7 @@ static void *DecoderThread( void *p_data )
             paused = p_owner->paused;
             vlc_fifo_Unlock( p_owner->p_fifo );
 
-            vlc_mutex_lock( &p_owner->lock );
             OutputChangePause( p_owner, paused, date );
-            vlc_mutex_unlock( &p_owner->lock );
 
             vlc_restorecancel( canc );
             vlc_fifo_Lock( p_owner->p_fifo );
@@ -1611,9 +1621,7 @@ static void *DecoderThread( void *p_data )
             rate = p_owner->request_rate;
             vlc_fifo_Unlock( p_owner->p_fifo );
 
-            vlc_mutex_lock( &p_owner->lock );
             OutputChangeRate( p_owner, rate );
-            vlc_mutex_unlock( &p_owner->lock );
 
             vlc_restorecancel( canc );
             vlc_fifo_Lock( p_owner->p_fifo );
@@ -1626,9 +1634,7 @@ static void *DecoderThread( void *p_data )
             delay = p_owner->delay;
             vlc_fifo_Unlock( p_owner->p_fifo );
 
-            vlc_mutex_lock( &p_owner->lock );
             OutputChangeDelay( p_owner, delay );
-            vlc_mutex_unlock( &p_owner->lock );
 
             vlc_restorecancel( canc );
             vlc_fifo_Lock( p_owner->p_fifo );
-- 
2.17.1



More information about the vlc-devel mailing list