From 60220ade5614d1b619ef27977f30e87648ade298 Mon Sep 17 00:00:00 2001
From: Thomas Guillem <thomas@gllm.fr>
Date: Tue, 28 May 2019 10:15:10 +0200
Subject: [PATCH] rc: lock the player only once while processing commands
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

And avoid racy states due to successive lock/unlock

Refs #22328

Signed-off-by: Rémi Denis-Courmont <remi@remlab.net>

Conflicts:
	modules/control/rc.c
---
 modules/control/rc.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/modules/control/rc.c b/modules/control/rc.c
index 3971916eb149..4ec92712e8ea 100644
--- a/modules/control/rc.c
+++ b/modules/control/rc.c
@@ -1569,12 +1569,11 @@ static void *Run( void *data )
         b_complete = ReadCommand( p_intf, p_buffer, &i_size );
         canc = vlc_savecancel( );
 
+        vlc_player_Lock(player);
         /* Manage the input part */
         if( item == NULL )
         {
-            vlc_player_Lock(player);
             item = vlc_player_HoldCurrentMedia(player);
-            vlc_player_Unlock(player);
             /* New input has been registered */
             if( item )
             {
@@ -1584,7 +1583,6 @@ static void *Run( void *data )
             }
         }
 
-        vlc_player_Lock(player);
         if( !vlc_player_IsStarted( player ) )
         {
             if (item)
@@ -1596,13 +1594,10 @@ static void *Run( void *data )
             p_sys->last_state = VLC_PLAYER_STATE_STOPPED;
             msg_rc( STATUS_CHANGE "( stop state: 0 )" );
         }
-        vlc_player_Unlock(player);
 
         if( item != NULL )
         {
-            vlc_player_Lock(player);
             enum vlc_player_state state = vlc_player_GetState(player);
-            vlc_player_Unlock(player);
 
             if (p_sys->last_state != state)
             {
@@ -1627,15 +1622,14 @@ static void *Run( void *data )
 
         if( item && b_showpos )
         {
-            vlc_player_Lock(player);
             i_newpos = 100 * vlc_player_GetPosition( player );
-            vlc_player_Unlock(player);
             if( i_oldpos != i_newpos )
             {
                 i_oldpos = i_newpos;
                 msg_rc( "pos: %d%%", i_newpos );
             }
         }
+        vlc_player_Unlock(player);
 
         /* Is there something to do? */
         if( !b_complete ) continue;
-- 
GitLab