Commit 62daf8e8 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

mirror: use atomic variables instead of lock

parent 5ba31909
...@@ -29,10 +29,11 @@ ...@@ -29,10 +29,11 @@
# include "config.h" # include "config.h"
#endif #endif
#include <assert.h>
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_plugin.h> #include <vlc_plugin.h>
#include <vlc_atomic.h>
#include <assert.h>
#include <vlc_filter.h> #include <vlc_filter.h>
#include "filter_picture.h" #include "filter_picture.h"
...@@ -102,9 +103,8 @@ static int FilterCallback( vlc_object_t *, char const *, ...@@ -102,9 +103,8 @@ static int FilterCallback( vlc_object_t *, char const *,
*****************************************************************************/ *****************************************************************************/
struct filter_sys_t struct filter_sys_t
{ {
int i_split; atomic_int i_split;
int i_direction; atomic_int i_direction;
vlc_mutex_t lock;
}; };
/***************************************************************************** /*****************************************************************************
...@@ -146,14 +146,14 @@ static int Create( vlc_object_t *p_this ) ...@@ -146,14 +146,14 @@ static int Create( vlc_object_t *p_this )
config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options, config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
p_filter->p_cfg ); p_filter->p_cfg );
p_sys->i_split = var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "split" ); atomic_init( &p_sys->i_split,
p_sys->i_direction = var_CreateGetIntegerCommand( p_filter, var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "split" ) );
CFG_PREFIX "direction" ); atomic_init( &p_sys->i_direction,
var_CreateGetIntegerCommand( p_filter,
vlc_mutex_init( &p_sys->lock ); CFG_PREFIX "direction" ) );
var_AddCallback( p_filter, CFG_PREFIX "split", FilterCallback, NULL ); var_AddCallback( p_filter, CFG_PREFIX "split", FilterCallback, p_sys );
var_AddCallback( p_filter, CFG_PREFIX "direction", FilterCallback, NULL ); var_AddCallback( p_filter, CFG_PREFIX "direction", FilterCallback, p_sys );
p_filter->pf_video_filter = Filter; p_filter->pf_video_filter = Filter;
...@@ -168,12 +168,11 @@ static int Create( vlc_object_t *p_this ) ...@@ -168,12 +168,11 @@ static int Create( vlc_object_t *p_this )
static void Destroy( vlc_object_t *p_this ) static void Destroy( vlc_object_t *p_this )
{ {
filter_t *p_filter = (filter_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 "split", FilterCallback, p_sys );
var_DelCallback( p_filter, CFG_PREFIX "direction", FilterCallback, NULL ); var_DelCallback( p_filter, CFG_PREFIX "direction", FilterCallback, p_sys );
free( p_sys );
vlc_mutex_destroy( &p_filter->p_sys->lock );
free( p_filter->p_sys );
} }
/***************************************************************************** /*****************************************************************************
...@@ -192,10 +191,8 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -192,10 +191,8 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
if( !p_pic ) return NULL; if( !p_pic ) return NULL;
filter_sys_t *p_sys = p_filter->p_sys; filter_sys_t *p_sys = p_filter->p_sys;
vlc_mutex_lock( &p_sys->lock ); b_vertical_split = !atomic_load( &p_sys->i_split );
b_vertical_split = p_sys->i_split == 0 ? true : false; b_left_to_right = !atomic_load( &p_sys->i_direction );
b_left_to_right = p_sys->i_direction == 0 ? true : false;
vlc_mutex_unlock( &p_sys->lock );
p_outpic = filter_NewPicture( p_filter ); p_outpic = filter_NewPicture( p_filter );
if( !p_outpic ) if( !p_outpic )
...@@ -592,22 +589,13 @@ static void HorizontalMirror( picture_t *p_pic, picture_t *p_outpic, int i_plane ...@@ -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, static int FilterCallback ( vlc_object_t *p_this, char const *psz_var,
vlc_value_t oldval, vlc_value_t newval, void *p_data ) vlc_value_t oldval, vlc_value_t newval, void *p_data )
{ {
(void)oldval; (void)p_data; (void) p_this; (void)oldval;
filter_t *p_filter = (filter_t*)p_this; filter_sys_t *p_sys = p_data;
filter_sys_t *p_sys = p_filter->p_sys;
if( !strcmp( psz_var, CFG_PREFIX "split" ) ) if( !strcmp( psz_var, CFG_PREFIX "split" ) )
{ atomic_store( &p_sys->i_split, newval.i_int );
vlc_mutex_lock( &p_sys->lock );
p_sys->i_split = newval.i_int;
vlc_mutex_unlock( &p_sys->lock );
}
else /* CFG_PREFIX "direction" */ else /* CFG_PREFIX "direction" */
{ atomic_store( &p_sys->i_direction, newval.i_int );
vlc_mutex_lock( &p_sys->lock );
p_sys->i_direction = newval.i_int;
vlc_mutex_unlock( &p_sys->lock );
}
return VLC_SUCCESS; return VLC_SUCCESS;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment