[vlc-commits] mirror: use atomic variables instead of lock

Rémi Denis-Courmont git at videolan.org
Sat Nov 10 21:42:58 CET 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Nov 10 22:28:08 2012 +0200| [62daf8e88fef3305b34d1064c76e8dab5bdab676] | committer: Rémi Denis-Courmont

mirror: use atomic variables instead of lock

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=62daf8e88fef3305b34d1064c76e8dab5bdab676
---

 modules/video_filter/mirror.c |   56 ++++++++++++++++-------------------------
 1 file changed, 22 insertions(+), 34 deletions(-)

diff --git a/modules/video_filter/mirror.c b/modules/video_filter/mirror.c
index 543ee31..f7e2f69 100644
--- a/modules/video_filter/mirror.c
+++ b/modules/video_filter/mirror.c
@@ -29,10 +29,11 @@
 # include "config.h"
 #endif
 
+#include <assert.h>
+
 #include <vlc_common.h>
 #include <vlc_plugin.h>
-
-#include <assert.h>
+#include <vlc_atomic.h>
 #include <vlc_filter.h>
 #include "filter_picture.h"
 
@@ -102,9 +103,8 @@ static int FilterCallback( vlc_object_t *, char const *,
  *****************************************************************************/
 struct filter_sys_t
 {
-    int i_split;
-    int i_direction;
-    vlc_mutex_t lock;
+    atomic_int i_split;
+    atomic_int i_direction;
 };
 
 /*****************************************************************************
@@ -146,14 +146,14 @@ static int Create( vlc_object_t *p_this )
 
     config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
                        p_filter->p_cfg );
-    p_sys->i_split = var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "split" );
-    p_sys->i_direction = var_CreateGetIntegerCommand( p_filter,
-                                                    CFG_PREFIX "direction" );
-
-    vlc_mutex_init( &p_sys->lock );
+    atomic_init( &p_sys->i_split,
+                 var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "split" ) );
+    atomic_init( &p_sys->i_direction,
+                 var_CreateGetIntegerCommand( p_filter,
+                                                    CFG_PREFIX "direction" ) );
 
-    var_AddCallback( p_filter, CFG_PREFIX "split", FilterCallback, NULL );
-    var_AddCallback( p_filter, CFG_PREFIX "direction", FilterCallback, NULL );
+    var_AddCallback( p_filter, CFG_PREFIX "split", FilterCallback, p_sys );
+    var_AddCallback( p_filter, CFG_PREFIX "direction", FilterCallback, p_sys );
 
     p_filter->pf_video_filter = Filter;
 
@@ -168,12 +168,11 @@ static int Create( vlc_object_t *p_this )
 static void Destroy( vlc_object_t *p_this )
 {
     filter_t *p_filter = (filter_t *)p_this;
+    filter_sys_t *p_sys = p_filter->p_sys;
 
-    var_DelCallback( p_filter, CFG_PREFIX "split", FilterCallback, NULL );
-    var_DelCallback( p_filter, CFG_PREFIX "direction", FilterCallback, NULL );
-
-    vlc_mutex_destroy( &p_filter->p_sys->lock );
-    free( p_filter->p_sys );
+    var_DelCallback( p_filter, CFG_PREFIX "split", FilterCallback, p_sys );
+    var_DelCallback( p_filter, CFG_PREFIX "direction", FilterCallback, p_sys );
+    free( p_sys );
 }
 
 /*****************************************************************************
@@ -192,10 +191,8 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
     if( !p_pic ) return NULL;
 
     filter_sys_t *p_sys = p_filter->p_sys;
-    vlc_mutex_lock( &p_sys->lock );
-    b_vertical_split = p_sys->i_split == 0 ? true : false;
-    b_left_to_right = p_sys->i_direction == 0 ? true : false;
-    vlc_mutex_unlock( &p_sys->lock );
+    b_vertical_split = !atomic_load( &p_sys->i_split );
+    b_left_to_right = !atomic_load( &p_sys->i_direction );
 
     p_outpic = filter_NewPicture( p_filter );
     if( !p_outpic )
@@ -592,22 +589,13 @@ static void HorizontalMirror( picture_t *p_pic, picture_t *p_outpic, int i_plane
 static int FilterCallback ( vlc_object_t *p_this, char const *psz_var,
                             vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
-    (void)oldval;    (void)p_data;
-    filter_t *p_filter = (filter_t*)p_this;
-    filter_sys_t *p_sys = p_filter->p_sys;
+    (void) p_this; (void)oldval;
+    filter_sys_t *p_sys = p_data;
 
     if( !strcmp( psz_var, CFG_PREFIX "split" ) )
-    {
-        vlc_mutex_lock( &p_sys->lock );
-        p_sys->i_split = newval.i_int;
-        vlc_mutex_unlock( &p_sys->lock );
-    }
+        atomic_store( &p_sys->i_split, newval.i_int );
     else /* CFG_PREFIX "direction" */
-    {
-        vlc_mutex_lock( &p_sys->lock );
-        p_sys->i_direction = newval.i_int;
-        vlc_mutex_unlock( &p_sys->lock );
-    }
+        atomic_store( &p_sys->i_direction, newval.i_int );
 
     return VLC_SUCCESS;
 }



More information about the vlc-commits mailing list