]> git.sesse.net Git - vlc/commitdiff
postproc: reduce lock contention in callback
authorRémi Denis-Courmont <remi@remlab.net>
Thu, 24 Jul 2014 16:11:27 +0000 (19:11 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Thu, 24 Jul 2014 16:12:03 +0000 (19:12 +0300)
modules/video_filter/postproc.c

index 3ee8882f625fd37c9d627834b39ebdbcf94f49d9..454c79c8fdc9a9b1d0dba0a4f47779cf2b820f0c 100644 (file)
@@ -331,28 +331,27 @@ static void PPChangeMode( filter_t *p_filter, const char *psz_name,
                           int i_quality )
 {
     filter_sys_t *p_sys = p_filter->p_sys;
+    pp_mode *newmode = NULL, *oldmode;
+
     vlc_mutex_lock( &p_sys->lock );
     if( i_quality > 0 )
     {
-        pp_mode *pp_mode = pp_get_mode_by_name_and_quality( psz_name ?
-                                                              psz_name :
-                                                              "default",
-                                                              i_quality );
-        if( pp_mode )
-        {
-            pp_free_mode( p_sys->pp_mode );
-            p_sys->pp_mode = pp_mode;
+         newmode = pp_get_mode_by_name_and_quality( psz_name ? psz_name :
+                                                    "default", i_quality );
+         if( newmode == NULL )
+         {
+             msg_Warn( p_filter, "Error while changing post processing mode. "
+                       "Keeping previous mode." );
+             return;
         }
-        else
-            msg_Warn( p_filter, "Error while changing post processing mode. "
-                      "Keeping previous mode." );
-    }
-    else
-    {
-        pp_free_mode( p_sys->pp_mode );
-        p_sys->pp_mode = NULL;
     }
+
+    vlc_mutex_lock( &p_sys->lock );
+    oldmode = p_sys->pp_mode;
+    p_sys->pp_mode = newmode;
     vlc_mutex_unlock( &p_sys->lock );
+
+    pp_free_mode( oldmode );
 }
 
 static int PPQCallback( vlc_object_t *p_this, const char *psz_var,